Projet

Général

Profil

0001-templates-replace-use-of-sekizai-by-our-own-template.patch

Benjamin Dauvergne, 14 mai 2015 22:53

Télécharger (7,58 ko)

Voir les différences:

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
src/authentic2/context_processors.py
1
from collections import defaultdict
2

  
1 3
from pkg_resources import get_distribution
2 4
from django.conf import settings
3 5

  
......
38 40
        else:
39 41
            __AUTHENTIC2_DISTRIBUTION = str(get_distribution('authentic2'))
40 42
    variables['AUTHENTIC2_VERSION'] = __AUTHENTIC2_DISTRIBUTION
43
    variables['add_to_blocks'] = defaultdict(lambda:[])
41 44
    return variables
src/authentic2/settings.py
52 52
    'django.contrib.messages.context_processors.messages',
53 53
    'django.core.context_processors.static',
54 54
    'authentic2.context_processors.a2_processor',
55
    'sekizai.context_processors.sekizai',
56 55
)
57 56

  
58 57
MIDDLEWARE_CLASSES = (
......
118 117
    'authentic2.custom_user',
119 118
    'authentic2',
120 119
    'gadjo',
121
    'sekizai',
122 120
)
123 121

  
124 122
INSTALLED_APPS = tuple(plugins.register_plugins_installed_apps(INSTALLED_APPS))
src/authentic2/templates/authentic2/login.html
1 1
{% extends "base.html" %}
2
{% load i18n sekizai_tags gadjo %}
2
{% load i18n gadjo authentic2 %}
3 3

  
4 4
{% block title %}
5 5
  {% trans "Log in" %}
6 6
{% endblock %}
7 7

  
8
{% block extra_scripts %}
9
<link rel="stylesheet" href="{{ STATIC_URL }}jquery/css/jquery-ui.custom.css" />
10
<link rel="stylesheet" href="{{ STATIC_URL }}ulx/css/ulx.css" />
11
<script type="text/javascript" src="{% xstatic 'jquery' 'jquery.min.js' %}"></script>
12
<script type="text/javascript" src="{% xstatic 'jquery-ui' 'jquery-ui.min.js' %}"></script>
13
<script type="text/javascript" src="{{ STATIC_URL }}jquery/js/jquery.cookie.js"></script>
14
<script type="text/javascript" src="{{ STATIC_URL }}jquery/js/jquery.simplemodal.js"></script>
15
{% endblock %}
16

  
8 17
{% block content %}
9 18
  <div id="tabs">
10 19
    <ul>
......
23 32
  <script type="text/javascript">
24 33
    $( "#tabs" ).tabs({cookie: {path: '/'}});
25 34
  </script>
26
  {% addtoblock "css" %}<link rel="stylesheet" href="{{ STATIC_URL }}jquery/css/jquery-ui.custom.css" />{% endaddtoblock %}
27
  {% addtoblock "css" %}<link rel="stylesheet" href="{{ STATIC_URL }}ulx/css/ulx.css" />{% endaddtoblock %}
28
  {% addtoblock "js" %}<script type="text/javascript" src="{% xstatic 'jquery' 'jquery.min.js' %}"></script>{% endaddtoblock %}
29
  {% addtoblock "js" %}<script type="text/javascript" src="{% xstatic 'jquery-ui' 'jquery-ui.min.js' %}"></script>{% endaddtoblock %}
30
  {% addtoblock "js" %}<script type="text/javascript" src="{{ STATIC_URL }}jquery/js/jquery.cookie.js"></script>{% endaddtoblock %}
31
  {% addtoblock "js" %}<script type="text/javascript" src="{{ STATIC_URL }}jquery/js/jquery.simplemodal.js"></script>{% endaddtoblock %}
32 35
{% endblock %}
src/authentic2/templates/authentic2/login_password_form.html
1
{% load i18n sekizai_tags staticfiles %}
1
{% load i18n authentic2 staticfiles %}
2 2
<div>
3 3
<form method="post" action="">
4 4
{% csrf_token %}
src/authentic2/templates/authentic2/logout_confirm.html
1 1
{% extends "base.html" %}
2
{% load i18n sekizai_tags gadjo %}
2
{% load i18n gadjo %}
3 3

  
4 4

  
5 5
{% block title %}
src/authentic2/templates/base.html
1
{% load i18n sekizai_tags%}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1
{% load i18n authentic2 %}<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 2
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 3
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
4 4
<head>
5 5
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
6 6
    <link rel="stylesheet" href="{{ STATIC_URL }}authentic2/css/style.css" />
7
    {% render_block "css" %}
8 7
    <title>{% block title %}User test{% endblock %}</title>
9 8
    {% block extra_scripts %}
9
       {% renderblock "css" %}
10
       {% renderblock "js" %}
10 11
    {% endblock %}
11
    {% render_block "js" %}
12 12
</head>
13 13

  
14 14
<body {% block bodyargs %}{% endblock %} >
......
51 51
        {% endblock %}
52 52
    </div>
53 53
  </div>
54
  {% render_block "js-endpage" %}
54
  {% block js-endpage %}
55
  {% renderblock "js-endpage" %}
56
  {% endblock %}
55 57
</body>
56 58

  
57 59
</html>
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
    output = u'\n'.join(context['add_to_blocks'][block_name])
37
    return output
0
-