forked from unicef/iogt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathforms.py
18 lines (14 loc) · 779 Bytes
/
forms.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
from django.apps import apps
from wagtail.admin.forms import WagtailAdminPageForm
class SectionPageForm(WagtailAdminPageForm):
def clean(self):
cleaned_data = super().clean()
if cleaned_data['show_progress_bar']:
Section = apps.get_model('home', 'Section')
if self.instance not in Section.get_progress_bar_eligible_sections():
progress_bar_enabled_ancestor_title = self.instance.get_progress_bar_enabled_ancestor().title
self.add_error(
'show_progress_bar',
f'This section is not eligible for showing the progress bar. '
f'Disable "Show Progress Bar" on "{progress_bar_enabled_ancestor_title}" section first.')
return cleaned_data