Changeset - 05c7ed664763
[Not reviewed]
0 1 0
Ben Sturmfels (bsturmfels) - 11 months ago 2023-10-19 00:52:04
ben@sturm.com.au
assignment: Prevent unhandled error when fields not provided

This typically happens when a bot is submitting the form. This should be a
validation error rather than an unhandled exception.
1 file changed with 6 insertions and 5 deletions:
0 comments (0 inline, 0 general)
www/conservancy/apps/assignment/forms.py
Show inline comments
...
 
@@ -60,13 +60,14 @@ class AssignmentForm(forms.ModelForm):
 
            'period_ends',
 
            'agreement_terms',
 
            'attestation_of_copyright',
 
        ]
 

	
 
    def clean_period_ends(self):
 
        if 'period_begins' in self.cleaned_data and 'period_ends' in self.cleaned_data and self.cleaned_data['period_begins'] and self.cleaned_data['period_ends'] and self.cleaned_data['period_begins'] > self.cleaned_data['period_ends']:
 
        period_begins = self.cleaned_data.get('period_begins')
 
        period_ends = self.cleaned_data.get('period_ends')
 
        period_end_type = self.cleaned_data.get('period_end_type')
 
        if period_begins and period_ends and period_begins > period_ends:
 
            raise ValidationError('End of period is before start')
 

	
 
        if self.cleaned_data['period_end_type'] == 'a specific past date' and not self.cleaned_data['period_ends']:
 
        if period_end_type == 'a specific past date' and not period_ends:
 
            raise ValidationError('This field is required')
 

	
 
        return self.cleaned_data['period_ends']
 
        return period_ends
0 comments (0 inline, 0 general)