From 66815866144e08fd2a9c9f8e5b8cec2c7f2a0baf Mon Sep 17 00:00:00 2001 From: Benjamin Dauvergne Date: Thu, 14 May 2015 22:39:12 +0200 Subject: [PATCH] templates: replace use of sekizai by our own template tags fixes #7206 --- src/authentic2/context_processors.py | 3 ++ src/authentic2/settings.py | 2 -- src/authentic2/templates/authentic2/login.html | 17 ++++++---- .../templates/authentic2/login_password_form.html | 2 +- .../templates/authentic2/logout_confirm.html | 2 +- src/authentic2/templates/base.html | 10 +++--- src/authentic2/templatetags/__init__.py | 0 src/authentic2/templatetags/authentic2.py | 37 ++++++++++++++++++++++ 8 files changed, 58 insertions(+), 15 deletions(-) create mode 100644 src/authentic2/templatetags/__init__.py create mode 100644 src/authentic2/templatetags/authentic2.py diff --git a/src/authentic2/context_processors.py b/src/authentic2/context_processors.py index e894cf3..22fd4eb 100644 --- a/src/authentic2/context_processors.py +++ b/src/authentic2/context_processors.py @@ -1,3 +1,5 @@ +from collections import defaultdict + from pkg_resources import get_distribution from django.conf import settings @@ -38,4 +40,5 @@ def a2_processor(request): else: __AUTHENTIC2_DISTRIBUTION = str(get_distribution('authentic2')) variables['AUTHENTIC2_VERSION'] = __AUTHENTIC2_DISTRIBUTION + variables['add_to_blocks'] = defaultdict(lambda:[]) return variables diff --git a/src/authentic2/settings.py b/src/authentic2/settings.py index 117cfbc..edd455f 100644 --- a/src/authentic2/settings.py +++ b/src/authentic2/settings.py @@ -52,7 +52,6 @@ TEMPLATE_CONTEXT_PROCESSORS = ( 'django.contrib.messages.context_processors.messages', 'django.core.context_processors.static', 'authentic2.context_processors.a2_processor', - 'sekizai.context_processors.sekizai', ) MIDDLEWARE_CLASSES = ( @@ -118,7 +117,6 @@ INSTALLED_APPS = ( 'authentic2.custom_user', 'authentic2', 'gadjo', - 'sekizai', ) INSTALLED_APPS = tuple(plugins.register_plugins_installed_apps(INSTALLED_APPS)) diff --git a/src/authentic2/templates/authentic2/login.html b/src/authentic2/templates/authentic2/login.html index 3d81158..7534398 100644 --- a/src/authentic2/templates/authentic2/login.html +++ b/src/authentic2/templates/authentic2/login.html @@ -1,10 +1,19 @@ {% extends "base.html" %} -{% load i18n sekizai_tags gadjo %} +{% load i18n gadjo authentic2 %} {% block title %} {% trans "Log in" %} {% endblock %} +{% block extra_scripts %} + + + + + + +{% endblock %} + {% block content %}
- {% render_block "js-endpage" %} + {% block js-endpage %} + {% renderblock "js-endpage" %} + {% endblock %} diff --git a/src/authentic2/templatetags/__init__.py b/src/authentic2/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/authentic2/templatetags/authentic2.py b/src/authentic2/templatetags/authentic2.py new file mode 100644 index 0000000..1dd4a17 --- /dev/null +++ b/src/authentic2/templatetags/authentic2.py @@ -0,0 +1,37 @@ +from django import template + +register = template.Library() + + +@register.tag('addtoblock') +def addtoblock(parser, token): + try: + tag_name, block_name = token.split_contents() + except ValueError: + raise template.TemplateSyntaxError( + '%r tag requires a single argument' % token.contents.split()[0]) + if not (block_name[0] == block_name[-1] and block_name[0] in ('"', "'")): + raise template.TemplateSyntaxError( + '%r tag requireds its argument to be quoted' % tag_name) + nodelist = parser.parse(('endaddtoblock',)) + parser.delete_first_token() + return AddToBlock(block_name, nodelist) + + +class AddToBlock(template.Node): + def __init__(self, block_name, nodelist): + self.block_name = block_name[1:-1] + self.nodelist = nodelist + + def render(self, context): + output = self.nodelist.render(context) + dest = context['add_to_blocks'][self.block_name] + if output not in dest: + dest.append(output) + return '' + + +@register.simple_tag(takes_context=True) +def renderblock(context, block_name): + output = u'\n'.join(context['add_to_blocks'][block_name]) + return output -- 2.1.4