-
Notifications
You must be signed in to change notification settings - Fork 18
Open
Description
Problem
Currently, these are the problems with validation of pool form:
- Seats can be assigned zero and negative values.
- User can select any past datetime values.
- Source and Destination can be same.
- Unpaid trips store the amount in database(if the paid box is unchecked, then the amount stored in database should be 0)
- Amount on paid trips cannot be negative
Solution
We can override the default form.clean() method on class PoolForm() and make a custom clean method.
def clean(self):
cleaned_data = super(PoolForm,self).clean()
if cleaned_data.get('tot') <= 0:
raise forms.ValidationError("There should be atleast 1 seats")
if datetime.strptime(cleaned_data.get('dateTime'),"%Y-%m-%d %H:%M") <= datetime.now():
raise forms.ValidationError("Selected DateTime has passed. Please select a valid date.")
if cleaned_data.get('source') == cleaned_data.get('dest'):
raise forms.ValidationError("Source and Destination should be different")
if cleaned_data.get('paid') == False:
self.cleaned_data['amount']=0
else :
if cleaned_data.get('amount') < 0:
raise forms.ValidationError("Amount should be positive")
return cleaned_data
@dipanshu231099 Please review this issue and its solution
Metadata
Metadata
Assignees
Labels
No labels