Validation of power reqs

This commit is contained in:
2020-08-30 12:15:04 +01:00
parent bfe80db85e
commit f3c2ce2519
10 changed files with 281 additions and 53 deletions

View File

@@ -173,6 +173,12 @@ class EventRiskAssessmentForm(forms.ModelForm):
class EventChecklistForm(forms.ModelForm):
def __init__(self, *args, **kwargs):
super(EventChecklistForm, self).__init__(*args, **kwargs)
for name, field in self.fields.items():
if field.__class__ == forms.NullBooleanField:
# Only display yes/no to user, the 'none' is only ever set in the background
field.widget = forms.CheckboxInput()
# Parsed from incoming form data by clean, then saved into models when the form is saved
items = {}
@@ -231,6 +237,7 @@ class EventChecklistForm(forms.ModelForm):
# Remove all existing, to be recreated from the form
checklist.vehicles.all().delete()
checklist.crew.all().delete()
checklist.save()
for key in self.items:
item = self.items[key]
@@ -240,8 +247,6 @@ class EventChecklistForm(forms.ModelForm):
item.full_clean()
item.save()
checklist.save()
self.items.clear()
return checklist