Projet

Général

Profil

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

Benjamin Dauvergne, 09 septembre 2019 13:48

Télécharger (4,74 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/__init__.py               | 7 +++++++
 src/authentic2_auth_fc/authenticators.py       | 8 +++++---
 3 files changed, 14 insertions(+), 5 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/__init__.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
16 16

  
17 17
from django.utils.translation import gettext_noop
18 18
from django.template.loader import render_to_string
19
from django.shortcuts import render
19
from django.template.response import TemplateResponse
20 20

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

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

  
70 72
    def profile(self, request, *args, **kwargs):
71 73
        # We prevent unlinking if the user has no usable password and can't change it
......
108 110
            'popup': self.popup,
109 111
            'about_url': app_settings.about_url,
110 112
        })
111
        return render(request, 'authentic2_auth_fc/registration.html', context)
113
        return TemplateResponse(request, 'authentic2_auth_fc/registration.html', context)
112
-