misc: add raw attributes & values to ProfileView context (#25195)
This commit is contained in:
parent
fb42e8d844
commit
82f4dc6cdc
|
@ -13,16 +13,16 @@
|
|||
{% block content %}
|
||||
<div id="a2-profile-blocks">
|
||||
<div id="a2-profile" class="a2-profile-block">
|
||||
{% if profile %}
|
||||
{% if attributes %}
|
||||
<dl>
|
||||
{% for key, values in profile %}
|
||||
<dt>{{ key|capfirst }} :</dt>
|
||||
{% for attribute in attributes %}
|
||||
<dt>{{ attribute.attribute.label|capfirst }} :</dt>
|
||||
<dd>
|
||||
{% if values|length == 1 %}
|
||||
{{ values.0 }}
|
||||
{% if attribute.values|length == 1 %}
|
||||
{{ attribute.values.0 }}
|
||||
{% else %}
|
||||
<ul>
|
||||
{% for value in values %}
|
||||
{% for value in attribute.values %}
|
||||
<li>{{ value }}</li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue