From 508360472acc19366668d60a90a92942ffa94cf0 Mon Sep 17 00:00:00 2001 From: PCoder Date: Wed, 26 Sep 2018 09:14:11 +0200 Subject: [PATCH] Add amount/recurring form fields validation --- hosting/forms.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/hosting/forms.py b/hosting/forms.py index 9eb5b2d2..928f910e 100644 --- a/hosting/forms.py +++ b/hosting/forms.py @@ -82,6 +82,20 @@ class GenericPaymentForm(forms.Form): model = GenericProduct 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): confirm_password = forms.CharField(label=_("Confirm Password"),