From 6f253286a75401ed864a3f71dc898f61d498c419 Mon Sep 17 00:00:00 2001
From: Thomas NOEL <tnoel@entrouvert.com>
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 729f6c7..7a4bbd8 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 7dcfd5d..596f04c 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 %}
 <h2>{% trans "Informations related to your family" %}</h2>
 
diff --git a/combo/apps/lingo/templates/lingo/tipi_form.html b/combo/apps/lingo/templates/lingo/tipi_form.html
index d0f87bc..7a71c2d 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 %}<h2>{{ title }}</h2>{% endif %}
 <div>
   {% 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 ca8cf5e..71e0df9 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 %}
 <div class="pwa-navigation" id="pwa-navigation"
   {% if include_user_name %}data-pwa-user-name="{% skeleton_extra_placeholder user-name %}{{user.get_full_name}}{% end_skeleton_extra_placeholder %}"{% endif %}>
diff --git a/combo/apps/pwa/templates/combo/service-worker-registration.js b/combo/apps/pwa/templates/combo/service-worker-registration.js
index 0dc27e6..a3669a7 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 47673bf..c3348fc 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 83e431b..136a7d9 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 %}
 <h2>{% trans "New Form" %}</h2>
 {% 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 853f849..9e7489e 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 %}
 <h2>{% trans 'Current Drafts' %}</h2>
 {% 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 36c2faa..10b83e7 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 %}
 <h2>{% trans 'All Forms' %}</h2>
 {% 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 2455a6f..be4c61b 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 %}
 <h2>{% trans 'Done Forms' %}</h2>
 {% for slug, forms in user_forms.items %}
diff --git a/combo/profile/models.py b/combo/profile/models.py
index 229b0c6..ebf0e15 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 dc74f9a..8a8b241 100644
--- a/combo/public/templates/combo/menu.html
+++ b/combo/public/templates/combo/menu.html
@@ -1,4 +1,3 @@
-{% load combo %}
 {% if menuitems %}
 <ul>
 {% spaceless %}
diff --git a/combo/public/templates/combo/page_template.html b/combo/public/templates/combo/page_template.html
index 7d22838..5d830ad 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 %}<!DOCTYPE html>
+{% load gadjo i18n %}<!DOCTYPE html>
 <html>
  <head>
   <meta charset="utf-8"/>
diff --git a/combo/public/templates/combo/page_template_sidebar.html b/combo/public/templates/combo/page_template_sidebar.html
index 06ed505..0b06fac 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 %}
 <div id="main-content">
diff --git a/combo/public/templates/combo/placeholder.html b/combo/public/templates/combo/placeholder.html
index 71830a1..58aa65a 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 %}
 {% for cell in cells %}
 <div class="cell {{ cell.css_class_names }} {% if cell.slug %}{{cell.slug}}{% endif %} {% if cell|shown_because_admin:request %}shown-because-admin{% endif %}"
diff --git a/combo/public/views.py b/combo/public/views.py
index e690754..07d48b1 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 d859cb3..1114ca8 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 b82454c..005ee7d 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 %}
 <div id="main-content">
diff --git a/tests/test_cells.py b/tests/test_cells.py
index dd46fa8..89ddb09 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='<p>Public text</p>', order=0,
diff --git a/tests/test_manager.py b/tests/test_manager.py
index 136e8f9..61a945c 100644
--- a/tests/test_manager.py
+++ b/tests/test_manager.py
@@ -1054,7 +1054,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 2ede145..ead51e4 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}}<br>{% endfor %}')
+    t = Template('{% for x in plop|split %}{{x}}<br>{% endfor %}')
     assert t.render(Context({'plop': 'ab cd ef'})) == 'ab<br>cd<br>ef<br>'
-    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,'
 
-- 
2.23.0

