From 57542ab058647c13300758af1a845991a99308bb Mon Sep 17 00:00:00 2001 From: Thomas NOEL Date: Mon, 28 Oct 2019 15:08:41 +0100 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(-) diff --git a/combo/apps/dashboard/templates/combo/dashboardcell.html b/combo/apps/dashboard/templates/combo/dashboardcell.html index daf76666..358ffa38 100644 --- a/combo/apps/dashboard/templates/combo/dashboardcell.html +++ b/combo/apps/dashboard/templates/combo/dashboardcell.html @@ -1,4 +1,4 @@ -{% load combo i18n %} +{% load i18n %} {% block cell-content %} {% for tile in tiles %} {% with cell=tile.cell %} diff --git a/combo/apps/family/templates/family/infos.html b/combo/apps/family/templates/family/infos.html index 7dcfd5d9..596f04c1 100644 --- a/combo/apps/family/templates/family/infos.html +++ b/combo/apps/family/templates/family/infos.html @@ -1,4 +1,4 @@ -{% load i18n combo %} +{% load i18n %} {% block cell-content %}

{% trans "Informations related to your family" %}

diff --git a/combo/apps/lingo/templates/lingo/tipi_form.html b/combo/apps/lingo/templates/lingo/tipi_form.html index d0f87bc4..7a71c2d7 100644 --- a/combo/apps/lingo/templates/lingo/tipi_form.html +++ b/combo/apps/lingo/templates/lingo/tipi_form.html @@ -1,4 +1,4 @@ -{% load i18n combo %} +{% load i18n %} {% if title %}

{{ title }}

{% endif %}
{% trans "Introduction" context "tipi" as tipi_intro %} diff --git a/combo/apps/pwa/templates/combo/pwa/navigation.html b/combo/apps/pwa/templates/combo/pwa/navigation.html index ca8cf5e3..71e0df91 100644 --- a/combo/apps/pwa/templates/combo/pwa/navigation.html +++ b/combo/apps/pwa/templates/combo/pwa/navigation.html @@ -1,4 +1,3 @@ -{% load combo %} {% if entries|length %}
diff --git a/combo/apps/pwa/templates/combo/service-worker-registration.js b/combo/apps/pwa/templates/combo/service-worker-registration.js index 0dc27e68..a3669a7b 100644 --- a/combo/apps/pwa/templates/combo/service-worker-registration.js +++ b/combo/apps/pwa/templates/combo/service-worker-registration.js @@ -1,5 +1,3 @@ -{% load combo %} - var applicationServerPublicKey = {{ pwa_vapid_public_key|as_json|safe }}; var COMBO_PWA_USER_SUBSCRIPTION = false; diff --git a/combo/apps/pwa/templates/combo/service-worker.js b/combo/apps/pwa/templates/combo/service-worker.js index 47673bff..c3348fc3 100644 --- a/combo/apps/pwa/templates/combo/service-worker.js +++ b/combo/apps/pwa/templates/combo/service-worker.js @@ -1,4 +1,4 @@ -{% load combo gadjo static thumbnail %} +{% load gadjo static thumbnail %} /* global self, caches, fetch, URL, Response */ 'use strict'; diff --git a/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html b/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html index 83e431b7..136a7d95 100644 --- a/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html +++ b/combo/apps/wcs/templates/combo/wcs/backoffice_submission.html @@ -1,4 +1,4 @@ -{% load combo i18n %} +{% load i18n %} {% block cell-content %}

{% trans "New Form" %}

{% for site_formdefs in all_formdefs.values %} diff --git a/combo/apps/wcs/templates/combo/wcs/current_drafts.html b/combo/apps/wcs/templates/combo/wcs/current_drafts.html index 853f8493..9e7489e3 100644 --- a/combo/apps/wcs/templates/combo/wcs/current_drafts.html +++ b/combo/apps/wcs/templates/combo/wcs/current_drafts.html @@ -1,4 +1,4 @@ -{% load i18n combo %} +{% load i18n %} {% block cell-content %}

{% trans 'Current Drafts' %}

{% for slug, forms in current_drafts.items %} diff --git a/combo/apps/wcs/templates/combo/wcs/user_all_forms.html b/combo/apps/wcs/templates/combo/wcs/user_all_forms.html index 36c2faaf..10b83e76 100644 --- a/combo/apps/wcs/templates/combo/wcs/user_all_forms.html +++ b/combo/apps/wcs/templates/combo/wcs/user_all_forms.html @@ -1,4 +1,4 @@ -{% load combo i18n %} +{% load i18n %} {% block cell-content %}

{% trans 'All Forms' %}

{% for slug, forms in user_forms.items %} diff --git a/combo/apps/wcs/templates/combo/wcs/user_done_forms.html b/combo/apps/wcs/templates/combo/wcs/user_done_forms.html index 2455a6fe..be4c61bc 100644 --- a/combo/apps/wcs/templates/combo/wcs/user_done_forms.html +++ b/combo/apps/wcs/templates/combo/wcs/user_done_forms.html @@ -1,4 +1,4 @@ -{% load combo i18n %} +{% load i18n %} {% block cell-content %}

{% trans 'Done Forms' %}

{% for slug, forms in user_forms.items %} diff --git a/combo/profile/models.py b/combo/profile/models.py index 0e1ad4c1..6c5c4a0e 100644 --- a/combo/profile/models.py +++ b/combo/profile/models.py @@ -43,7 +43,7 @@ class ProfileCell(JsonCellBase): @property def url(self): idp = list(settings.KNOWN_SERVICES.get('authentic').values())[0] - return '{%% load combo %%}%sapi/users/{{ concerned_user|name_id }}/' % idp.get('url') + return '%sapi/users/{{ concerned_user|name_id }}/' % idp.get('url') def is_visible(self, user=None): if not user or user.is_anonymous: diff --git a/combo/public/templates/combo/menu.html b/combo/public/templates/combo/menu.html index dc74f9ac..8a8b241a 100644 --- a/combo/public/templates/combo/menu.html +++ b/combo/public/templates/combo/menu.html @@ -1,4 +1,3 @@ -{% load combo %} {% if menuitems %}
    {% spaceless %} diff --git a/combo/public/templates/combo/page_template.html b/combo/public/templates/combo/page_template.html index 7d22838c..5d830adf 100644 --- a/combo/public/templates/combo/page_template.html +++ b/combo/public/templates/combo/page_template.html @@ -1,4 +1,4 @@ -{% load combo gadjo i18n %} +{% load gadjo i18n %} diff --git a/combo/public/templates/combo/page_template_sidebar.html b/combo/public/templates/combo/page_template_sidebar.html index 06ed5055..0b06fac7 100644 --- a/combo/public/templates/combo/page_template_sidebar.html +++ b/combo/public/templates/combo/page_template_sidebar.html @@ -1,5 +1,5 @@ {% extends "combo/page_template.html" %} -{% load combo i18n %} +{% load i18n %} {% block combo-content %}
    diff --git a/combo/public/templates/combo/placeholder.html b/combo/public/templates/combo/placeholder.html index dfa97e31..4ec2369e 100644 --- a/combo/public/templates/combo/placeholder.html +++ b/combo/public/templates/combo/placeholder.html @@ -1,4 +1,4 @@ -{% load combo i18n %} +{% load i18n %} {% if render %} {% if render_skeleton %} {{ skeleton }} diff --git a/combo/public/views.py b/combo/public/views.py index 6ed152d5..e607a82e 100644 --- a/combo/public/views.py +++ b/combo/public/views.py @@ -164,7 +164,7 @@ def render_cell(request, cell): # Cell can pass data through its own __dict__ cell.modify_global_context(context, request) - template = engines['django'].from_string('{% load combo %}{% render_cell cell %}') + template = engines['django'].from_string('{% render_cell cell %}') return HttpResponse(template.render(context, request), content_type='text/html') diff --git a/combo/settings.py b/combo/settings.py index d859cb30..1114ca8e 100644 --- a/combo/settings.py +++ b/combo/settings.py @@ -118,6 +118,9 @@ TEMPLATES = [ 'django.contrib.messages.context_processors.messages', 'combo.context_processors.template_vars', ], + 'builtins': [ + 'combo.public.templatetags.combo', + ], }, }, ] diff --git a/tests/templates-1/combo/page_template_synchronous_placeholder.html b/tests/templates-1/combo/page_template_synchronous_placeholder.html index b82454c9..005ee7dc 100644 --- a/tests/templates-1/combo/page_template_synchronous_placeholder.html +++ b/tests/templates-1/combo/page_template_synchronous_placeholder.html @@ -1,5 +1,5 @@ {% extends "combo/page_template.html" %} -{% load combo i18n %} +{% load i18n %} {% block combo-content %}
    diff --git a/tests/test_cells.py b/tests/test_cells.py index dd46fa8c..89ddb096 100644 --- a/tests/test_cells.py +++ b/tests/test_cells.py @@ -667,7 +667,7 @@ def test_page_cell_placeholder_restricted_visibility(app, admin_user): page = Page(title='Test', slug='test', template_name='standard') page.save() json_cell = JsonCell(page=page, placeholder='content', order=0, url='http://example.com') - json_cell.template_string = '{% load combo %}{% placeholder "foobar" name="Foobar" %}' + json_cell.template_string = '{% placeholder "foobar" name="Foobar" %}' json_cell.save() TextCell(page=page, placeholder='foobar', text='

    Public text

    ', order=0, diff --git a/tests/test_manager.py b/tests/test_manager.py index 4c990127..5cdeac90 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1166,7 +1166,7 @@ def test_page_cell_placeholder(app, admin_user): assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'footer'] # check a placeholder within a cell is included - cell.template_string = '{% load combo %}{% placeholder "foobar" name="Foobar" %}' + cell.template_string = '{% placeholder "foobar" name="Foobar" %}' cell.save() resp = app.get('/manage/pages/%s/' % page.id) assert re.findall('data-placeholder-key="(.*)">', resp.text) == ['content', 'foobar', 'footer'] diff --git a/tests/test_public_templatetags.py b/tests/test_public_templatetags.py index 2ede1452..ead51e40 100644 --- a/tests/test_public_templatetags.py +++ b/tests/test_public_templatetags.py @@ -19,7 +19,7 @@ pytestmark = pytest.mark.django_db def test_strptime(): - t = Template('{% load combo %}{{ someday|strptime:"%Y-%m-%d"|date:"Y" }}') + t = Template('{{ someday|strptime:"%Y-%m-%d"|date:"Y" }}') assert t.render(Context({'someday': '2015-04-15'})) == '2015' assert t.render(Context({'someday': 'foobar'})) == '' assert t.render(Context({'someday': None})) == '' @@ -27,7 +27,7 @@ def test_strptime(): assert t.render(Context({'someday': ['foo', 'bar']})) == '' def test_parse_datetime(): - t = Template('{% load combo %}{{ someday|parse_datetime|date:"Y m d H i s T" }}') + t = Template('{{ someday|parse_datetime|date:"Y m d H i s T" }}') expected = '2015 04 15 13 11 12 UTC' assert t.render(Context({'someday': '2015-04-15T13:11:12'})) == expected assert t.render(Context({'someday': '2015-04-15 13:11:12'})) == expected @@ -45,7 +45,7 @@ def test_parse_datetime(): assert t.render(Context({'someday': {'foo': 'bar'}})) == '' assert t.render(Context({'someday': ['foo', 'bar']})) == '' - t = Template('{% load combo %}{{ someday|parse_date|date:"Y m d" }}') + t = Template('{{ someday|parse_date|date:"Y m d" }}') expected = '2015 04 15' assert t.render(Context({'someday': '2015-04-15'})) == expected assert t.render(Context({'someday': '2015-04-15T13:11:12Z'})) == '' @@ -55,7 +55,7 @@ def test_parse_datetime(): assert t.render(Context({'someday': {'foo': 'bar'}})) == '' assert t.render(Context({'someday': ['foo', 'bar']})) == '' - t = Template('{% load combo %}{{ someday|parse_time|date:"H i s" }}') + t = Template('{{ someday|parse_time|date:"H i s" }}') expected = '13 11 12' assert t.render(Context({'someday': '13:11:12'})) == expected assert t.render(Context({'someday': '13:11:12Z'})) == expected @@ -73,7 +73,7 @@ def test_parse_datetime(): assert t.render(Context({'someday': ['foo', 'bar']})) == '' def test_has_role(): - t = Template('{% load combo %}{{ request.user|has_role:"Role1" }}') + t = Template('{{ request.user|has_role:"Role1" }}') request = RequestFactory().get('/') user = User(username='foo', email='foo@example.net') @@ -88,7 +88,7 @@ def test_has_role(): user.save() assert t.render(context) == 'True' - t = Template('{% load combo %}{{ request.user|has_role:"Role2" }}') + t = Template('{{ request.user|has_role:"Role2" }}') assert t.render(context) == 'False' group = Group(name='Role2') group.save() @@ -106,7 +106,7 @@ def test_has_role(): assert t.render(context) == 'False' def test_get(): - t = Template('{% load combo %}{{ foo|get:"foo-bar" }}') + t = Template('{{ foo|get:"foo-bar" }}') context = Context({'foo': {'foo-bar': 'hello'}}) assert t.render(context) == 'hello' context = Context({'foo': {'bar-foo': 'hello'}}) @@ -114,18 +114,18 @@ def test_get(): context = Context({'foo': None}) assert t.render(context) == 'None' - t = Template('{% load combo %}{{ foo|get:"foo-bar"|default:"" }}') + t = Template('{{ foo|get:"foo-bar"|default:"" }}') context = Context({'foo': {'rab': 'hello'}}) assert t.render(context) == '' - t = Template('{% load combo %}{{ foo|get:key }}') + t = Template('{{ foo|get:key }}') context = Context({'foo': {'foo-bar': 'hello'}, 'key': 'foo-bar'}) assert t.render(context) == 'hello' def test_split(): - t = Template('{% load combo %}{% for x in plop|split %}{{x}}
    {% endfor %}') + t = Template('{% for x in plop|split %}{{x}}
    {% endfor %}') assert t.render(Context({'plop': 'ab cd ef'})) == 'ab
    cd
    ef
    ' - t = Template('{% load combo %}{% for x in plop|split:"|" %}{{x}} {% endfor %}') + t = Template('{% for x in plop|split:"|" %}{{x}} {% endfor %}') assert t.render(Context({'plop': 'ab|cd|ef'})) == 'ab cd ef ' def test_get_group(): @@ -136,7 +136,7 @@ def test_get_group(): {'name': 'Chicago', 'population': '7,000,000', 'country': 'USA'}, {'name': 'Tokyo', 'population': '33,000,000', 'country': 'Japan'}, ]}) - t = Template('{% load combo %}{% regroup cities by country as country_list %}' + t = Template('{% regroup cities by country as country_list %}' '{% for c in country_list|get_group:"USA" %}{{c.name}},{% endfor %}') assert t.render(context) == 'New York,Chicago,'