0001-manager-allow-applying-include-in-navigation-to-subp.patch
combo/manager/forms.py | ||
---|---|---|
194 | 194 | |
195 | 195 |
class PageEditIncludeInNavigationForm(forms.ModelForm): |
196 | 196 |
include_in_navigation = forms.BooleanField(label=_('Include in navigation menus'), required=False) |
197 |
apply_to_subpages = forms.BooleanField(label=_('Apply to subpages'), required=False) |
|
197 | 198 | |
198 | 199 |
class Meta: |
199 | 200 |
model = Page |
... | ... | |
207 | 208 | |
208 | 209 |
def save(self, *args, **kwargs): |
209 | 210 |
super().save(*args, **kwargs) |
210 |
self.instance.exclude_from_navigation = not self.cleaned_data['include_in_navigation'] |
|
211 |
self.instance.save() |
|
211 |
if self.cleaned_data['apply_to_subpages']: |
|
212 |
subpages = self.instance.get_descendants(include_myself=True) |
|
213 |
subpages.update(exclude_from_navigation=bool(not self.cleaned_data['include_in_navigation'])) |
|
214 |
else: |
|
215 |
self.instance.exclude_from_navigation = not self.cleaned_data['include_in_navigation'] |
|
216 |
self.instance.save() |
|
212 | 217 |
return self.instance |
213 | 218 | |
214 | 219 |
tests/test_manager.py | ||
---|---|---|
285 | 285 |
assert 'syntax error:' in resp.text |
286 | 286 |
resp = resp.click('Cancel') |
287 | 287 |
# exclude from nav |
288 |
page2 = Page.objects.create(title='Two', parent=Page.objects.get(), exclude_from_navigation=False) |
|
288 | 289 |
resp = resp.click(href='.*/include-in-navigation') |
289 | 290 |
resp.form['include_in_navigation'].checked = False |
290 | 291 |
resp = resp.form.submit() |
291 | 292 |
resp = resp.follow() |
292 | 293 |
assert Page.objects.all()[0].exclude_from_navigation is True |
294 |
assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False |
|
293 | 295 |
# include from nav |
294 | 296 |
resp = resp.click(href='.*/include-in-navigation') |
295 | 297 |
resp.form['include_in_navigation'].checked = True |
296 | 298 |
resp = resp.form.submit() |
297 | 299 |
resp = resp.follow() |
298 | 300 |
assert Page.objects.all()[0].exclude_from_navigation is False |
301 |
# exclude from nav including subpages |
|
302 |
resp = resp.click(href='.*/include-in-navigation') |
|
303 |
resp.form['include_in_navigation'].checked = False |
|
304 |
resp.form['apply_to_subpages'].checked = True |
|
305 |
resp = resp.form.submit() |
|
306 |
resp = resp.follow() |
|
307 |
assert Page.objects.get(pk=page2.pk).exclude_from_navigation is True |
|
308 |
# include from nav including subpages |
|
309 |
resp = resp.click(href='.*/include-in-navigation') |
|
310 |
resp.form['include_in_navigation'].checked = True |
|
311 |
resp.form['apply_to_subpages'].checked = True |
|
312 |
resp = resp.form.submit() |
|
313 |
resp = resp.follow() |
|
314 |
assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False |
|
299 | 315 | |
300 | 316 | |
301 | 317 |
def test_page_edit_template_form(settings): |
302 |
- |