From 2884230fe48148805ef30ad6c82d3723fb8de3ba Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Sat, 10 Aug 2019 15:12:43 +0200 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(-) diff --git a/src/authentic2/templates/authentic2/login.html b/src/authentic2/templates/authentic2/login.html index fa741634..5e052a36 100644 --- a/src/authentic2/templates/authentic2/login.html +++ b/src/authentic2/templates/authentic2/login.html @@ -25,7 +25,7 @@ {% if blocks|length != 1 %} {% for id, login_block in blocks.items %} {% if not login_block.is_hidden %} - + {{ login_block.name }} {% endif %} @@ -33,7 +33,7 @@ {% endif %} {% for id, login_block in blocks.items %} -
+ {% endfor %} diff --git a/src/authentic2/utils/__init__.py b/src/authentic2/utils/__init__.py index 2b4e9055..2e4d2ca5 100644 --- a/src/authentic2/utils/__init__.py +++ b/src/authentic2/utils/__init__.py @@ -212,10 +212,16 @@ def get_authenticator_method(authenticator, method, parameters): if not response: return None status_code = 200 + extra_css_class = '' # Some authenticator methods return an HttpResponse, others return a string if isinstance(response, HttpResponse): + # Force a TemplateResponse to be rendered. + if not getattr(response, 'is_rendered', True) and callable(getattr(response, 'render', None)): + response = response.render() content = response.content status_code = response.status_code + if hasattr(response, 'context_data') and response.context_data: + extra_css_class = response.context_data.get('block-extra-css-class', '') return { 'id': authenticator.id, 'name': authenticator.name, @@ -223,6 +229,7 @@ def get_authenticator_method(authenticator, method, parameters): 'response': response, 'status_code': status_code, 'authenticator': authenticator, + 'extra_css_class': extra_css_class, } diff --git a/src/authentic2_auth_fc/authenticators.py b/src/authentic2_auth_fc/authenticators.py index 01097d30..dc8ce5c5 100644 --- a/src/authentic2_auth_fc/authenticators.py +++ b/src/authentic2_auth_fc/authenticators.py @@ -16,7 +16,7 @@ from django.utils.translation import gettext_noop from django.template.loader import render_to_string -from django.shortcuts import render +from django.template.response import TemplateResponse from authentic2 import app_settings as a2_app_settings, utils as a2_utils @@ -57,6 +57,7 @@ class FcAuthenticator(object): params=params, request=request), 'fc_user_info': fc_user_info, + 'block-extra-css-class': 'fc-registration', }) template = 'authentic2_auth_fc/login_registration.html' else: @@ -64,8 +65,9 @@ class FcAuthenticator(object): keep_params=True, params=params, request=request) + context['block-extra-css-class'] = 'fc-login' template = 'authentic2_auth_fc/login.html' - return render(request, template, context) + return TemplateResponse(request, template, context) def profile(self, request, *args, **kwargs): # We prevent unlinking if the user has no usable password and can't change it @@ -108,4 +110,4 @@ class FcAuthenticator(object): 'popup': self.popup, 'about_url': app_settings.about_url, }) - return render(request, 'authentic2_auth_fc/registration.html', context) + return TemplateResponse(request, 'authentic2_auth_fc/registration.html', context) -- 2.23.0.rc1