Projet

Général

Profil

0001-add-combo-templatetags-in-builtins-37273.patch

Thomas Noël, 28 octobre 2019 15:10

Télécharger (15,2 ko)

Voir les différences:

Subject: [PATCH] add combo templatetags in builtins (#37273)

 .../templates/combo/dashboardcell.html        |  2 +-
 combo/apps/family/templates/family/infos.html |  2 +-
 .../apps/lingo/templates/lingo/tipi_form.html |  2 +-
 .../pwa/templates/combo/pwa/navigation.html   |  1 -
 .../combo/service-worker-registration.js      |  2 --
 .../pwa/templates/combo/service-worker.js     |  2 +-
 .../combo/wcs/backoffice_submission.html      |  2 +-
 .../templates/combo/wcs/current_drafts.html   |  2 +-
 .../templates/combo/wcs/user_all_forms.html   |  2 +-
 .../templates/combo/wcs/user_done_forms.html  |  2 +-
 combo/profile/models.py                       |  2 +-
 combo/public/templates/combo/menu.html        |  1 -
 .../public/templates/combo/page_template.html |  2 +-
 .../combo/page_template_sidebar.html          |  2 +-
 combo/public/templates/combo/placeholder.html |  2 +-
 combo/public/views.py                         |  2 +-
 combo/settings.py                             |  3 +++
 ...page_template_synchronous_placeholder.html |  2 +-
 tests/test_cells.py                           |  2 +-
 tests/test_manager.py                         |  2 +-
 tests/test_public_templatetags.py             | 24 +++++++++----------
 21 files changed, 31 insertions(+), 32 deletions(-)
combo/apps/dashboard/templates/combo/dashboardcell.html
1
{% load combo i18n %}
1
{% load i18n %}
2 2
{% block cell-content %}
3 3
{% for tile in tiles %}
4 4
{% with cell=tile.cell %}
combo/apps/family/templates/family/infos.html
1
{% load i18n combo %}
1
{% load i18n %}
2 2
{% block cell-content %}
3 3
<h2>{% trans "Informations related to your family" %}</h2>
4 4

  
combo/apps/lingo/templates/lingo/tipi_form.html
1
{% load i18n combo %}
1
{% load i18n %}
2 2
{% if title %}<h2>{{ title }}</h2>{% endif %}
3 3
<div>
4 4
  {% trans "Introduction" context "tipi" as tipi_intro %}
combo/apps/pwa/templates/combo/pwa/navigation.html
1
{% load combo %}
2 1
{% if entries|length %}
3 2
<div class="pwa-navigation" id="pwa-navigation"
4 3
  {% if include_user_name %}data-pwa-user-name="{% skeleton_extra_placeholder user-name %}{{user.get_full_name}}{% end_skeleton_extra_placeholder %}"{% endif %}>
combo/apps/pwa/templates/combo/service-worker-registration.js
1
{% load combo %}
2

  
3 1
var applicationServerPublicKey = {{ pwa_vapid_public_key|as_json|safe }};
4 2
var COMBO_PWA_USER_SUBSCRIPTION = false;
5 3

  
combo/apps/pwa/templates/combo/service-worker.js
1
{% load combo gadjo static thumbnail %}
1
{% load gadjo static thumbnail %}
2 2

  
3 3
/* global self, caches, fetch, URL, Response */
4 4
'use strict';
combo/apps/wcs/templates/combo/wcs/backoffice_submission.html
1
{% load combo i18n %}
1
{% load i18n %}
2 2
{% block cell-content %}
3 3
<h2>{% trans "New Form" %}</h2>
4 4
{% for site_formdefs in all_formdefs.values %}
combo/apps/wcs/templates/combo/wcs/current_drafts.html
1
{% load i18n combo %}
1
{% load i18n %}
2 2
{% block cell-content %}
3 3
<h2>{% trans 'Current Drafts' %}</h2>
4 4
{% for slug, forms in current_drafts.items %}
combo/apps/wcs/templates/combo/wcs/user_all_forms.html
1
{% load combo i18n %}
1
{% load i18n %}
2 2
{% block cell-content %}
3 3
<h2>{% trans 'All Forms' %}</h2>
4 4
{% for slug, forms in user_forms.items %}
combo/apps/wcs/templates/combo/wcs/user_done_forms.html
1
{% load combo i18n %}
1
{% load i18n %}
2 2
{% block cell-content %}
3 3
<h2>{% trans 'Done Forms' %}</h2>
4 4
{% for slug, forms in user_forms.items %}
combo/profile/models.py
43 43
    @property
44 44
    def url(self):
45 45
        idp = list(settings.KNOWN_SERVICES.get('authentic').values())[0]
46
        return '{%% load combo %%}%sapi/users/{{ concerned_user|name_id }}/' % idp.get('url')
46
        return '%sapi/users/{{ concerned_user|name_id }}/' % idp.get('url')
47 47

  
48 48
    def is_visible(self, user=None):
49 49
        if not user or user.is_anonymous():
combo/public/templates/combo/menu.html
1
{% load combo %}
2 1
{% if menuitems %}
3 2
<ul>
4 3
{% spaceless %}
combo/public/templates/combo/page_template.html
1
{% load combo gadjo i18n %}<!DOCTYPE html>
1
{% load gadjo i18n %}<!DOCTYPE html>
2 2
<html>
3 3
 <head>
4 4
  <meta charset="utf-8"/>
combo/public/templates/combo/page_template_sidebar.html
1 1
{% extends "combo/page_template.html" %}
2
{% load combo i18n %}
2
{% load i18n %}
3 3

  
4 4
{% block combo-content %}
5 5
<div id="main-content">
combo/public/templates/combo/placeholder.html
1
{% load combo i18n %}
1
{% load i18n %}
2 2
{% if render %}
3 3
{% for cell in cells %}
4 4
<div class="cell {{ cell.css_class_names }} {% if cell.slug %}{{cell.slug}}{% endif %} {% if cell|shown_because_admin:request %}shown-because-admin{% endif %}"
combo/public/views.py
164 164
                # Cell can pass data through its own __dict__
165 165
                cell.modify_global_context(context, request)
166 166

  
167
    template = engines['django'].from_string('{% load combo %}{% render_cell cell %}')
167
    template = engines['django'].from_string('{% render_cell cell %}')
168 168
    return HttpResponse(template.render(context, request), content_type='text/html')
169 169

  
170 170

  
combo/settings.py
118 118
                'django.contrib.messages.context_processors.messages',
119 119
                'combo.context_processors.template_vars',
120 120
            ],
121
            'builtins': [
122
                'combo.public.templatetags.combo',
123
            ],
121 124
        },
122 125
    },
123 126
]
tests/templates-1/combo/page_template_synchronous_placeholder.html
1 1
{% extends "combo/page_template.html" %}
2
{% load combo i18n %}
2
{% load i18n %}
3 3

  
4 4
{% block combo-content %}
5 5
<div id="main-content">
tests/test_cells.py
667 667
    page = Page(title='Test', slug='test', template_name='standard')
668 668
    page.save()
669 669
    json_cell = JsonCell(page=page, placeholder='content', order=0, url='http://example.com')
670
    json_cell.template_string = '{% load combo %}{% placeholder "foobar" name="Foobar" %}'
670
    json_cell.template_string = '{% placeholder "foobar" name="Foobar" %}'
671 671
    json_cell.save()
672 672

  
673 673
    TextCell(page=page, placeholder='foobar', text='<p>Public text</p>', order=0,
tests/test_manager.py
1054 1054
    assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer']
1055 1055

  
1056 1056
    # check a placeholder within a cell is included
1057
    cell.template_string = '{% load combo %}{% placeholder "foobar" name="Foobar" %}'
1057
    cell.template_string = '{% placeholder "foobar" name="Foobar" %}'
1058 1058
    cell.save()
1059 1059
    resp = app.get('/manage/pages/%s/' % page.id)
1060 1060
    assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'foobar', 'footer']
tests/test_public_templatetags.py
19 19

  
20 20

  
21 21
def test_strptime():
22
    t = Template('{% load combo %}{{ someday|strptime:"%Y-%m-%d"|date:"Y" }}')
22
    t = Template('{{ someday|strptime:"%Y-%m-%d"|date:"Y" }}')
23 23
    assert t.render(Context({'someday': '2015-04-15'})) == '2015'
24 24
    assert t.render(Context({'someday': 'foobar'})) == ''
25 25
    assert t.render(Context({'someday': None})) == ''
......
27 27
    assert t.render(Context({'someday': ['foo', 'bar']})) == ''
28 28

  
29 29
def test_parse_datetime():
30
    t = Template('{% load combo %}{{ someday|parse_datetime|date:"Y m d H i s T" }}')
30
    t = Template('{{ someday|parse_datetime|date:"Y m d H i s T" }}')
31 31
    expected = '2015 04 15 13 11 12 UTC'
32 32
    assert t.render(Context({'someday': '2015-04-15T13:11:12'})) == expected
33 33
    assert t.render(Context({'someday': '2015-04-15 13:11:12'})) == expected
......
45 45
    assert t.render(Context({'someday': {'foo': 'bar'}})) == ''
46 46
    assert t.render(Context({'someday': ['foo', 'bar']})) == ''
47 47

  
48
    t = Template('{% load combo %}{{ someday|parse_date|date:"Y m d" }}')
48
    t = Template('{{ someday|parse_date|date:"Y m d" }}')
49 49
    expected = '2015 04 15'
50 50
    assert t.render(Context({'someday': '2015-04-15'})) == expected
51 51
    assert t.render(Context({'someday': '2015-04-15T13:11:12Z'})) == ''
......
55 55
    assert t.render(Context({'someday': {'foo': 'bar'}})) == ''
56 56
    assert t.render(Context({'someday': ['foo', 'bar']})) == ''
57 57

  
58
    t = Template('{% load combo %}{{ someday|parse_time|date:"H i s" }}')
58
    t = Template('{{ someday|parse_time|date:"H i s" }}')
59 59
    expected = '13 11 12'
60 60
    assert t.render(Context({'someday': '13:11:12'})) == expected
61 61
    assert t.render(Context({'someday': '13:11:12Z'})) == expected
......
73 73
    assert t.render(Context({'someday': ['foo', 'bar']})) == ''
74 74

  
75 75
def test_has_role():
76
    t = Template('{% load combo %}{{ request.user|has_role:"Role1" }}')
76
    t = Template('{{ request.user|has_role:"Role1" }}')
77 77

  
78 78
    request = RequestFactory().get('/')
79 79
    user = User(username='foo', email='foo@example.net')
......
88 88
    user.save()
89 89
    assert t.render(context) == 'True'
90 90

  
91
    t = Template('{% load combo %}{{ request.user|has_role:"Role2" }}')
91
    t = Template('{{ request.user|has_role:"Role2" }}')
92 92
    assert t.render(context) == 'False'
93 93
    group = Group(name='Role2')
94 94
    group.save()
......
106 106
    assert t.render(context) == 'False'
107 107

  
108 108
def test_get():
109
    t = Template('{% load combo %}{{ foo|get:"foo-bar" }}')
109
    t = Template('{{ foo|get:"foo-bar" }}')
110 110
    context = Context({'foo': {'foo-bar': 'hello'}})
111 111
    assert t.render(context) == 'hello'
112 112
    context = Context({'foo': {'bar-foo': 'hello'}})
......
114 114
    context = Context({'foo': None})
115 115
    assert t.render(context) == 'None'
116 116

  
117
    t = Template('{% load combo %}{{ foo|get:"foo-bar"|default:"" }}')
117
    t = Template('{{ foo|get:"foo-bar"|default:"" }}')
118 118
    context = Context({'foo': {'rab': 'hello'}})
119 119
    assert t.render(context) == ''
120 120

  
121
    t = Template('{% load combo %}{{ foo|get:key }}')
121
    t = Template('{{ foo|get:key }}')
122 122
    context = Context({'foo': {'foo-bar': 'hello'}, 'key': 'foo-bar'})
123 123
    assert t.render(context) == 'hello'
124 124

  
125 125
def test_split():
126
    t = Template('{% load combo %}{% for x in plop|split %}{{x}}<br>{% endfor %}')
126
    t = Template('{% for x in plop|split %}{{x}}<br>{% endfor %}')
127 127
    assert t.render(Context({'plop': 'ab cd ef'})) == 'ab<br>cd<br>ef<br>'
128
    t = Template('{% load combo %}{% for x in plop|split:"|" %}{{x}} {% endfor %}')
128
    t = Template('{% for x in plop|split:"|" %}{{x}} {% endfor %}')
129 129
    assert t.render(Context({'plop': 'ab|cd|ef'})) == 'ab cd ef '
130 130

  
131 131
def test_get_group():
......
136 136
        {'name': 'Chicago', 'population': '7,000,000', 'country': 'USA'},
137 137
        {'name': 'Tokyo', 'population': '33,000,000', 'country': 'Japan'},
138 138
    ]})
139
    t = Template('{% load combo %}{% regroup cities by country as country_list %}'
139
    t = Template('{% regroup cities by country as country_list %}'
140 140
                 '{% for c in country_list|get_group:"USA" %}{{c.name}},{% endfor %}')
141 141
    assert t.render(context) == 'New York,Chicago,'
142 142

  
143
-