Projet

Général

Profil

0001-misc-add-raw-attributes-values-to-ProfileView-contex.patch

Frédéric Péters, 11 juillet 2018 12:33

Télécharger (3,36 ko)

Voir les différences:

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(-)
src/authentic2/templates/authentic2/accounts.html
13 13
{% block content %}
14 14
  <div id="a2-profile-blocks">
15 15
    <div id="a2-profile" class="a2-profile-block">
16
      {% if profile %}
16
      {% if attributes %}
17 17
        <dl>
18
          {% for key, values in profile %}
19
            <dt>{{ key|capfirst }}&nbsp;:</dt>
18
          {% for attribute in attributes %}
19
            <dt>{{ attribute.attribute.label|capfirst }}&nbsp;:</dt>
20 20
            <dd>
21
              {% if values|length == 1 %}
22
                {{ values.0 }}
21
              {% if attribute.values|length == 1 %}
22
                {{ attribute.values.0 }}
23 23
              {% else %}
24 24
                <ul>
25
                  {% for value in values %}
25
                  {% for value in attribute.values %}
26 26
                    <li>{{ value }}</li>
27 27
                  {% endfor %}
28 28
                </ul>
src/authentic2/views.py
436 436
            for field_name in qs:
437 437
                if field_name not in field_names:
438 438
                    field_names.append(field_name)
439
        attributes = []
439 440
        for field_name in field_names:
440 441
            title = None
441 442
            if isinstance(field_name, (list, tuple)):
......
467 468
                if not title:
468 469
                    title = field.verbose_name
469 470
                value = getattr(self.request.user, field_name, None)
471
                attribute = models.Attribute(name=field_name, label=title)
470 472

  
473
            raw_value = None
471 474
            if value:
472 475
                if callable(value):
473 476
                    value = value()
474 477
                if not isinstance(value, (list, tuple)):
475 478
                    value = (value,)
479
                raw_value = value
476 480
                value = map(unicode, value)
477 481
            if value or app_settings.A2_PROFILE_DISPLAY_EMPTY_FIELDS:
478 482
                profile.append((title, value))
483
                attributes.append({'attribute': attribute, 'values': raw_value})
479 484

  
480 485
        # Credentials management
481 486
        parameters = {'request': request,
......
498 503
            'frontends_block': blocks,
499 504
            'frontends_block_by_id': blocks_by_id,
500 505
            'profile': profile,
506
            'attributes': attributes,
501 507
            'allow_account_deletion': app_settings.A2_REGISTRATION_CAN_DELETE_ACCOUNT,
502 508
            'allow_profile_edit': EditProfile.can_edit_profile(),
503 509
            'allow_email_change': app_settings.A2_PROFILE_CAN_CHANGE_EMAIL,
504
-