From e6de3d5956cfce55245838ab3c145a0740f6cea3 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Thu, 9 Sep 2021 16:29:11 +0200 Subject: [PATCH] manager: allow applying include in navigation to subpages (#56793) --- combo/manager/forms.py | 9 +++++++-- tests/test_manager.py | 16 ++++++++++++++++ 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/combo/manager/forms.py b/combo/manager/forms.py index 9b8e931c..1308f329 100644 --- a/combo/manager/forms.py +++ b/combo/manager/forms.py @@ -194,6 +194,7 @@ class PageEditRedirectionForm(forms.ModelForm): class PageEditIncludeInNavigationForm(forms.ModelForm): include_in_navigation = forms.BooleanField(label=_('Include in navigation menus'), required=False) + apply_to_subpages = forms.BooleanField(label=_('Apply to subpages'), required=False) class Meta: model = Page @@ -207,8 +208,12 @@ class PageEditIncludeInNavigationForm(forms.ModelForm): def save(self, *args, **kwargs): super().save(*args, **kwargs) - self.instance.exclude_from_navigation = not self.cleaned_data['include_in_navigation'] - self.instance.save() + if self.cleaned_data['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: + self.instance.exclude_from_navigation = not self.cleaned_data['include_in_navigation'] + self.instance.save() return self.instance diff --git a/tests/test_manager.py b/tests/test_manager.py index 188de2bb..97f1660d 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -285,17 +285,33 @@ def test_edit_page(app, admin_user): 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 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 + resp = resp.click(href='.*/include-in-navigation') + resp.form['include_in_navigation'].checked = False + resp.form['apply_to_subpages'].checked = True + resp = resp.form.submit() + resp = resp.follow() + assert Page.objects.get(pk=page2.pk).exclude_from_navigation is True + # include from nav including subpages + resp = resp.click(href='.*/include-in-navigation') + resp.form['include_in_navigation'].checked = True + resp.form['apply_to_subpages'].checked = True + resp = resp.form.submit() + resp = resp.follow() + assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False def test_page_edit_template_form(settings): -- 2.30.2