From 100388498e16cfd33fc7375a4a0978ee38fe77bd 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 | 6 +++--- src/authentic2/views.py | 6 ++++++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/authentic2/templates/authentic2/accounts.html b/src/authentic2/templates/authentic2/accounts.html index b36c3307..a6dfbe5c 100644 --- a/src/authentic2/templates/authentic2/accounts.html +++ b/src/authentic2/templates/authentic2/accounts.html @@ -13,10 +13,10 @@ {% block content %}
- {% if profile %} + {% if attributes %}
- {% for key, values in profile %} -
{{ key|capfirst }} :
+ {% for attribute, values in attributes %} +
{{ attribute.label|capfirst }} :
{% if values|length == 1 %} {{ values.0 }} diff --git a/src/authentic2/views.py b/src/authentic2/views.py index 50faac8c..b21736f4 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, 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