From 21b42e83a6dc0709ff33cf96df89a741e67884af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= Date: Wed, 11 Jul 2018 00:14:38 +0200 Subject: [PATCH] misc: add raw attributes & values to ProfileView context (#25195) --- src/authentic2/templates/authentic2/accounts.html | 12 ++++++------ src/authentic2/views.py | 6 ++++++ 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/authentic2/templates/authentic2/accounts.html b/src/authentic2/templates/authentic2/accounts.html index b36c3307..4e9f979f 100644 --- a/src/authentic2/templates/authentic2/accounts.html +++ b/src/authentic2/templates/authentic2/accounts.html @@ -13,16 +13,16 @@ {% block content %}
- {% if profile %} + {% if attributes %}
- {% for key, values in profile %} -
{{ key|capfirst }} :
+ {% for attribute in attributes %} +
{{ attribute.attribute.label|capfirst }} :
- {% if values|length == 1 %} - {{ values.0 }} + {% if attribute.values|length == 1 %} + {{ attribute.values.0 }} {% else %}
    - {% for value in values %} + {% for value in attribute.values %}
  • {{ value }}
  • {% endfor %}
diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 50faac8c..dc0736fa 100644 --- a/src/authentic2/views.py +++ b/src/authentic2/views.py @@ -436,6 +436,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView): for field_name in qs: if field_name not in field_names: field_names.append(field_name) + attributes = [] for field_name in field_names: title = None if isinstance(field_name, (list, tuple)): @@ -467,15 +468,19 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView): if not title: title = field.verbose_name value = getattr(self.request.user, field_name, None) + attribute = models.Attribute(name=field_name, label=title) + raw_value = None if value: if callable(value): value = value() if not isinstance(value, (list, tuple)): value = (value,) + raw_value = value value = map(unicode, value) if value or app_settings.A2_PROFILE_DISPLAY_EMPTY_FIELDS: profile.append((title, value)) + attributes.append({'attribute': attribute, 'values': raw_value}) # Credentials management parameters = {'request': request, @@ -498,6 +503,7 @@ class ProfileView(cbv.TemplateNamesMixin, TemplateView): 'frontends_block': blocks, 'frontends_block_by_id': blocks_by_id, 'profile': profile, + 'attributes': attributes, 'allow_account_deletion': app_settings.A2_REGISTRATION_CAN_DELETE_ACCOUNT, 'allow_profile_edit': EditProfile.can_edit_profile(), 'allow_email_change': app_settings.A2_PROFILE_CAN_CHANGE_EMAIL, -- 2.18.0