diff options
author | Marcin Gębala <maarcin.gebala@gmail.com> | 2017-02-23 13:36:17 +0100 |
---|---|---|
committer | Marcin Gębala <maarcin.gebala@gmail.com> | 2017-02-23 13:36:17 +0100 |
commit | a79e22f405eb9d6585a131c132e73ec08fad314e (patch) | |
tree | 8bb6dde31ee70028c5460e0b478b06f4d9c24f34 | |
parent | dd3d7aa477b1c8be2b589063f4b696d1c0d167fe (diff) | |
download | django-payments-taler-a79e22f405eb9d6585a131c132e73ec08fad314e.tar.gz django-payments-taler-a79e22f405eb9d6585a131c132e73ec08fad314e.tar.bz2 django-payments-taler-a79e22f405eb9d6585a131c132e73ec08fad314e.zip |
Move functions that generate choices to utils
-rw-r--r-- | payments/fields.py | 16 | ||||
-rw-r--r-- | payments/stripe/forms.py | 8 | ||||
-rw-r--r-- | payments/utils.py | 14 |
3 files changed, 20 insertions, 18 deletions
diff --git a/payments/fields.py b/payments/fields.py index 761365e..1c1290a 100644 --- a/payments/fields.py +++ b/payments/fields.py @@ -8,6 +8,7 @@ from django.core import validators from django.utils.translation import ugettext_lazy as _ from .core import get_credit_card_issuer +from .utils import get_month_choices, get_year_choices from .widgets import CreditCardExpiryWidget, CreditCardNumberWidget @@ -74,13 +75,13 @@ class CreditCardExpiryField(forms.MultiValueField): fields = ( forms.ChoiceField( - choices=CreditCardExpiryField.get_month_choices(), + choices=get_month_choices(), error_messages={'invalid': errors['invalid_month']}, widget=forms.Select( attrs={'autocomplete': 'cc-exp-month', 'required': 'required'})), forms.ChoiceField( - choices=CreditCardExpiryField.get_year_choices(), + choices=get_year_choices(), error_messages={'invalid': errors['invalid_year']}, widget=forms.Select( attrs={'autocomplete': 'cc-exp-year', @@ -113,17 +114,6 @@ class CreditCardExpiryField(forms.MultiValueField): return date(year, month, day) return None - @classmethod - def get_month_choices(cls): - month_choices = [(str(x), '%02d' % (x,)) for x in range(1, 13)] - return [('', _('Month'))] + month_choices - - @classmethod - def get_year_choices(cls): - year_choices = [(str(x), str(x)) for x in range( - date.today().year, date.today().year + 15)] - return [('', _('Year'))] + year_choices - class CreditCardVerificationField(forms.CharField): diff --git a/payments/stripe/forms.py b/payments/stripe/forms.py index f26d590..0c83657 100644 --- a/payments/stripe/forms.py +++ b/payments/stripe/forms.py @@ -4,9 +4,9 @@ import stripe from django import forms from django.utils.translation import ugettext as _ -from payments.fields import CreditCardExpiryField from .. import FraudStatus, PaymentStatus, RedirectNeeded from ..forms import PaymentForm as BasePaymentForm, CreditCardPaymentFormWithName +from ..utils import get_month_choices, get_year_choices from ..widgets import ( SensitiveTextInput, SensitiveSelect, CreditCardExpiryWidget) from .widgets import StripeCheckoutWidget, StripeWidget @@ -100,13 +100,11 @@ class PaymentForm(StripeFormMixin, CreditCardPaymentFormWithName): SensitiveSelect( attrs={'autocomplete': 'cc-exp-month', 'required': 'required'}, - choices=CreditCardExpiryField.get_year_choices()), + choices=get_month_choices()), SensitiveSelect( attrs={'autocomplete': 'cc-exp-year', 'required': 'required'}, - choices=CreditCardExpiryField.get_year_choices())]) - } + choices=get_year_choices())])} for field_name, widget in widget_map.items(): self.fields[field_name].widget = widget self.fields[field_name].required = False - diff --git a/payments/utils.py b/payments/utils.py new file mode 100644 index 0000000..2d78659 --- /dev/null +++ b/payments/utils.py @@ -0,0 +1,14 @@ +from datetime import date + +from django.utils.translation import ugettext_lazy as _ + + +def get_month_choices(): + month_choices = [(str(x), '%02d' % (x,)) for x in range(1, 13)] + return [('', _('Month'))] + month_choices + + +def get_year_choices(): + year_choices = [(str(x), str(x)) for x in range( + date.today().year, date.today().year + 15)] + return [('', _('Year'))] + year_choices |