diff --git a/combo/apps/wcs/forms.py b/combo/apps/wcs/forms.py index 12425205..33608c6a 100644 --- a/combo/apps/wcs/forms.py +++ b/combo/apps/wcs/forms.py @@ -50,7 +50,9 @@ class WcsFormForLinkListCellForm(WcsFormCellForm): class WcsCardsCellForm(forms.ModelForm): - with_user = forms.BooleanField(label=_('Restrict to cards accessible to the user'), required=False) + with_user = forms.BooleanField( + label=_('Restrict to cards accessible to the user'), required=False, initial=True + ) class Meta: model = WcsCardsCell @@ -72,7 +74,9 @@ class WcsCardsCellForm(forms.ModelForm): class WcsCardInfoCellForm(forms.ModelForm): - with_user = forms.BooleanField(label=_('Restrict to cards accessible to the user'), required=False) + with_user = forms.BooleanField( + label=_('Restrict to cards accessible to the user'), required=False, initial=True + ) customize_display = forms.BooleanField(label=_('Customize display'), required=False) related_card_path = forms.ChoiceField(label=_('Card Identifier'), required=False) @@ -116,6 +120,7 @@ class WcsCardInfoCellForm(forms.ModelForm): self.fields['related_card_path'].choices += [ ('--', _('Identifier from page URL')), ] + self.fields['related_card_path'].initial = '--' if not self.instance.card_ids and not self.instance.related_card_path: self.initial['related_card_path'] = '--' self.fields['related_card_path'].choices += [ diff --git a/combo/data/forms.py b/combo/data/forms.py index 96a4059a..f26e69c4 100644 --- a/combo/data/forms.py +++ b/combo/data/forms.py @@ -62,6 +62,8 @@ class LinkListCellForm(forms.ModelForm): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + if self.instance.get_items_with_prefetch(): + self.is_not_default = True class ConfigJsonForm(forms.ModelForm): diff --git a/combo/data/models.py b/combo/data/models.py index c08f3f58..99bdb2a5 100644 --- a/combo/data/models.py +++ b/combo/data/models.py @@ -1784,7 +1784,9 @@ class LinkListCell(CellBase): ) def get_items_with_prefetch(self): - return self.get_items(prefetch_validity_info=True) + if not hasattr(self, '_items_with_prefetch_cache'): + self._items_with_prefetch_cache = self.get_items(prefetch_validity_info=True) + return self._items_with_prefetch_cache def get_additional_label(self): title = self.title diff --git a/combo/manager/forms.py b/combo/manager/forms.py index ddd44514..949f92a0 100644 --- a/combo/manager/forms.py +++ b/combo/manager/forms.py @@ -60,6 +60,19 @@ def get_template_name_choices(with_models=False): return templates +def build_tab_is_not_default(form): + if getattr(form, 'is_not_default', None) is True: + return True + for field_name, field in form.fields.items(): + if field.initial is not None: + if field.initial != form.initial.get(field_name): + return True + else: + if bool(form.initial.get(field_name)): + return True + return False + + class PageDuplicateForm(forms.Form): title = forms.CharField(label=_('New title'), max_length=150, required=False) @@ -274,6 +287,7 @@ class CellVisibilityForm(forms.Form): ('groups-any', _('Users with one of these groups')), ('groups-none', _('Users with none of these groups')), ], + initial='all', ) groups = forms.MultipleChoiceField(label=_('Groups'), required=False, choices=get_groups_as_choices) diff --git a/combo/manager/static/js/combo.manager.js b/combo/manager/static/js/combo.manager.js index caf2e59d..00a44cc4 100644 --- a/combo/manager/static/js/combo.manager.js +++ b/combo/manager/static/js/combo.manager.js @@ -275,10 +275,10 @@ $(function() { $button.attr('disabled', null); for (const tab_slug in data.tabs) { var $tab_content = $form.find('[data-tab-slug="' + tab_slug + '"]'); - if (data.tabs[tab_slug].indexOf('ckeditortype') == -1) { + if (data.tabs[tab_slug].form.indexOf('ckeditortype') == -1) { /* update form with new content, unless it has a ckeditor, as * this causes an unpleasant flickering */ - $tab_content.html(data.tabs[tab_slug]); + $tab_content.html(data.tabs[tab_slug].form); } else { for (const error in data.errorlist[tab_slug]) { var $widget_p = $('[name="' + data.prefix + '-' + error).closest('p'); @@ -289,6 +289,11 @@ $(function() { $widget_p.before($widget_ul); } } + if (data.tabs[tab_slug].is_not_default) { + $('#tab-' + $cell.data('cell-reference') + '-' + tab_slug).addClass('pk-tabs--button-marker'); + } else { + $('#tab-' + $cell.data('cell-reference') + '-' + tab_slug).removeClass('pk-tabs--button-marker'); + } } // update title labels $cell.find('.visibility-summary').removeClass( diff --git a/combo/manager/templates/combo/manager_edit_cell_block.html b/combo/manager/templates/combo/manager_edit_cell_block.html index 48ef634a..d3e7b7fe 100644 --- a/combo/manager/templates/combo/manager_edit_cell_block.html +++ b/combo/manager/templates/combo/manager_edit_cell_block.html @@ -5,19 +5,20 @@ {% for tab in manager_tabs %} + aria-controls="panel-{{ cell.get_reference }}-{{ tab.slug }}" + id="tab-{{ cell.get_reference }}-{{ tab.slug }}" + tabindex="{{ forloop.first|yesno:"0,-1" }}" + {% if tab.is_not_default %}class="pk-tabs--button-marker"{% endif %}>{{ tab.name }} {% endfor %}
{% csrf_token %} {% for tab in manager_tabs %} -
+ aria-labelledby="tab-{{ cell.get_reference }}-{{ tab.slug }}"> {% if tab.template %}{% include tab.template %}{% else %}{{ tab.form_instance.as_p }}{% endif %}
{% endfor %} diff --git a/combo/manager/templatetags/cells.py b/combo/manager/templatetags/cells.py index 5b232b98..665e0fa5 100644 --- a/combo/manager/templatetags/cells.py +++ b/combo/manager/templatetags/cells.py @@ -17,6 +17,8 @@ from django import forms, template from django.urls import reverse +from combo.manager.forms import build_tab_is_not_default + register = template.Library() @@ -37,6 +39,7 @@ def cell_form(context, cell): if tab.get('fields'): tab['form'] = forms.models.modelform_factory(cell.__class__, fields=tab['fields']) tab['form_instance'] = tab['form'](initial={}, instance=cell, prefix='c%s' % cell.get_reference()) + tab['is_not_default'] = build_tab_is_not_default(tab['form_instance']) context[form_name] = tab['form_instance'] context['cell'] = cell cell_form_template = template.loader.get_template('combo/manager_edit_cell_block.html') diff --git a/combo/manager/views.py b/combo/manager/views.py index d5035ca7..a789008e 100644 --- a/combo/manager/views.py +++ b/combo/manager/views.py @@ -88,6 +88,7 @@ from .forms import ( SiteExportForm, SiteImportForm, SiteSettingsForm, + build_tab_is_not_default, ) @@ -736,6 +737,7 @@ class PageEditCellView(ManagedPageMixin, UpdateView): form = tab_error_forms.get(tab['slug']) or tab['form']( instance=self.object, prefix=self.get_prefix(), initial={} ) + is_not_default = build_tab_is_not_default(form) if tab['slug'] == 'general': form_name = 'form' else: @@ -745,7 +747,10 @@ class PageEditCellView(ManagedPageMixin, UpdateView): cell_form_template = template.loader.get_template(tab['template']) else: cell_form_template = engines['django'].from_string('{{ %s.as_p }}' % form_name) - response['tabs'][tab['slug']] = cell_form_template.render(context) + response['tabs'][tab['slug']] = { + 'form': cell_form_template.render(context), + 'is_not_default': is_not_default, + } response['visibility_css_class'] = self.object.get_manager_visibility_css_class() response['visibility_content'] = self.object.get_manager_visibility_content() diff --git a/tests/test_dataviz.py b/tests/test_dataviz.py index 13b3a8e5..88d00ac4 100644 --- a/tests/test_dataviz.py +++ b/tests/test_dataviz.py @@ -1624,8 +1624,8 @@ def test_chartng_cell_manager_new_api_dynamic_fields(app, admin_user, new_api_st field_prefix = 'cdataviz_chartngcell-%s-' % cell.id resp.form[field_prefix + 'statistic'] = statistic.pk resp = app.post(resp.form.action, params=resp.form.submit_fields(), xhr=True) - assert 'time_interval' in resp.json['tabs']['general'] - assert 'This field is required.' not in resp.json['tabs']['general'] + assert 'time_interval' in resp.json['tabs']['general']['form'] + assert 'This field is required.' not in resp.json['tabs']['general']['form'] @with_httmock(new_api_mock) diff --git a/tests/test_manager.py b/tests/test_manager.py index 2b41ac85..d76bc0db 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -1778,7 +1778,7 @@ def test_edit_config_json_cell(app, admin_user): assert resp.form['c%s-test4' % cells[0].get_reference()].tag == 'textarea' resp.forms[0]['c%s-test4' % cells[0].get_reference()].value = 'Text Area' resp = manager_submit_cell(resp.form) - assert resp.json['tabs']['general'].strip().startswith('