Private
Public Access
1
0

made form flexible

This commit is contained in:
Sander Roosendaal
2019-01-02 17:15:59 +01:00
parent 3cd0827661
commit e929e0fcb9

View File

@@ -19,9 +19,29 @@ from django.forms import formset_factory
from utils import landingpages
from metrics import axes
class FlexibleDecimalField(forms.DecimalField):
def to_python(self, value):
# check decimal symbol
comma_index = 0
dot_index = 0
try:
comma_index = value.index(',')
except ValueError:
pass
try:
dot_index = value.index('.')
except ValueError:
pass
if value:
if comma_index > dot_index:
value = value.replace('.', '').replace(',', '.')
return super(FlexibleDecimalField, self).to_python(value)
# BillingForm form
class BillingForm(forms.Form):
amount = forms.FloatField(required=True)
amount = FlexibleDecimalField(required=True,decimal_places=2,
max_digits=8)
plan = forms.IntegerField(widget=forms.HiddenInput())
payment_method_nonce = forms.CharField(max_length=255,required=True)