From 5fe168a0344197f66c3a402dd94a7863139aede5 Mon Sep 17 00:00:00 2001 From: Paul Marillonnet Date: Tue, 4 Sep 2018 16:26:15 +0200 Subject: [PATCH] WIP support avatar picture in user profile (#26022) --- src/authentic2/attribute_kinds.py | 6 ++++++ src/authentic2/custom_user/apps.py | 12 ++++++++++-- .../templates/authentic2/accounts_edit.html | 7 ++++++- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/authentic2/attribute_kinds.py b/src/authentic2/attribute_kinds.py index 27ae00b4..a60b85d9 100644 --- a/src/authentic2/attribute_kinds.py +++ b/src/authentic2/attribute_kinds.py @@ -151,6 +151,12 @@ DEFAULT_ATTRIBUTE_KINDS = [ 'field_class': PhoneNumberField, 'rest_framework_field_class': PhoneNumberDRFField, }, + { + 'label': _('image'), + 'name': 'image', + 'field_class': forms.ImageField, + 'rest_framework_field_class': serializers.ImageField, + }, ] diff --git a/src/authentic2/custom_user/apps.py b/src/authentic2/custom_user/apps.py index d220422c..4f6b71ba 100644 --- a/src/authentic2/custom_user/apps.py +++ b/src/authentic2/custom_user/apps.py @@ -10,10 +10,10 @@ class CustomUserConfig(AppConfig): from django.db.models.signals import post_migrate post_migrate.connect( - self.create_first_name_last_name_attributes, + self.create_custom_attributes, sender=self) - def create_first_name_last_name_attributes(self, app_config, verbosity=2, interactive=True, + def create_custom_attributes(self, app_config, verbosity=2, interactive=True, using=DEFAULT_DB_ALIAS, **kwargs): from django.utils import translation from django.utils.translation import ugettext_lazy as _ @@ -50,6 +50,14 @@ class CustomUserConfig(AppConfig): 'asked_on_registration': True, 'user_editable': True, 'user_visible': True}) + attrs['avatar_picture'], created = Attribute.objects.get_or_create( + name='avatar_picture', + defaults={'kind': 'image', + 'label': _('Avatar picture'), + 'required': False, + 'asked_on_registration': False, + 'user_editable': True, + 'user_visible': True}) serialize = get_kind('string').get('serialize') for user in User.objects.all(): diff --git a/src/authentic2/templates/authentic2/accounts_edit.html b/src/authentic2/templates/authentic2/accounts_edit.html index c7587b14..a642b1b7 100644 --- a/src/authentic2/templates/authentic2/accounts_edit.html +++ b/src/authentic2/templates/authentic2/accounts_edit.html @@ -12,7 +12,12 @@ {% endblock %} {% block content %} -
+ {% if form.is_multipart %} + + {% else %} + + {% endif %} + {% csrf_token %} {{ form.as_p }} {% if form.instance and form.instance.id %} -- 2.19.0.rc1