Add amount/recurring form fields validation

This commit is contained in:
PCoder 2018-09-26 09:14:11 +02:00
parent 48ba6a6166
commit 508360472a

View file

@ -82,6 +82,20 @@ class GenericPaymentForm(forms.Form):
model = GenericProduct model = GenericProduct
fields = ['product_name', 'amount', 'recurring', 'description'] fields = ['product_name', 'amount', 'recurring', 'description']
def clean_amount(self):
amount = self.cleaned_data.get('amount')
if (float(self.cleaned_data.get('product_name').get_actual_price()) !=
amount):
raise forms.ValidationError(_("Amount field does not match"))
return amount
def clean_recurring(self):
recurring = self.cleaned_data.get('recurring')
if (self.cleaned_data.get('product_name').product_is_subscription !=
(True if recurring else False)):
raise forms.ValidationError(_("Recurring field does not match"))
return recurring
class HostingUserSignupForm(forms.ModelForm): class HostingUserSignupForm(forms.ModelForm):
confirm_password = forms.CharField(label=_("Confirm Password"), confirm_password = forms.CharField(label=_("Confirm Password"),