From 02b8fa3cef8973534383ed99a8fd49c4247832cc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20P=C3=A9ters?= <fpeters@entrouvert.com>
Date: Fri, 23 Jul 2021 12:37:23 +0200
Subject: [PATCH 1/5] general: rename cell template_name attribute to
 default_template_name (#55792)

---
 combo/apps/calendar/models.py |  2 +-
 combo/apps/dataviz/models.py  |  4 ++--
 combo/apps/family/models.py   |  2 +-
 combo/apps/fargo/models.py    |  2 +-
 combo/apps/gallery/models.py  |  2 +-
 combo/apps/kb/models.py       |  2 +-
 combo/apps/lingo/models.py    |  6 +++---
 combo/apps/maps/models.py     |  2 +-
 combo/apps/search/models.py   |  2 +-
 combo/apps/wcs/models.py      | 22 +++++++++++-----------
 combo/data/models.py          | 22 +++++++++++-----------
 combo/profile/models.py       |  2 +-
 tests/test_cells.py           | 14 +++++++-------
 tests/test_lingo_cells.py     |  2 +-
 14 files changed, 43 insertions(+), 43 deletions(-)

diff --git a/combo/apps/calendar/models.py b/combo/apps/calendar/models.py
index 79aac451..a0669df7 100644
--- a/combo/apps/calendar/models.py
+++ b/combo/apps/calendar/models.py
@@ -44,7 +44,7 @@ class BookingCalendar(CellBase):
     )
     days_displayed = models.PositiveSmallIntegerField(_('Number of days to display'), default=7)
 
-    template_name = 'calendar/booking_calendar_cell.html'
+    default_template_name = 'calendar/booking_calendar_cell.html'
 
     class Meta:
         verbose_name = _('Booking Calendar')
diff --git a/combo/apps/dataviz/models.py b/combo/apps/dataviz/models.py
index 7e543952..68d32365 100644
--- a/combo/apps/dataviz/models.py
+++ b/combo/apps/dataviz/models.py
@@ -53,7 +53,7 @@ class Gauge(CellBase):
     jsonp_data_source = models.BooleanField(_('Use JSONP to get data'), default=True)
     max_value = models.PositiveIntegerField(_('Max Value'), blank=True, null=True)
 
-    template_name = 'combo/gauge-cell.html'
+    default_template_name = 'combo/gauge-cell.html'
 
     class Media:
         js = ('js/gauge.min.js', 'js/combo.gauge.js')
@@ -84,7 +84,7 @@ class Gauge(CellBase):
 
 @register_cell_class
 class ChartCell(CellBase):
-    template_name = 'combo/dataviz-chart.html'
+    default_template_name = 'combo/dataviz-chart.html'
 
     title = models.CharField(_('Title'), max_length=150, blank=True, null=True)
     url = models.URLField(_('URL'), max_length=250, blank=True, null=True)
diff --git a/combo/apps/family/models.py b/combo/apps/family/models.py
index fb7e7fbe..88469257 100644
--- a/combo/apps/family/models.py
+++ b/combo/apps/family/models.py
@@ -24,7 +24,7 @@ from .utils import get_family, is_family_enabled
 
 @register_cell_class
 class FamilyInfosCell(CellBase):
-    template_name = 'family/infos.html'
+    default_template_name = 'family/infos.html'
     user_dependant = True
 
     class Meta:
diff --git a/combo/apps/fargo/models.py b/combo/apps/fargo/models.py
index 418eafe2..5578a121 100644
--- a/combo/apps/fargo/models.py
+++ b/combo/apps/fargo/models.py
@@ -32,7 +32,7 @@ logger = logging.getLogger(__name__)
 
 @register_cell_class
 class RecentDocumentsCell(CellBase):
-    template_name = 'combo/fargo/recent-documents-cell.html'
+    default_template_name = 'combo/fargo/recent-documents-cell.html'
     fargo_site = models.CharField(_('Site'), max_length=50, blank=True)
     user_dependant = True
 
diff --git a/combo/apps/gallery/models.py b/combo/apps/gallery/models.py
index bfb1dadf..4d603423 100644
--- a/combo/apps/gallery/models.py
+++ b/combo/apps/gallery/models.py
@@ -29,7 +29,7 @@ from combo.data.models import CellBase
 @register_cell_class
 class GalleryCell(CellBase):
     title = models.CharField(_('Title'), max_length=50, blank=True, null=True)
-    template_name = 'combo/gallerycell.html'
+    default_template_name = 'combo/gallerycell.html'
     manager_form_template = 'combo/gallery_manager.html'
 
     class Meta:
diff --git a/combo/apps/kb/models.py b/combo/apps/kb/models.py
index 490f4974..2827a86c 100644
--- a/combo/apps/kb/models.py
+++ b/combo/apps/kb/models.py
@@ -37,7 +37,7 @@ class LatestPageUpdatesCell(CellBase):
     )
     limit = models.PositiveSmallIntegerField(_('Maximum number of entries'), default=10)
 
-    template_name = 'combo/latest-page-updates-cell.html'
+    default_template_name = 'combo/latest-page-updates-cell.html'
     exclude_from_search = True
 
     class Meta:
diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py
index 857a662d..0c83279d 100644
--- a/combo/apps/lingo/models.py
+++ b/combo/apps/lingo/models.py
@@ -1157,7 +1157,7 @@ class Items(CellBase):
     text = RichTextField(_('Text'), blank=True, null=True)
 
     user_dependant = True
-    template_name = 'lingo/combo/items.html'
+    default_template_name = 'lingo/combo/items.html'
     loading_message = _('Loading invoices...')
 
     class Meta:
@@ -1262,7 +1262,7 @@ class ActiveItems(Items):
 @register_cell_class
 class SelfDeclaredInvoicePayment(Items):
     user_dependant = False
-    template_name = 'lingo/combo/self-declared-invoice-payment.html'
+    default_template_name = 'lingo/combo/self-declared-invoice-payment.html'
 
     class Meta:
         verbose_name = _('Self declared invoice payment')
@@ -1313,7 +1313,7 @@ class TipiPaymentFormCell(CellBase):
         'ROLDET', max_length=13, blank=True, help_text=_('Default value to be used in form')
     )
     test_mode = models.BooleanField(_('Test mode'), default=False)
-    template_name = 'lingo/tipi_form.html'
+    default_template_name = 'lingo/tipi_form.html'
 
     class Meta:
         verbose_name = _('TIPI Payment Form')
diff --git a/combo/apps/maps/models.py b/combo/apps/maps/models.py
index f514e9e1..2b888ae1 100644
--- a/combo/apps/maps/models.py
+++ b/combo/apps/maps/models.py
@@ -368,7 +368,7 @@ class Map(CellBase):
     )
     layers = models.ManyToManyField(MapLayer, through='MapLayerOptions', verbose_name=_('Layers'), blank=True)
 
-    template_name = 'maps/map_cell.html'
+    default_template_name = 'maps/map_cell.html'
     manager_form_template = 'maps/map_cell_form.html'
 
     class Meta:
diff --git a/combo/apps/search/models.py b/combo/apps/search/models.py
index 7d14b56c..0542d5d7 100644
--- a/combo/apps/search/models.py
+++ b/combo/apps/search/models.py
@@ -48,7 +48,7 @@ def get_root_page_and_children(service_slug):
 
 @register_cell_class
 class SearchCell(CellBase):
-    template_name = 'combo/search-cell.html'
+    default_template_name = 'combo/search-cell.html'
     manager_form_template = 'combo/manager/search-cell-form.html'
     exclude_from_search = True
 
diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py
index 9afa7cc3..b1635713 100644
--- a/combo/apps/wcs/models.py
+++ b/combo/apps/wcs/models.py
@@ -68,7 +68,7 @@ class WcsFormCell(CellBase):
     cached_url = models.URLField(_('URL'))
     cached_json = JSONField(blank=True, default=dict)
 
-    template_name = 'combo/wcs/form.html'
+    default_template_name = 'combo/wcs/form.html'
     add_as_link_label = _('add a form link')
     add_link_label = _('New form link')
     edit_link_label = _('Edit form link')
@@ -249,7 +249,7 @@ class WcsCommonCategoryCell(CellBase):
 
 @register_cell_class
 class WcsCategoryCell(WcsCommonCategoryCell):
-    template_name = 'combo/wcs/category.html'
+    default_template_name = 'combo/wcs/category.html'
 
     class Meta:
         verbose_name = _('Category Link')
@@ -481,7 +481,7 @@ class WcsCurrentFormsCell(CategoriesValidityMixin, CategoriesFilteringMixin, Wcs
         return url
 
     @property
-    def template_name(self):
+    def default_template_name(self):
         if self.current_forms and self.done_forms:
             return 'combo/wcs/user_all_forms.html'
         if self.done_forms:
@@ -544,7 +544,7 @@ class WcsCurrentFormsCell(CategoriesValidityMixin, CategoriesFilteringMixin, Wcs
 @register_cell_class
 class WcsCurrentDraftsCell(CategoriesValidityMixin, CategoriesFilteringMixin, WcsUserDataBaseCell):
     variable_name = 'current_drafts'
-    template_name = 'combo/wcs/current_drafts.html'
+    default_template_name = 'combo/wcs/current_drafts.html'
     loading_message = _('Loading drafts...')
 
     categories = JSONField(_('Categories'), blank=True, default=dict)
@@ -613,7 +613,7 @@ class WcsFormsOfCategoryCell(WcsCommonCategoryCell, WcsBlurpMixin):
         verbose_name = _('Forms of Category')
 
     variable_name = 'forms'
-    template_name = 'combo/wcs/forms_of_category.html'
+    default_template_name = 'combo/wcs/forms_of_category.html'
     cache_duration = 600
 
     def get_default_form_class(self):
@@ -718,7 +718,7 @@ class WcsCareFormsCell(CategoriesValidityMixin, CategoriesFilteringMixin, WcsDat
 
     api_url = '/api/forms/?limit=10'
     variable_name = 'care_forms'
-    template_name = 'combo/wcs/care_forms.html'
+    default_template_name = 'combo/wcs/care_forms.html'
     cache_duration = 120
     user_dependant = True
 
@@ -750,7 +750,7 @@ class WcsCareFormsCell(CategoriesValidityMixin, CategoriesFilteringMixin, WcsDat
 class CategoriesCell(WcsDataBaseCell):
     api_url = '/api/categories/?full=on'
     variable_name = 'form_categories'
-    template_name = 'combo/wcs/form_categories.html'
+    default_template_name = 'combo/wcs/form_categories.html'
     cache_duration = 600
 
     class Meta:
@@ -781,7 +781,7 @@ class WcsCardsCell(CardMixin, WcsBlurpMixin, CellBase):
     only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False)
     without_user = models.BooleanField(_('Ignore the logged-in user'), default=False)
 
-    template_name = 'combo/wcs/cards.html'
+    default_template_name = 'combo/wcs/cards.html'
     variable_name = 'cards'
 
     class Meta:
@@ -899,7 +899,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
 
     is_enabled = classmethod(is_wcs_enabled)
 
-    template_name = 'combo/wcs/card.html'
+    default_template_name = 'combo/wcs/card.html'
     manager_form_template = 'combo/wcs/manager/card-infos-cell-form.html'
 
     class Meta:
@@ -1002,7 +1002,7 @@ class WcsCardInfosCell(CardMixin, CellBase):
 class TrackingCodeInputCell(CellBase):
     is_enabled = classmethod(is_wcs_enabled)
     wcs_site = models.CharField(_('Site'), max_length=50, blank=True)
-    template_name = 'combo/wcs/tracking_code_input.html'
+    default_template_name = 'combo/wcs/tracking_code_input.html'
 
     class Meta:
         verbose_name = _('Tracking Code Input')
@@ -1029,7 +1029,7 @@ class TrackingCodeInputCell(CellBase):
 class BackofficeSubmissionCell(CategoriesValidityMixin, CategoriesFilteringMixin, WcsDataBaseCell):
     api_url = '/api/formdefs/?backoffice-submission=on'
     variable_name = 'all_formdefs'
-    template_name = 'combo/wcs/backoffice_submission.html'
+    default_template_name = 'combo/wcs/backoffice_submission.html'
     cache_duration = 600
     user_dependant = True
 
diff --git a/combo/data/models.py b/combo/data/models.py
index c6a1faf9..632b7a67 100644
--- a/combo/data/models.py
+++ b/combo/data/models.py
@@ -725,7 +725,7 @@ class CellBase(six.with_metaclass(CellMeta, models.Model)):
 
     visible = True
     user_dependant = False
-    template_name = None
+    default_template_name = None
 
     # get_badge(self, context); set to None so cell types can be skipped easily
     get_badge = None
@@ -1117,9 +1117,9 @@ class CellBase(six.with_metaclass(CellMeta, models.Model)):
         context.update(self.get_cell_extra_context(context))
         template_names = ['combo/' + self._meta.model_name + '.html']
         base_template_name = self._meta.model_name + '.html'
-        if self.template_name:
-            base_template_name = os.path.basename(self.template_name)
-            template_names.append(self.template_name)
+        if self.default_template_name:
+            base_template_name = os.path.basename(self.default_template_name)
+            template_names.append(self.default_template_name)
         if self.slug:
             template_names.append('combo/cells/%s/%s' % (self.slug, base_template_name))
         template_names.reverse()
@@ -1189,7 +1189,7 @@ class CellBase(six.with_metaclass(CellMeta, models.Model)):
 class TextCell(CellBase):
     text = RichTextField(_('Text'), blank=True, null=True)
 
-    template_name = 'combo/text-cell.html'
+    default_template_name = 'combo/text-cell.html'
 
     class Meta:
         verbose_name = _('Text')
@@ -1299,7 +1299,7 @@ class MenuCell(CellBase):
         verbose_name=_('Root Page'),
     )
 
-    template_name = 'combo/menu-cell.html'
+    default_template_name = 'combo/menu-cell.html'
     exclude_from_search = True
 
     class Meta:
@@ -1338,7 +1338,7 @@ class LinkCell(CellBase):
     )
     anchor = models.CharField(_('Anchor'), max_length=150, blank=True)
 
-    template_name = 'combo/link-cell.html'
+    default_template_name = 'combo/link-cell.html'
     add_as_link_label = _('add a link')
     add_link_label = _('New link')
     edit_link_label = _('Edit link')
@@ -1455,7 +1455,7 @@ class LinkListCell(CellBase):
     title = models.CharField(_('Title'), max_length=150, blank=True)
     limit = models.PositiveSmallIntegerField(_('Limit'), null=True, blank=True)
 
-    template_name = 'combo/link-list-cell.html'
+    default_template_name = 'combo/link-list-cell.html'
     manager_form_template = 'combo/manager/link-list-cell-form.html'
     children_placeholder_prefix = '_linkslist:'
     exclude_from_search = True
@@ -1558,7 +1558,7 @@ class FeedCell(CellBase):
     limit = models.PositiveSmallIntegerField(_('Maximum number of entries'), null=True, blank=True)
 
     manager_form_factory_kwargs = {'field_classes': {'url': TemplatableURLField}}
-    template_name = 'combo/feed-cell.html'
+    default_template_name = 'combo/feed-cell.html'
 
     invalid_reason_codes = {
         'data_url_not_defined': _('No URL set'),
@@ -1844,7 +1844,7 @@ class JsonCellBase(CellBase):
                 context['synchronous'] = synchronous
 
     @property
-    def template_name(self):
+    def default_template_name(self):
         json_content = self._json_content
         if json_content is None:
             return 'combo/json-error-cell.html'
@@ -2039,7 +2039,7 @@ class ConfigJsonCell(JsonCellBase):
         return settings.JSON_CELL_TYPES[self.key].get('additional-data')
 
     @property
-    def template_name(self):
+    def default_template_name(self):
         return settings.JSON_CELL_TYPES[self.key].get('template-name', 'combo/json/%s.html' % self.key)
 
     @property
diff --git a/combo/profile/models.py b/combo/profile/models.py
index 6e62a2b4..3159cddf 100644
--- a/combo/profile/models.py
+++ b/combo/profile/models.py
@@ -33,7 +33,7 @@ class Profile(models.Model):
 
 @register_cell_class
 class ProfileCell(JsonCellBase):
-    template_name = 'combo/profile.html'
+    default_template_name = 'combo/profile.html'
     first_data_key = 'profile'
     cache_duration = None
 
diff --git a/tests/test_cells.py b/tests/test_cells.py
index 9f9315fc..1d14bd5e 100644
--- a/tests/test_cells.py
+++ b/tests/test_cells.py
@@ -437,19 +437,19 @@ def test_json_cell():
     cell.save()
 
     cell._json_content = None
-    assert cell.template_name == 'combo/json-error-cell.html'
+    assert cell.default_template_name == 'combo/json-error-cell.html'
 
     cell._json_content = {}
-    assert cell.template_name == 'combo/json-cell.html'
+    assert cell.default_template_name == 'combo/json-cell.html'
 
     cell._json_content = {'data': []}
-    assert cell.template_name == 'combo/json-cell.html'
+    assert cell.default_template_name == 'combo/json-cell.html'
 
     cell._json_content = {'data': [{'url': 'xxx', 'text': 'xxx'}]}
-    assert cell.template_name == 'combo/json-list-cell.html'
+    assert cell.default_template_name == 'combo/json-list-cell.html'
 
     cell._json_content = {'data': [{'foo': 'xxx', 'bar': 'xxx'}]}
-    assert cell.template_name == 'combo/json-cell.html'
+    assert cell.default_template_name == 'combo/json-cell.html'
 
     with mock.patch('combo.utils.requests.get') as requests_get:
         data = {'data': [{'url': 'xxx', 'text': 'xxx'}]}
@@ -678,7 +678,7 @@ def test_config_json_cell():
         cell.parameters = {'blah': 'plop'}
         assert cell.get_label() == 'Foobar'
         assert cell.url == 'http://test/'
-        assert cell.template_name == 'combo/json/foobar.html'
+        assert cell.default_template_name == 'combo/json/foobar.html'
         assert cell.css_class_names.split() == ['config-json-cell', 'configjsoncell', 'foobar']
 
         with mock.patch('combo.utils.requests.get') as requests_get:
@@ -700,7 +700,7 @@ def test_config_json_cell():
         cell.parameters = {'blah': 'plop'}
         assert cell.get_label() == 'Foobar'
         assert cell.url == 'http://test/'
-        assert cell.template_name == 'combo/json/foobar.html'
+        assert cell.default_template_name == 'combo/json/foobar.html'
         assert cell.cache_duration == 10
 
 
diff --git a/tests/test_lingo_cells.py b/tests/test_lingo_cells.py
index e1bf5666..80dcd939 100644
--- a/tests/test_lingo_cells.py
+++ b/tests/test_lingo_cells.py
@@ -217,7 +217,7 @@ def test_tipi_cell():
     cell.save()
     assert cell.control_protocol == 'pesv2'
     assert cell.url == 'https://www.payfip.gouv.fr/tpa/paiement.web'
-    assert cell.template_name == 'lingo/tipi_form.html'
+    assert cell.default_template_name == 'lingo/tipi_form.html'
     html = cell.render({})
     assert "<h2>TIPI Payment</h2>" in html
     assert "Community identifier" not in html
-- 
2.32.0

