Projet

Général

Profil

0001-manager-show-apply_to_subpages-only-if-not-included-.patch

Valentin Deniaud, 25 octobre 2021 14:04

Télécharger (3,29 ko)

Voir les différences:

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(-)
combo/manager/forms.py
238 238
        initial = kwargs.pop('initial', {})
239 239
        initial['include_in_navigation'] = not instance.exclude_from_navigation
240 240
        super().__init__(initial=initial, *args, **kwargs)
241
        if initial['include_in_navigation']:
242
            del self.fields['apply_to_subpages']
241 243

  
242 244
    def save(self, *args, **kwargs):
243 245
        super().save(*args, **kwargs)
244
        if self.cleaned_data['apply_to_subpages']:
246
        if self.cleaned_data.get('apply_to_subpages'):
245 247
            subpages = self.instance.get_descendants(include_myself=True)
246 248
            subpages.update(exclude_from_navigation=bool(not self.cleaned_data['include_in_navigation']))
247 249
        else:
tests/test_manager.py
286 286
    resp = resp.form.submit()
287 287
    assert 'syntax error:' in resp.text
288 288
    resp = resp.click('Cancel')
289
    # exclude from nav
290
    page2 = Page.objects.create(title='Two', parent=Page.objects.get(), exclude_from_navigation=False)
291
    resp = resp.click(href='.*/include-in-navigation')
292
    resp.form['include_in_navigation'].checked = False
293
    resp = resp.form.submit()
294
    resp = resp.follow()
295
    assert Page.objects.all()[0].exclude_from_navigation is True
296
    assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False
297 289
    # include from nav
290
    page2 = Page.objects.create(title='Two', parent=Page.objects.get(), exclude_from_navigation=True)
298 291
    resp = resp.click(href='.*/include-in-navigation')
299 292
    resp.form['include_in_navigation'].checked = True
300 293
    resp = resp.form.submit()
301 294
    resp = resp.follow()
302 295
    assert Page.objects.all()[0].exclude_from_navigation is False
303
    # exclude from nav including subpages
296
    assert Page.objects.get(pk=page2.pk).exclude_from_navigation is True
297
    # exclude from nav
304 298
    resp = resp.click(href='.*/include-in-navigation')
305 299
    resp.form['include_in_navigation'].checked = False
306
    resp.form['apply_to_subpages'].checked = True
300
    assert 'apply_to_subpages' not in resp.form.fields
307 301
    resp = resp.form.submit()
308 302
    resp = resp.follow()
303
    assert Page.objects.all()[0].exclude_from_navigation is True
309 304
    assert Page.objects.get(pk=page2.pk).exclude_from_navigation is True
310 305
    # include from nav including subpages
311 306
    resp = resp.click(href='.*/include-in-navigation')
......
313 308
    resp.form['apply_to_subpages'].checked = True
314 309
    resp = resp.form.submit()
315 310
    resp = resp.follow()
311
    assert Page.objects.all()[0].exclude_from_navigation is False
316 312
    assert Page.objects.get(pk=page2.pk).exclude_from_navigation is False
317 313

  
318 314

  
319
-