From b7a389909a2d0de63c50c2ba1be68452b61afd07 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Corentin=20S=C3=A9chet?= Date: Mon, 2 May 2022 14:13:38 +0200 Subject: [PATCH] misc: move title fields to appearance tab (#64681) --- combo/apps/dataviz/forms.py | 1 - combo/apps/family/forms.py | 1 - combo/apps/gallery/models.py | 6 +++ combo/apps/lingo/models.py | 2 +- combo/apps/maps/models.py | 1 - combo/apps/search/forms.py | 2 +- combo/apps/wcs/forms.py | 6 +-- combo/apps/wcs/models.py | 4 ++ .../card-infos-cell-form-appearance.html | 26 +++++++++++ .../wcs/manager/card-infos-cell-form.html | 22 --------- combo/data/forms.py | 4 +- combo/data/models.py | 10 +++- .../templates/combo/cell_appearance.html | 2 + tests/test_cells.py | 26 +++++++++++ tests/test_dataviz.py | 12 +++++ tests/test_family.py | 10 ++++ tests/test_gallery_cell.py | 13 ++++++ tests/test_lingo_manager.py | 26 +++++++++++ tests/test_manager.py | 10 ++++ tests/test_maps_manager.py | 10 ++++ tests/test_search.py | 10 ++++ tests/test_wcs.py | 46 +++++++++++++++++++ 22 files changed, 215 insertions(+), 35 deletions(-) create mode 100644 combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form-appearance.html diff --git a/combo/apps/dataviz/forms.py b/combo/apps/dataviz/forms.py index 84bf9a22..8642915e 100644 --- a/combo/apps/dataviz/forms.py +++ b/combo/apps/dataviz/forms.py @@ -126,7 +126,6 @@ class ChartNgForm(ChartFiltersMixin, forms.ModelForm): class Meta: model = ChartNgCell fields = ( - 'title', 'statistic', 'time_range', 'time_range_start', diff --git a/combo/apps/family/forms.py b/combo/apps/family/forms.py index bd865077..159be4c0 100644 --- a/combo/apps/family/forms.py +++ b/combo/apps/family/forms.py @@ -23,7 +23,6 @@ class WeeklyAgendaCellForm(forms.ModelForm): class Meta: model = WeeklyAgendaCell fields = [ - 'title', 'agenda_type', 'agenda_references_template', 'agenda_categories', diff --git a/combo/apps/gallery/models.py b/combo/apps/gallery/models.py index 295954d0..37b96a72 100644 --- a/combo/apps/gallery/models.py +++ b/combo/apps/gallery/models.py @@ -16,6 +16,7 @@ import json +from django import forms from django.core import serializers from django.db import models from django.utils.translation import ugettext_lazy as _ @@ -47,6 +48,11 @@ class GalleryCell(CellBase): image.object.gallery_id = self.id image.save() + def get_default_form_class(self, fields=None): + if fields is None: + fields = [] + return forms.models.modelform_factory(self.__class__, fields=fields) + class Image(models.Model): gallery = models.ForeignKey(GalleryCell, on_delete=models.CASCADE, verbose_name=_('Gallery')) diff --git a/combo/apps/lingo/models.py b/combo/apps/lingo/models.py index c26c8ff9..7e469d2d 100644 --- a/combo/apps/lingo/models.py +++ b/combo/apps/lingo/models.py @@ -1187,7 +1187,7 @@ class Items(CellBase): return getattr(context['request'], 'user', None) and context['request'].user.is_authenticated def get_default_form_class(self): - fields = ['title', 'text'] + fields = ['text'] if hasattr(self, 'hide_if_empty'): fields.append('hide_if_empty') widgets = {} diff --git a/combo/apps/maps/models.py b/combo/apps/maps/models.py index 66d6cd88..c858d718 100644 --- a/combo/apps/maps/models.py +++ b/combo/apps/maps/models.py @@ -399,7 +399,6 @@ class Map(CellBase): def get_default_form_class(self): fields = ( - 'title', 'initial_state', 'group_markers', 'marker_behaviour_onclick', diff --git a/combo/apps/search/forms.py b/combo/apps/search/forms.py index 9f5677b9..03da406a 100644 --- a/combo/apps/search/forms.py +++ b/combo/apps/search/forms.py @@ -27,7 +27,7 @@ from .models import SearchCell class SearchCellForm(forms.ModelForm): class Meta: model = SearchCell - fields = ('title', 'autofocus', 'input_placeholder') + fields = ('autofocus', 'input_placeholder') class SelectWithDisabled(forms.Select): diff --git a/combo/apps/wcs/forms.py b/combo/apps/wcs/forms.py index 79b3d01e..12425205 100644 --- a/combo/apps/wcs/forms.py +++ b/combo/apps/wcs/forms.py @@ -54,7 +54,7 @@ class WcsCardsCellForm(forms.ModelForm): class Meta: model = WcsCardsCell - fields = ('carddef_reference', 'custom_title', 'limit', 'only_for_user') + fields = ('carddef_reference', 'limit', 'only_for_user') def __init__(self, *args, **kwargs): instance = kwargs['instance'] @@ -80,8 +80,6 @@ class WcsCardInfoCellForm(forms.ModelForm): model = WcsCardInfosCell fields = ( 'carddef_reference', - 'title_type', - 'custom_title', 'related_card_path', 'card_ids', 'custom_schema', @@ -210,7 +208,6 @@ class WcsCurrentFormsCellForm(WcsFormsMixin, forms.ModelForm): field_order = [ 'wcs_site', 'categories', - 'custom_title', 'current_forms', 'done_forms', 'include_drafts', @@ -221,7 +218,6 @@ class WcsCurrentFormsCellForm(WcsFormsMixin, forms.ModelForm): model = WcsCurrentFormsCell fields = [ 'wcs_site', - 'custom_title', 'current_forms', 'done_forms', 'include_drafts', diff --git a/combo/apps/wcs/models.py b/combo/apps/wcs/models.py index 8179d3b6..3473dbd5 100644 --- a/combo/apps/wcs/models.py +++ b/combo/apps/wcs/models.py @@ -961,6 +961,7 @@ class WcsCardInfosCell(CardMixin, CellBase): default_template_name = 'combo/wcs/card.html' manager_form_template = 'combo/wcs/manager/card-infos-cell-form.html' + manager_appearance_template = 'combo/wcs/manager/card-infos-cell-form-appearance.html' class Meta: verbose_name = _('Card Information Cell') @@ -1375,6 +1376,9 @@ class WcsCardInfosCell(CardMixin, CellBase): return WcsCardInfoCellForm + def get_appearance_fields(self): + return ['title_type', 'custom_title'] + def get_custom_schema(self): custom_schema = self.custom_schema or {} diff --git a/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form-appearance.html b/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form-appearance.html new file mode 100644 index 00000000..932974f7 --- /dev/null +++ b/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form-appearance.html @@ -0,0 +1,26 @@ +{% extends "combo/cell_appearance.html" %} + +{% block cell-form-appearance %} + {{ block.super }} + +{% endblock %} diff --git a/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html b/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html index 5c2650ff..1b737a63 100644 --- a/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html +++ b/combo/apps/wcs/templates/combo/wcs/manager/card-infos-cell-form.html @@ -166,26 +166,4 @@ {% endif %} - - {% endblock %} diff --git a/combo/data/forms.py b/combo/data/forms.py index cd91f1f6..6e81f253 100644 --- a/combo/data/forms.py +++ b/combo/data/forms.py @@ -42,7 +42,7 @@ class MenuCellForm(forms.ModelForm): class LinkCellForm(forms.ModelForm): class Meta: model = LinkCell - fields = ('title', 'url', 'link_page', 'anchor') + fields = ('url', 'link_page', 'anchor') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -58,7 +58,7 @@ class LinkCellForLinkListCellForm(LinkCellForm): class LinkListCellForm(forms.ModelForm): class Meta: model = LinkListCell - fields = ['title', 'limit'] + fields = ['limit'] def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/combo/data/models.py b/combo/data/models.py index 71042b10..68643774 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -1146,6 +1146,7 @@ class CellBase(models.Model, metaclass=CellMeta): 'restricted_to_unlogged', 'template_name', ) + + tuple(self.get_appearance_fields()) ] def get_default_form_class(self, fields=None): @@ -1161,8 +1162,15 @@ class CellBase(models.Model, metaclass=CellMeta): self.__class__, fields=fields, **self.manager_form_factory_kwargs ) + def get_appearance_fields(self): + return ['title', 'custom_title'] + def get_appearance_form_class(self): - fields = ['slug', 'extra_css_class'] + model_fields = {field.name for field in self._meta.local_concrete_fields} + fields = [field for field in self.get_appearance_fields() if field in model_fields] + [ + 'slug', + 'extra_css_class', + ] widgets = None extra_templates = settings.COMBO_CELL_TEMPLATES.get(self.get_cell_type_str()) if extra_templates: diff --git a/combo/manager/templates/combo/cell_appearance.html b/combo/manager/templates/combo/cell_appearance.html index 994bcc56..b52cebb1 100644 --- a/combo/manager/templates/combo/cell_appearance.html +++ b/combo/manager/templates/combo/cell_appearance.html @@ -1,6 +1,8 @@ {% load i18n %} +{% block cell-form-appearance %} {{ appearance_form.as_p }} {% if cell.can_have_assets %}

{% trans 'Assets' %}

{% endif %} +{% endblock %} diff --git a/tests/test_cells.py b/tests/test_cells.py index 6f578508..e0cd2f02 100644 --- a/tests/test_cells.py +++ b/tests/test_cells.py @@ -377,6 +377,16 @@ def test_feed_cell_validity(context): assert ValidityInfo.objects.exists() is False +def test_manager_feed_cell_tabs(app, admin_user): + page = Page.objects.create(title='example page', slug='example-page') + FeedCell.objects.create(page=page, placeholder='content', order=1) + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_menu_cell(): Page.objects.all().delete() parent = Page.objects.create( @@ -840,6 +850,22 @@ def test_json_cell_validity(context): assert ValidityInfo.objects.exists() is False +def test_manager_json_cell_tabs(app, admin_user): + page = Page.objects.create(title='example page', slug='example-page') + JsonCell.objects.create( + page=page, + placeholder='content', + order=1, + varnames_str='var1, var2, ', + url='http://foo?varone=[var1]&vartwo=[var2]', + ) + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_config_json_cell(): page = Page(title='example page', slug='example-page') page.save() diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index d66f2dba..2fe54ee1 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -1619,6 +1619,18 @@ def test_chartng_cell_manager_new_api_page_variables(app, admin_user, new_api_st assert [x[0] for x in color_field.options] == ['red', 'green', 'blue'] +def test_chartng_cell_manager_new_api_tabs(app, admin_user): + page = Page.objects.create(title='One', slug='index') + cell = ChartNgCell(page=page, order=1, placeholder='content') + cell.save() + + login(app) + resp = app.get('/manage/pages/%s/' % page.id) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + @with_httmock(bijoe_mock) def test_table_cell(app, admin_user, statistics): page = Page(title='One', slug='index') diff --git a/tests/test_family.py b/tests/test_family.py index 7c22fcbc..25050c8e 100644 --- a/tests/test_family.py +++ b/tests/test_family.py @@ -84,6 +84,16 @@ def test_manager_weeklyagenda_cell(app, admin_user): assert cell.end_date_filter == '{{ end_date }}' +def test_manager_weeklyagenda_cell_tabs(app, admin_user): + page = Page.objects.create(title='Family', slug='family', template_name='standard') + WeeklyAgendaCell.objects.create(page=page, placeholder='content', order=0) + login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_weeklyagenda_cell_user_external_id(context): page = Page.objects.create(title='Family', slug='index', template_name='standard') cell = WeeklyAgendaCell.objects.create(page=page, placeholder='content', order=0, agenda_type='manual') diff --git a/tests/test_gallery_cell.py b/tests/test_gallery_cell.py index af063694..8182c30c 100644 --- a/tests/test_gallery_cell.py +++ b/tests/test_gallery_cell.py @@ -73,3 +73,16 @@ def test_adding_gallery_images(app, admin_user): status=404, ) app.get(reverse('combo-gallery-image-order', kwargs={'gallery_pk': 0}), status=404) + + +def test_manager_gallery_cell_tabs(app, admin_user): + page = Page(title='Pictures', slug='test_gallery_cell', template_name='standard') + page.save() + cell = GalleryCell(page=page, placeholder='content', order=0) + cell.save() + + app = login(app) + resp = app.get('/manage/pages/%s/' % page.id) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') diff --git a/tests/test_lingo_manager.py b/tests/test_lingo_manager.py index a7d20dde..f9cc0ffa 100644 --- a/tests/test_lingo_manager.py +++ b/tests/test_lingo_manager.py @@ -566,6 +566,19 @@ def test_configure_tipi_cell(app, admin_user): assert resp.text.count('ROLDET:') == 1 +def test_manager_tipi_cell_tabs(app, admin_user): + page = Page(title='tipi', slug='tipi', template_name='standard') + page.save() + cell = TipiPaymentFormCell(title='Test payment', page=page, placeholder='content', order=0) + cell.save() + + app = login(app) + resp = app.get('/manage/pages/%s/' % page.id, status=200) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_configure_invoices_cell(app, admin_user, payment_backend): page = Page(title='xxx', slug='test', template_name='standard') page.save() @@ -621,6 +634,19 @@ def test_configure_invoices_cell(app, admin_user, payment_backend): assert ActiveItems.objects.get(id=cell.id).regie == regie2.slug +def test_manager_invoices_cell_tabs(app, admin_user): + page = Page(title='xxx', slug='test', template_name='standard') + page.save() + cell = ActiveItems(regie='remote', page=page, placeholder='content', order=0) + cell.save() + + app = login(app) + resp = app.get('/manage/pages/%s/' % page.id, status=200) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_payment_backend_list(app, admin_user): PaymentBackend.objects.create(label='label1', slug='slug1') PaymentBackend.objects.create(label='label2', slug='slug2') diff --git a/tests/test_manager.py b/tests/test_manager.py index 56a6fc64..ff2054b8 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -2591,6 +2591,16 @@ def test_link_cell_setup(): assert 'extra_css_class' not in form.fields +def test_manager_link_cell_tabs(app, admin_user): + page = Page.objects.create(title='One', slug='one', template_name='standard') + LinkCell.objects.create(order=0, placeholder='content', page=page) + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_link_cell_validation(): form = LinkCellForm(data={'url': 'http://example.com'}) assert form.is_valid() is True diff --git a/tests/test_maps_manager.py b/tests/test_maps_manager.py index 96484f74..3332e773 100644 --- a/tests/test_maps_manager.py +++ b/tests/test_maps_manager.py @@ -311,3 +311,13 @@ def test_add_delete_layer(app, admin_user, layer, tiles_layer): assert resp.status_int == 302 assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.pk, cell.get_reference())) assert MapLayerOptions.objects.count() == 0 + + +def test_manager_maps_cell_tabs(app, admin_user): + page = Page.objects.create(title='One', slug='one', template_name='standard') + Map.objects.create(page=page, placeholder='content', order=0, public=True, title='Map') + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') diff --git a/tests/test_search.py b/tests/test_search.py index 308ecbf4..ed614150 100644 --- a/tests/test_search.py +++ b/tests/test_search.py @@ -851,6 +851,16 @@ def test_manager_search_cell_order(settings, app, admin_user): assert cell._search_services == {'data': ['search_tmpl', '_text', 'search1']} +def test_manager_search_cell_tabs(app, admin_user): + page = Page.objects.create(title='One', slug='one', template_name='standard') + SearchCell.objects.create(page=page, placeholder='content', order=0) + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_manager_waiting_index_message(app, admin_user): page = Page.objects.create(title='One', slug='one', template_name='standard') cell = SearchCell.objects.create(page=page, placeholder='content', order=0) diff --git a/tests/test_wcs.py b/tests/test_wcs.py index 7c70f220..c5e1b71b 100644 --- a/tests/test_wcs.py +++ b/tests/test_wcs.py @@ -1594,6 +1594,18 @@ def test_manager_current_forms(mock_send, settings, app, admin_user): assert resp.form['c%s-wcs_site' % cells[0].get_reference()].attrs['type'] == 'hidden' +def test_manager_current_forms_tabs(app, admin_user): + page = Page(title='One', slug='one', template_name='standard') + page.save() + cell = WcsCurrentFormsCell.objects.create(page=page, placeholder='content', order=1) + cell.save() + app = login(app) + resp = app.get('/manage/pages/%s/' % page.id) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="custom_title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]') + + @mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) def test_manager_forms_in_your_care_cell(mock_send, app, admin_user): page = Page(title='One', slug='one', template_name='standard') @@ -1635,6 +1647,17 @@ def test_manager_cards_cell(mock_send, app, admin_user): assert resp.forms[0]['c%s-with_user' % cell.get_reference()].value is None +def test_manager_cards_cell_tabs(app, admin_user): + page = Page.objects.create(title='xxx', slug='test_cards_cell_save_cache', template_name='standard') + WcsCardsCell.objects.create(page=page, placeholder='content', order=0) + login(app) + + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="custom_title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]') + + @mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) def test_cards_cell_setup(mock_send): cell = WcsCardsCell() @@ -2456,6 +2479,19 @@ def test_manager_card_cell(mock_send, app, admin_user): ] +def test_manager_card_cell_tabs(app, admin_user): + page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard', sub_slug='foobar') + WcsCardInfosCell.objects.create(page=page, placeholder='content', order=0) + + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] select[name$="title_type"]') + assert not resp.pyquery('[data-tab-slug="general"] input[name$="custom_title"]') + assert resp.pyquery('[data-tab-slug="appearance"] select[name$="title_type"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="custom_title"]') + + @mock.patch('combo.apps.wcs.utils.requests.send', side_effect=mocked_requests_send) def test_card_cell_load(mock_send): page = Page.objects.create(title='xxx', slug='test_cards', template_name='standard') @@ -4203,6 +4239,16 @@ def test_manager_add_edit_delete_list_link_item(mock_send, app, admin_user): assert WcsFormCell.objects.count() == 0 +def test_manager_link_list_tabs(app, admin_user): + page = Page.objects.create(title='One', slug='one', template_name='standard') + LinkListCell.objects.create(order=0, placeholder='content', page=page) + app = login(app) + resp = app.get('/manage/pages/%s/' % page.pk) + + assert not resp.pyquery('[data-tab-slug="general"] input[name$="title"]') + assert resp.pyquery('[data-tab-slug="appearance"] input[name$="title"]') + + def test_import_export_pages_with_links(): page = Page(title='bar', slug='bar', order=1) page.save() -- 2.35.1