From 75284f653db46f02153a9493390db29502522a6f Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 25 Oct 2021 14:02:10 +0200 Subject: [PATCH] manager: show apply_to_subpages only if not included in navigation (#58116) --- combo/manager/forms.py | 4 +++- tests/test_manager.py | 16 ++++++---------- 2 files changed, 9 insertions(+), 11 deletions(-) diff --git a/combo/manager/forms.py b/combo/manager/forms.py index b5f173ef..1ac8c6f4 100644 --- a/combo/manager/forms.py +++ b/combo/manager/forms.py @@ -238,10 +238,12 @@ class PageEditIncludeInNavigationForm(forms.ModelForm): initial = kwargs.pop('initial', {}) initial['include_in_navigation'] = not instance.exclude_from_navigation super().__init__(initial=initial, *args, **kwargs) + if initial['include_in_navigation']: + del self.fields['apply_to_subpages'] def save(self, *args, **kwargs): super().save(*args, **kwargs) - if self.cleaned_data['apply_to_subpages']: + if self.cleaned_data.get('apply_to_subpages'): subpages = self.instance.get_descendants(include_myself=True) subpages.update(exclude_from_navigation=bool(not self.cleaned_data['include_in_navigation'])) else: diff --git a/tests/test_manager.py b/tests/test_manager.py index 8c2d08ed..bb79530c 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -286,26 +286,21 @@ def test_edit_page(app, admin_user): resp = resp.form.submit() assert 'syntax error:' in resp.text resp = resp.click('Cancel') - # exclude from nav - page2 = Page.objects.create(title='Two', parent=Page.objects.get(), exclude_from_navigation=False) - resp = resp.click(href='.*/include-in-navigation') - resp.form['include_in_navigation'].checked = False - resp = resp.form.submit() - resp = resp.follow() - assert Page.objects.all()[0].exclude_from_navigation is True - assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False # include from nav + page2 = Page.objects.create(title='Two', parent=Page.objects.get(), exclude_from_navigation=True) resp = resp.click(href='.*/include-in-navigation') resp.form['include_in_navigation'].checked = True resp = resp.form.submit() resp = resp.follow() assert Page.objects.all()[0].exclude_from_navigation is False - # exclude from nav including subpages + assert Page.objects.get(pk=page2.pk).exclude_from_navigation is True + # exclude from nav resp = resp.click(href='.*/include-in-navigation') resp.form['include_in_navigation'].checked = False - resp.form['apply_to_subpages'].checked = True + assert 'apply_to_subpages' not in resp.form.fields resp = resp.form.submit() resp = resp.follow() + assert Page.objects.all()[0].exclude_from_navigation is True assert Page.objects.get(pk=page2.pk).exclude_from_navigation is True # include from nav including subpages resp = resp.click(href='.*/include-in-navigation') @@ -313,6 +308,7 @@ def test_edit_page(app, admin_user): resp.form['apply_to_subpages'].checked = True resp = resp.form.submit() resp = resp.follow() + assert Page.objects.all()[0].exclude_from_navigation is False assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False -- 2.30.2