From 0feaed573149df172f4c24ceb13d0f569d0083c5 Mon Sep 17 00:00:00 2001 From: Valentin Deniaud Date: Mon, 25 Oct 2021 14:11:36 +0200 Subject: [PATCH] manager: show apply_to_subpages only if page has chidren (#58115) --- combo/manager/forms.py | 2 +- tests/test_manager.py | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/combo/manager/forms.py b/combo/manager/forms.py index 1ac8c6f4..008f02d9 100644 --- a/combo/manager/forms.py +++ b/combo/manager/forms.py @@ -238,7 +238,7 @@ 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']: + if initial['include_in_navigation'] or not instance.has_children(): del self.fields['apply_to_subpages'] def save(self, *args, **kwargs): diff --git a/tests/test_manager.py b/tests/test_manager.py index bb79530c..21a577f5 100644 --- a/tests/test_manager.py +++ b/tests/test_manager.py @@ -286,10 +286,15 @@ def test_edit_page(app, admin_user): resp = resp.form.submit() assert 'syntax error:' in resp.text resp = resp.click('Cancel') - # include from nav + # include from nav, no apply_to_subpages field if page doesn't have children + resp = resp.click(href='.*/include-in-navigation') + assert 'apply_to_subpages' not in resp.form.fields + resp = resp.click('Cancel') + # include from nav not including subpages 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 + assert 'apply_to_subpages' in resp.form.fields resp = resp.form.submit() resp = resp.follow() assert Page.objects.all()[0].exclude_from_navigation is False -- 2.30.2