Projet

Général

Profil

0001-delete-addtoblock-and-renderblock-tags-25361.patch

Emmanuel Cazenave, 27 juillet 2018 17:50

Télécharger (6,44 ko)

Voir les différences:

Subject: [PATCH] delete addtoblock and renderblock tags (#25361)

 src/authentic2/context_processors.py          |  1 -
 src/authentic2/registration_backend/views.py  |  1 -
 .../saml/templates/saml/post_form.html        |  2 +-
 .../templates/authentic2/login.html           |  2 +-
 .../authentic2/login_password_form.html       |  2 +-
 src/authentic2/templates/error.html           |  2 +-
 src/authentic2/templatetags/__init__.py       |  0
 src/authentic2/templatetags/authentic2.py     | 39 -------------------
 src/authentic2/views.py                       |  2 -
 9 files changed, 4 insertions(+), 47 deletions(-)
 delete mode 100644 src/authentic2/templatetags/__init__.py
 delete mode 100644 src/authentic2/templatetags/authentic2.py
src/authentic2/context_processors.py
40 40
        else:
41 41
            __AUTHENTIC2_DISTRIBUTION = str(get_distribution('authentic2'))
42 42
    variables['AUTHENTIC2_VERSION'] = __AUTHENTIC2_DISTRIBUTION
43
    variables['add_to_blocks'] = defaultdict(lambda:[])
44 43
    if hasattr(request, 'session'):
45 44
        variables['LAST_LOGIN'] = request.session.get(constants.LAST_LOGIN_SESSION_KEY)
46 45
        variables['USER_SWITCHED'] = constants.SWITCH_USER_SESSION_KEY in request.session
src/authentic2/registration_backend/views.py
95 95
        ctx = super(BaseRegistrationView, self).get_context_data(**kwargs)
96 96
        request_context = RequestContext(self.request)
97 97
        request_context.push(ctx)
98
        request_context['add_to_blocks'] = collections.defaultdict(lambda: [])
99 98
        parameters = {'request': self.request,
100 99
                      'context_instance': request_context}
101 100
        blocks = [utils.get_backend_method(backend, 'registration', parameters)
src/authentic2/saml/templates/saml/post_form.html
1 1
{% extends "authentic2/base-page.html" %}
2
{% load i18n authentic2 gadjo %}
2
{% load i18n gadjo %}
3 3

  
4 4
{% block page-title %}
5 5
  {{ block.super }} - {{ title }}
src/authentic2/templates/authentic2/login.html
1 1
{% extends "authentic2/base-page.html" %}
2
{% load i18n gadjo authentic2 staticfiles %}
2
{% load i18n gadjo staticfiles %}
3 3

  
4 4
{% block gadjo-jquery %}{% endblock %}
5 5

  
src/authentic2/templates/authentic2/login_password_form.html
1
{% load i18n authentic2 staticfiles %}
1
{% load i18n staticfiles %}
2 2
<div>
3 3
<form method="post" action="">
4 4
{% csrf_token %}
src/authentic2/templates/error.html
1 1
{% extends "authentic2/base-page.html" %}
2
{% load i18n authentic2 gadjo %}
2
{% load i18n gadjo %}
3 3

  
4 4
{% block extrascripts %}
5 5
  {{ block.super }}
src/authentic2/templatetags/authentic2.py
1
from django import template
2

  
3
register = template.Library()
4

  
5

  
6
@register.tag('addtoblock')
7
def addtoblock(parser, token):
8
    try:
9
        tag_name, block_name = token.split_contents()
10
    except ValueError:
11
        raise template.TemplateSyntaxError(
12
            '%r tag requires a single argument' % token.contents.split()[0])
13
    if not (block_name[0] == block_name[-1] and block_name[0] in ('"', "'")):
14
        raise template.TemplateSyntaxError(
15
            '%r tag requireds its argument to be quoted' % tag_name)
16
    nodelist = parser.parse(('endaddtoblock',))
17
    parser.delete_first_token()
18
    return AddToBlock(block_name, nodelist)
19

  
20

  
21
class AddToBlock(template.Node):
22
    def __init__(self, block_name, nodelist):
23
        self.block_name = block_name[1:-1]
24
        self.nodelist = nodelist
25

  
26
    def render(self, context):
27
        output = self.nodelist.render(context)
28
        dest = context['add_to_blocks'][self.block_name]
29
        if output not in dest:
30
            dest.append(output)
31
        return ''
32

  
33

  
34
@register.simple_tag(takes_context=True)
35
def renderblock(context, block_name):
36
    if 'add_to_blocks' in context and block_name in context['add_to_blocks']:
37
        return u'\n'.join(context['add_to_blocks'][block_name])
38
    else:
39
        return ''
src/authentic2/views.py
296 296
        'registration_authorized': getattr(settings, 'REGISTRATION_OPEN', True),
297 297
        'registration_url': registration_url,
298 298
    })
299
    context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
300 299

  
301 300
    # Cancel button
302 301
    if request.method == "POST" \
......
411 410
        request = self.request
412 411

  
413 412
        context_instance = RequestContext(request, ctx)
414
        context_instance['add_to_blocks'] = collections.defaultdict(lambda: [])
415 413
        if request.method == "POST":
416 414
            for frontend in frontends:
417 415
                if 'submit-%s' % frontend.id in request.POST:
418
-