manager: allow applying include in navigation to subpages (#56793)
This commit is contained in:
parent
937b1c2d12
commit
0b33600a00
|
@ -227,6 +227,7 @@ class PageEditRolesForm(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
|
||||
|
@ -240,8 +241,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
|
||||
|
||||
|
||||
|
|
|
@ -286,17 +286,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):
|
||||
|
|
Loading…
Reference in New Issue