Projet

Général

Profil

0001-general-rename-cell-template_name-attribute-to-defau.patch

Frédéric Péters, 23 juillet 2021 16:14

Télécharger (17,2 ko)

Voir les différences:

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(-)
combo/apps/calendar/models.py
44 44
    )
45 45
    days_displayed = models.PositiveSmallIntegerField(_('Number of days to display'), default=7)
46 46

  
47
    template_name = 'calendar/booking_calendar_cell.html'
47
    default_template_name = 'calendar/booking_calendar_cell.html'
48 48

  
49 49
    class Meta:
50 50
        verbose_name = _('Booking Calendar')
combo/apps/dataviz/models.py
53 53
    jsonp_data_source = models.BooleanField(_('Use JSONP to get data'), default=True)
54 54
    max_value = models.PositiveIntegerField(_('Max Value'), blank=True, null=True)
55 55

  
56
    template_name = 'combo/gauge-cell.html'
56
    default_template_name = 'combo/gauge-cell.html'
57 57

  
58 58
    class Media:
59 59
        js = ('js/gauge.min.js', 'js/combo.gauge.js')
......
84 84

  
85 85
@register_cell_class
86 86
class ChartCell(CellBase):
87
    template_name = 'combo/dataviz-chart.html'
87
    default_template_name = 'combo/dataviz-chart.html'
88 88

  
89 89
    title = models.CharField(_('Title'), max_length=150, blank=True, null=True)
90 90
    url = models.URLField(_('URL'), max_length=250, blank=True, null=True)
combo/apps/family/models.py
24 24

  
25 25
@register_cell_class
26 26
class FamilyInfosCell(CellBase):
27
    template_name = 'family/infos.html'
27
    default_template_name = 'family/infos.html'
28 28
    user_dependant = True
29 29

  
30 30
    class Meta:
combo/apps/fargo/models.py
32 32

  
33 33
@register_cell_class
34 34
class RecentDocumentsCell(CellBase):
35
    template_name = 'combo/fargo/recent-documents-cell.html'
35
    default_template_name = 'combo/fargo/recent-documents-cell.html'
36 36
    fargo_site = models.CharField(_('Site'), max_length=50, blank=True)
37 37
    user_dependant = True
38 38

  
combo/apps/gallery/models.py
29 29
@register_cell_class
30 30
class GalleryCell(CellBase):
31 31
    title = models.CharField(_('Title'), max_length=50, blank=True, null=True)
32
    template_name = 'combo/gallerycell.html'
32
    default_template_name = 'combo/gallerycell.html'
33 33
    manager_form_template = 'combo/gallery_manager.html'
34 34

  
35 35
    class Meta:
combo/apps/kb/models.py
37 37
    )
38 38
    limit = models.PositiveSmallIntegerField(_('Maximum number of entries'), default=10)
39 39

  
40
    template_name = 'combo/latest-page-updates-cell.html'
40
    default_template_name = 'combo/latest-page-updates-cell.html'
41 41
    exclude_from_search = True
42 42

  
43 43
    class Meta:
combo/apps/lingo/models.py
1157 1157
    text = RichTextField(_('Text'), blank=True, null=True)
1158 1158

  
1159 1159
    user_dependant = True
1160
    template_name = 'lingo/combo/items.html'
1160
    default_template_name = 'lingo/combo/items.html'
1161 1161
    loading_message = _('Loading invoices...')
1162 1162

  
1163 1163
    class Meta:
......
1262 1262
@register_cell_class
1263 1263
class SelfDeclaredInvoicePayment(Items):
1264 1264
    user_dependant = False
1265
    template_name = 'lingo/combo/self-declared-invoice-payment.html'
1265
    default_template_name = 'lingo/combo/self-declared-invoice-payment.html'
1266 1266

  
1267 1267
    class Meta:
1268 1268
        verbose_name = _('Self declared invoice payment')
......
1313 1313
        'ROLDET', max_length=13, blank=True, help_text=_('Default value to be used in form')
1314 1314
    )
1315 1315
    test_mode = models.BooleanField(_('Test mode'), default=False)
1316
    template_name = 'lingo/tipi_form.html'
1316
    default_template_name = 'lingo/tipi_form.html'
1317 1317

  
1318 1318
    class Meta:
1319 1319
        verbose_name = _('TIPI Payment Form')
combo/apps/maps/models.py
368 368
    )
369 369
    layers = models.ManyToManyField(MapLayer, through='MapLayerOptions', verbose_name=_('Layers'), blank=True)
370 370

  
371
    template_name = 'maps/map_cell.html'
371
    default_template_name = 'maps/map_cell.html'
372 372
    manager_form_template = 'maps/map_cell_form.html'
373 373

  
374 374
    class Meta:
combo/apps/search/models.py
48 48

  
49 49
@register_cell_class
50 50
class SearchCell(CellBase):
51
    template_name = 'combo/search-cell.html'
51
    default_template_name = 'combo/search-cell.html'
52 52
    manager_form_template = 'combo/manager/search-cell-form.html'
53 53
    exclude_from_search = True
54 54

  
combo/apps/wcs/models.py
68 68
    cached_url = models.URLField(_('URL'))
69 69
    cached_json = JSONField(blank=True, default=dict)
70 70

  
71
    template_name = 'combo/wcs/form.html'
71
    default_template_name = 'combo/wcs/form.html'
72 72
    add_as_link_label = _('add a form link')
73 73
    add_link_label = _('New form link')
74 74
    edit_link_label = _('Edit form link')
......
249 249

  
250 250
@register_cell_class
251 251
class WcsCategoryCell(WcsCommonCategoryCell):
252
    template_name = 'combo/wcs/category.html'
252
    default_template_name = 'combo/wcs/category.html'
253 253

  
254 254
    class Meta:
255 255
        verbose_name = _('Category Link')
......
481 481
        return url
482 482

  
483 483
    @property
484
    def template_name(self):
484
    def default_template_name(self):
485 485
        if self.current_forms and self.done_forms:
486 486
            return 'combo/wcs/user_all_forms.html'
487 487
        if self.done_forms:
......
544 544
@register_cell_class
545 545
class WcsCurrentDraftsCell(CategoriesValidityMixin, CategoriesFilteringMixin, WcsUserDataBaseCell):
546 546
    variable_name = 'current_drafts'
547
    template_name = 'combo/wcs/current_drafts.html'
547
    default_template_name = 'combo/wcs/current_drafts.html'
548 548
    loading_message = _('Loading drafts...')
549 549

  
550 550
    categories = JSONField(_('Categories'), blank=True, default=dict)
......
613 613
        verbose_name = _('Forms of Category')
614 614

  
615 615
    variable_name = 'forms'
616
    template_name = 'combo/wcs/forms_of_category.html'
616
    default_template_name = 'combo/wcs/forms_of_category.html'
617 617
    cache_duration = 600
618 618

  
619 619
    def get_default_form_class(self):
......
718 718

  
719 719
    api_url = '/api/forms/?limit=10'
720 720
    variable_name = 'care_forms'
721
    template_name = 'combo/wcs/care_forms.html'
721
    default_template_name = 'combo/wcs/care_forms.html'
722 722
    cache_duration = 120
723 723
    user_dependant = True
724 724

  
......
750 750
class CategoriesCell(WcsDataBaseCell):
751 751
    api_url = '/api/categories/?full=on'
752 752
    variable_name = 'form_categories'
753
    template_name = 'combo/wcs/form_categories.html'
753
    default_template_name = 'combo/wcs/form_categories.html'
754 754
    cache_duration = 600
755 755

  
756 756
    class Meta:
......
781 781
    only_for_user = models.BooleanField(_('Limit to cards linked to the logged-in user'), default=False)
782 782
    without_user = models.BooleanField(_('Ignore the logged-in user'), default=False)
783 783

  
784
    template_name = 'combo/wcs/cards.html'
784
    default_template_name = 'combo/wcs/cards.html'
785 785
    variable_name = 'cards'
786 786

  
787 787
    class Meta:
......
899 899

  
900 900
    is_enabled = classmethod(is_wcs_enabled)
901 901

  
902
    template_name = 'combo/wcs/card.html'
902
    default_template_name = 'combo/wcs/card.html'
903 903
    manager_form_template = 'combo/wcs/manager/card-infos-cell-form.html'
904 904

  
905 905
    class Meta:
......
1002 1002
class TrackingCodeInputCell(CellBase):
1003 1003
    is_enabled = classmethod(is_wcs_enabled)
1004 1004
    wcs_site = models.CharField(_('Site'), max_length=50, blank=True)
1005
    template_name = 'combo/wcs/tracking_code_input.html'
1005
    default_template_name = 'combo/wcs/tracking_code_input.html'
1006 1006

  
1007 1007
    class Meta:
1008 1008
        verbose_name = _('Tracking Code Input')
......
1029 1029
class BackofficeSubmissionCell(CategoriesValidityMixin, CategoriesFilteringMixin, WcsDataBaseCell):
1030 1030
    api_url = '/api/formdefs/?backoffice-submission=on'
1031 1031
    variable_name = 'all_formdefs'
1032
    template_name = 'combo/wcs/backoffice_submission.html'
1032
    default_template_name = 'combo/wcs/backoffice_submission.html'
1033 1033
    cache_duration = 600
1034 1034
    user_dependant = True
1035 1035

  
combo/data/models.py
725 725

  
726 726
    visible = True
727 727
    user_dependant = False
728
    template_name = None
728
    default_template_name = None
729 729

  
730 730
    # get_badge(self, context); set to None so cell types can be skipped easily
731 731
    get_badge = None
......
1117 1117
        context.update(self.get_cell_extra_context(context))
1118 1118
        template_names = ['combo/' + self._meta.model_name + '.html']
1119 1119
        base_template_name = self._meta.model_name + '.html'
1120
        if self.template_name:
1121
            base_template_name = os.path.basename(self.template_name)
1122
            template_names.append(self.template_name)
1120
        if self.default_template_name:
1121
            base_template_name = os.path.basename(self.default_template_name)
1122
            template_names.append(self.default_template_name)
1123 1123
        if self.slug:
1124 1124
            template_names.append('combo/cells/%s/%s' % (self.slug, base_template_name))
1125 1125
        template_names.reverse()
......
1189 1189
class TextCell(CellBase):
1190 1190
    text = RichTextField(_('Text'), blank=True, null=True)
1191 1191

  
1192
    template_name = 'combo/text-cell.html'
1192
    default_template_name = 'combo/text-cell.html'
1193 1193

  
1194 1194
    class Meta:
1195 1195
        verbose_name = _('Text')
......
1299 1299
        verbose_name=_('Root Page'),
1300 1300
    )
1301 1301

  
1302
    template_name = 'combo/menu-cell.html'
1302
    default_template_name = 'combo/menu-cell.html'
1303 1303
    exclude_from_search = True
1304 1304

  
1305 1305
    class Meta:
......
1338 1338
    )
1339 1339
    anchor = models.CharField(_('Anchor'), max_length=150, blank=True)
1340 1340

  
1341
    template_name = 'combo/link-cell.html'
1341
    default_template_name = 'combo/link-cell.html'
1342 1342
    add_as_link_label = _('add a link')
1343 1343
    add_link_label = _('New link')
1344 1344
    edit_link_label = _('Edit link')
......
1455 1455
    title = models.CharField(_('Title'), max_length=150, blank=True)
1456 1456
    limit = models.PositiveSmallIntegerField(_('Limit'), null=True, blank=True)
1457 1457

  
1458
    template_name = 'combo/link-list-cell.html'
1458
    default_template_name = 'combo/link-list-cell.html'
1459 1459
    manager_form_template = 'combo/manager/link-list-cell-form.html'
1460 1460
    children_placeholder_prefix = '_linkslist:'
1461 1461
    exclude_from_search = True
......
1558 1558
    limit = models.PositiveSmallIntegerField(_('Maximum number of entries'), null=True, blank=True)
1559 1559

  
1560 1560
    manager_form_factory_kwargs = {'field_classes': {'url': TemplatableURLField}}
1561
    template_name = 'combo/feed-cell.html'
1561
    default_template_name = 'combo/feed-cell.html'
1562 1562

  
1563 1563
    invalid_reason_codes = {
1564 1564
        'data_url_not_defined': _('No URL set'),
......
1844 1844
                context['synchronous'] = synchronous
1845 1845

  
1846 1846
    @property
1847
    def template_name(self):
1847
    def default_template_name(self):
1848 1848
        json_content = self._json_content
1849 1849
        if json_content is None:
1850 1850
            return 'combo/json-error-cell.html'
......
2039 2039
        return settings.JSON_CELL_TYPES[self.key].get('additional-data')
2040 2040

  
2041 2041
    @property
2042
    def template_name(self):
2042
    def default_template_name(self):
2043 2043
        return settings.JSON_CELL_TYPES[self.key].get('template-name', 'combo/json/%s.html' % self.key)
2044 2044

  
2045 2045
    @property
combo/profile/models.py
33 33

  
34 34
@register_cell_class
35 35
class ProfileCell(JsonCellBase):
36
    template_name = 'combo/profile.html'
36
    default_template_name = 'combo/profile.html'
37 37
    first_data_key = 'profile'
38 38
    cache_duration = None
39 39

  
tests/test_cells.py
437 437
    cell.save()
438 438

  
439 439
    cell._json_content = None
440
    assert cell.template_name == 'combo/json-error-cell.html'
440
    assert cell.default_template_name == 'combo/json-error-cell.html'
441 441

  
442 442
    cell._json_content = {}
443
    assert cell.template_name == 'combo/json-cell.html'
443
    assert cell.default_template_name == 'combo/json-cell.html'
444 444

  
445 445
    cell._json_content = {'data': []}
446
    assert cell.template_name == 'combo/json-cell.html'
446
    assert cell.default_template_name == 'combo/json-cell.html'
447 447

  
448 448
    cell._json_content = {'data': [{'url': 'xxx', 'text': 'xxx'}]}
449
    assert cell.template_name == 'combo/json-list-cell.html'
449
    assert cell.default_template_name == 'combo/json-list-cell.html'
450 450

  
451 451
    cell._json_content = {'data': [{'foo': 'xxx', 'bar': 'xxx'}]}
452
    assert cell.template_name == 'combo/json-cell.html'
452
    assert cell.default_template_name == 'combo/json-cell.html'
453 453

  
454 454
    with mock.patch('combo.utils.requests.get') as requests_get:
455 455
        data = {'data': [{'url': 'xxx', 'text': 'xxx'}]}
......
678 678
        cell.parameters = {'blah': 'plop'}
679 679
        assert cell.get_label() == 'Foobar'
680 680
        assert cell.url == 'http://test/'
681
        assert cell.template_name == 'combo/json/foobar.html'
681
        assert cell.default_template_name == 'combo/json/foobar.html'
682 682
        assert cell.css_class_names.split() == ['config-json-cell', 'configjsoncell', 'foobar']
683 683

  
684 684
        with mock.patch('combo.utils.requests.get') as requests_get:
......
700 700
        cell.parameters = {'blah': 'plop'}
701 701
        assert cell.get_label() == 'Foobar'
702 702
        assert cell.url == 'http://test/'
703
        assert cell.template_name == 'combo/json/foobar.html'
703
        assert cell.default_template_name == 'combo/json/foobar.html'
704 704
        assert cell.cache_duration == 10
705 705

  
706 706

  
tests/test_lingo_cells.py
217 217
    cell.save()
218 218
    assert cell.control_protocol == 'pesv2'
219 219
    assert cell.url == 'https://www.payfip.gouv.fr/tpa/paiement.web'
220
    assert cell.template_name == 'lingo/tipi_form.html'
220
    assert cell.default_template_name == 'lingo/tipi_form.html'
221 221
    html = cell.render({})
222 222
    assert "<h2>TIPI Payment</h2>" in html
223 223
    assert "Community identifier" not in html
224
-