Add basic validation of item prerequisites

Currently throws the worlds most unhelpful error message...
This commit is contained in:
2022-02-23 16:01:00 +00:00
parent 41f5a23ef0
commit 3d36d986a4
5 changed files with 56 additions and 11 deletions

View File

@@ -16,6 +16,13 @@ class QualificationForm(forms.ModelForm):
self.fields['trainee'].initial = Profile.objects.get(pk=pk)
self.fields['date'].widget.format = '%Y-%m-%d'
def clean(self):
cleaned_data = super().clean()
item = cleaned_data.get('item')
trainee = cleaned_data.get('trainee')
if not item.user_has_requirements(trainee):
self.add_error('item', 'Missing prerequisites')
def clean_date(self):
date = self.cleaned_data['date']
if date > date.today():