コード例 #1
0
ファイル: forms.py プロジェクト: jnm/django-zebra
 def __init__(self, *args, **kwargs):
     super(StripePaymentForm, self).__init__(*args, **kwargs)
     self.fields['card_cvv'].label = "Card CVC"
     self.fields['card_cvv'].help_text = "Card Verification Code; see rear of card."
     months = [ (m[0], u'%02d - %s' % (m[0], unicode(m[1])))
                 for m in sorted(MONTHS.iteritems()) ]
     self.fields['card_expiry_month'].choices = months
コード例 #2
0
def article_list(request, article_category='news'):

    article_category = get_object_or_404(ArticleCategory,
                                         permalink=article_category)

    year_min = News.objects.all().aggregate(Min('created'))['created__min']
    year_min = (year_min and year_min.year) or datetime.date.today().year

    year_list = range(year_min, datetime.date.today().year + 1)

    year_list = [{'title': year, 'permalink': year} for year in year_list]
    month_list = [{
        'permalink': permalink,
        'title': title
    } for permalink, title in MONTHS.iteritems()]

    context = {
        'year_list': year_list,
        'show_year_filter': len(year_list) > 1,
        'month_list': month_list,
        'item_template':
        '<div ng-include="\'template_party_news.html\'"></div>',
        'article_category': article_category,
        'article_category_name': article_category.title  # deprecate
    }

    try:
        return render(request,
                      'cms/news/%s_list.html' % article_category.permalink,
                      context)
    except TemplateDoesNotExist:
        return render(request, 'cms/news/list.html', context)
コード例 #3
0
class StripePaymentForm(CardForm):
    def __init__(self, *args, **kwargs):
        super(StripePaymentForm, self).__init__(*args, **kwargs)
        self.fields['card_cvv'].label = "Card CVC"
        self.fields[
            'card_cvv'].help_text = "Card Verification Code; see rear of card."
        months = [(m[0], u'%02d - %s' % (m[0], unicode(m[1])))
                  for m in sorted(MONTHS.iteritems())]
        self.fields['card_expiry_month'].choices = months

    card_number = forms.CharField(
        required=False,
        max_length=20,
        widget=NoNameTextInput(attrs={'class': 'span5'}))
    card_cvv = forms.CharField(
        required=False,
        max_length=4,
        widget=NoNameTextInput(attrs={'class': 'span2'}))
    card_expiry_month = forms.ChoiceField(required=False,
                                          widget=NoNameSelect(),
                                          choices=MONTHS.iteritems())
    card_expiry_year = forms.ChoiceField(
        required=False,
        widget=NoNameSelect(),
        choices=options.ZEBRA_CARD_YEARS_CHOICES)
コード例 #4
0
 def __init__(self, *args, **kwargs):
     super(StripePaymentForm, self).__init__(*args, **kwargs)
     self.fields['card_cvv'].label = "Card CVC"
     self.fields['card_cvv'].help_text = "Card Verification Code; see rear of card."
     months = [ (m[0], u'%02d - %s' % (m[0], unicode(m[1])))
                 for m in sorted(MONTHS.iteritems()) ]
     self.fields['card_expiry_month'].choices = months
コード例 #5
0
class StripePaymentForm(CardForm):
    card_number = forms.CharField(required=False,
                                  max_length=20,
                                  widget=NoNameTextInput())
    card_cvv = forms.CharField(required=False,
                               max_length=4,
                               widget=NoNameTextInput())
    card_expiry_month = forms.ChoiceField(required=False,
                                          widget=NoNameSelect(),
                                          choices=MONTHS.iteritems())
    card_expiry_year = forms.ChoiceField(
        required=False,
        widget=NoNameSelect(),
        choices=options.ZEBRA_CARD_YEARS_CHOICES)
コード例 #6
0
def event_list(request):

    year_max = Event.objects.all().aggregate(Max('end_date'))['end_date__max']
    year_max = (year_max and year_max.year) or datetime.date.today().year

    year_list = range(datetime.date.today().year, year_max + 1)

    year_list = [{'title': year, 'permalink': year} for year in year_list]
    month_list = [{
        'permalink': permalink,
        'title': title
    } for permalink, title in MONTHS.iteritems()]

    return render(
        request, 'cms/event/list.html', {
            'year_list': year_list,
            'show_year_filter': len(year_list) > 1,
            'month_list': month_list
        })
コード例 #7
0
    def as_dict(self):
        widget_dict = super(RemoteDateInput, self).as_dict()

        widget_dict['input_type'] = 'date'

        years = self.widget.years
        if not callable(self.widget.years):
            years = lambda: self.widget.years

        choices = [{'key': "%02d" % i, 'value': i} for i in range(1, 32)]
        day_choices = self.create_select('day', choices)

        choices = [{'key': "%02d" % i, 'value': j} for (i, j) in MONTHS.iteritems()]
        month_choices = self.create_select('month', choices)

        choices = [{'key': "%s" % i, 'value': i} for i in years()]
        year_choices = self.create_select('year', choices)

        widget_dict['choices'] = [day_choices, month_choices, year_choices]
        return widget_dict
コード例 #8
0
class OrderForm(FormsetForm, DiscountForm):
    """
    Main Form for the checkout process - ModelForm for the Order Model
    with extra fields for credit card. Used across each step of the
    checkout process with fields being hidden where applicable.
    """

    step = forms.IntegerField(widget=forms.HiddenInput())
    same_billing_shipping = forms.BooleanField(
        required=False,
        initial=True,
        label=_("My delivery details are the same as my billing details"))
    remember = forms.BooleanField(required=False,
                                  initial=True,
                                  label=_("Remember my address for next time"))
    card_name = forms.CharField(label=_("Cardholder name"))
    card_type = forms.ChoiceField(widget=forms.RadioSelect,
                                  choices=make_choices(
                                      settings.SHOP_CARD_TYPES))
    card_number = forms.CharField(required=False,
                                  max_length=20,
                                  widget=NoNameTextInput())
    card_cvv = forms.CharField(required=False,
                               max_length=4,
                               widget=NoNameTextInput())
    card_expiry_month = forms.ChoiceField(required=False,
                                          widget=NoNameSelect(),
                                          choices=MONTHS.iteritems())
    card_expiry_year = forms.ChoiceField(
        required=False,
        widget=NoNameSelect(),
        choices=options.ZEBRA_CARD_YEARS_CHOICES)
    last_4_digits = forms.CharField(required=True,
                                    min_length=4,
                                    max_length=4,
                                    widget=forms.HiddenInput())
    stripe_token = forms.CharField(required=True, widget=forms.HiddenInput())

    def addError(self, message):
        self._errors[NON_FIELD_ERRORS] = self.error_class([message])

    class Meta:
        model = Order
        fields = ([
            f.name
            for f in Order._meta.fields if f.name.startswith("billing_detail")
            or f.name.startswith("shipping_detail")
        ] + ["additional_instructions", "discount_code"])

    def __init__(self, request, step, data=None, initial=None, errors=None):
        """
        Handle setting shipping field values to the same as billing
        field values in case JavaScript is disabled, hiding fields for
        the current step.
        """

        # Copy billing fields to shipping fields if "same" checked.
        first = step == checkout.CHECKOUT_STEP_FIRST
        last = step == checkout.CHECKOUT_STEP_LAST
        if (first and data is not None and "same_billing_shipping" in data):
            data = copy(data)
            # Prevent second copy occuring for forcing step below when
            # moving backwards in steps.
            data["step"] = step
            for field in data:
                billing = field.replace("shipping_detail", "billing_detail")
                if "shipping_detail" in field and billing in data:
                    data[field] = data[billing]

        if initial is not None:
            initial["step"] = step
        # Force the specified step in the posted data - this is
        # required to allow moving backwards in steps.
        if data is not None and int(data["step"]) != step:
            data = copy(data)
            data["step"] = step

        super(OrderForm, self).__init__(request, data=data, initial=initial)
        self._checkout_errors = errors
        settings.use_editable()
        # Hide Discount Code field if no codes are active.
        if (DiscountCode.objects.active().count() == 0
                or not settings.SHOP_DISCOUNT_FIELD_IN_CHECKOUT):
            self.fields["discount_code"].widget = forms.HiddenInput()

        # Determine which sets of fields to hide for each checkout step.
        hidden = None
        if settings.SHOP_CHECKOUT_STEPS_SPLIT:
            if first:
                # Hide the cc fields for billing/shipping if steps are split.
                hidden = lambda f: (f.startswith("card_") or f ==
                                    "stripe_token" or f == "last_4_digits")
            elif step == checkout.CHECKOUT_STEP_PAYMENT:
                # Hide the non-cc fields for payment if steps are split.
                hidden = lambda f: not (f.startswith("card_") or f ==
                                        "stripe_token" or f == "last_4_digits")
        elif not settings.SHOP_PAYMENT_STEP_ENABLED:
            # Hide all the cc fields if payment step is not enabled.
            hidden = lambda f: (f.startswith("card_") or f == "stripe_token" or
                                f == "last_4_digits")
        if settings.SHOP_CHECKOUT_STEPS_CONFIRMATION and last:
            # Hide all fields for the confirmation step.
            hidden = lambda f: True
        if hidden is not None:
            for field in self.fields:
                if hidden(field):
                    self.fields[field].widget = forms.HiddenInput()
                    self.fields[field].required = False

        # Set the choices for the cc expiry year relative to the current year.
        year = now().year
        choices = make_choices(range(year, year + 21))
        self.fields["card_expiry_year"].choices = choices

    def clean(self):
        """
        Raise ``ValidationError`` if any errors have been assigned
        externally, via one of the custom checkout step handlers.
        """
        if self._checkout_errors:
            raise forms.ValidationError(self._checkout_errors)
        return self.cleaned_data