Projet

Général

Profil

0001-auth_fc-differentiate-registration-login-block-with-.patch

Benjamin Dauvergne, 10 août 2019 15:44

Télécharger (4,39 ko)

Voir les différences:

Subject: [PATCH] auth_fc: differentiate registration login block with a class
 (#29227)

 src/authentic2/templates/authentic2/login.html | 4 ++--
 src/authentic2/utils.py                        | 7 +++++++
 src/authentic2_auth_fc/authenticators.py       | 5 ++++-
 3 files changed, 13 insertions(+), 3 deletions(-)
src/authentic2/templates/authentic2/login.html
25 25
    {% if blocks|length != 1 %}
26 26
      {% for id, login_block in blocks.items %}
27 27
        {% if not login_block.is_hidden %}
28
          <a class="css-tab-link css-tab{{ forloop.counter }} {% if forloop.first %}css-tab-default{% endif %}" href="#css-tab{{ forloop.counter }}">
28
          <a class="css-tab-link css-tab{{ forloop.counter }} {% if forloop.first %}css-tab-default{% endif %} {{ login_block.extra_css_class }}" href="#css-tab{{ forloop.counter }}">
29 29
              {{ login_block.name }}
30 30
          </a>
31 31
        {% endif %}
......
33 33
    {% endif %}
34 34

  
35 35
    {% for id, login_block in blocks.items %}
36
      <div class="css-tab-content css-tab{{ forloop.counter }} {% if forloop.first %}css-tab-default{% endif %}">
36
      <div class="css-tab-content css-tab{{ forloop.counter }} {% if forloop.first %}css-tab-default{% endif %} {{ login_block.extra_css_class }}">
37 37
        {{ login_block.content|safe }}
38 38
      </div>
39 39
    {% endfor %}
src/authentic2/utils.py
212 212
    if not response:
213 213
        return None
214 214
    status_code = 200
215
    extra_css_class = ''
215 216
    # Some authenticator methods return an HttpResponse, others return a string
216 217
    if isinstance(response, HttpResponse):
218
        # Force a TemplateResponse to be rendered.
219
        if not getattr(response, 'is_rendered', True) and callable(getattr(response, 'render', None)):
220
            response = response.render()
217 221
        content = response.content
218 222
        status_code = response.status_code
223
        if hasattr(response, 'context_data') and response.context_data:
224
            extra_css_class = response.context_data.get('block-extra-css-class', '')
219 225
    return {
220 226
        'id': authenticator.id,
221 227
        'name': authenticator.name,
......
223 229
        'response': response,
224 230
        'status_code': status_code,
225 231
        'authenticator': authenticator,
232
        'extra_css_class': extra_css_class,
226 233
    }
227 234

  
228 235

  
src/authentic2_auth_fc/authenticators.py
17 17
from django.utils.translation import gettext_noop
18 18
from django.template.loader import render_to_string
19 19
from django.shortcuts import render
20
from django.template.response import TemplateResponse
20 21

  
21 22
from authentic2 import app_settings as a2_app_settings, utils as a2_utils
22 23

  
......
57 58
                                                      params=params,
58 59
                                                      request=request),
59 60
                'fc_user_info': fc_user_info,
61
                'block-extra-css-class': 'fc-registration',
60 62
            })
61 63
            template = 'authentic2_auth_fc/login_registration.html'
62 64
        else:
......
64 66
                                                     keep_params=True,
65 67
                                                     params=params,
66 68
                                                     request=request)
69
            context['block-extra-css-class'] = 'fc-login'
67 70
            template = 'authentic2_auth_fc/login.html'
68
        return render(request, template, context)
71
        return TemplateResponse(request, template, context)
69 72

  
70 73
    def profile(self, request, *args, **kwargs):
71 74
        # We prevent unlinking if the user has no usable password and can't change it
72
-