Source

Quiet apps / quiet / shop / forms / order.py

Full commit
from django import forms
from form_utils.forms import BetterForm
from quiet.common.countries import COUNTRIES

from quiet.common.conf import config

class OrderForm(BetterForm):
#    def __init__(self, gift_certificate=False, *args, **kwargs):
#        super(OrderForm, self).__init__(*args, **kwargs)
#        self.gift_certificate = gift_certificate

    telephone = forms.CharField(label="Telephone")
    email = forms.EmailField(label="Email")

    first_name = forms.CharField(label="First name", required=True)
    last_name = forms.CharField(label="Last name", required=True)
    address1 = forms.CharField(label="Address 1")
    address2 = forms.CharField(required=False, label="Address 2")
    address3 = forms.CharField(required=False, label="Address 3")
    city = forms.CharField(label="City")
    county = forms.CharField(required=False, label="County")
    if config.shop.international:
        country = forms.ChoiceField(label="Country", choices=COUNTRIES, initial="GBR")
    postcode = forms.RegexField(label="Postcode", regex=r'^(([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2}))$', max_length=10, error_message=("Please enter a valid UK postcode")) 

    delivery_telephone = forms.CharField(required=False, label="Telephone")
    delivery_email = forms.EmailField(required=False, label="Email")
    delivery_first_name = forms.CharField(label="First name", required=False)
    delivery_last_name = forms.CharField(label="Last name", required=False)
    delivery_address1 = forms.CharField(required=False, label="Address 1")
    delivery_address2 = forms.CharField(required=False, label="Address 2")
    delivery_address3 = forms.CharField(required=False, label="Address 3")
    delivery_city = forms.CharField(required=False, label="City")
    delivery_county = forms.CharField(required=False, label="County")
    if config.shop.international:
        delivery_country = forms.ChoiceField(label="Country", choices=COUNTRIES, initial="GBR")
    delivery_postcode = forms.RegexField(required=False, label="Postcode", regex=r'^(([Gg][Ii][Rr] 0[Aa]{2})|((([A-Za-z][0-9]{1,2})|(([A-Za-z][A-Ha-hJ-Yj-y][0-9]{1,2})|(([A-Za-z][0-9][A-Za-z])|([A-Za-z][A-Ha-hJ-Yj-y][0-9]?[A-Za-z])))) [0-9][A-Za-z]{2}))$', max_length=10, error_message=("Please enter a valid UK postcode")) 

    #def clean(self):
    #    if gift_certificate:
    #        cleaned_data = self.
    #    cc_myself = cleaned_data.get("cc_myself")

    #    if cc_myself and subject:
    #        if "help" not in subject:
    #            raise forms.ValidationError("Did not send for 'help' in the subject despite CC'ing yourself.")

    #    return cleaned_data

    class Meta:
        fieldsets = (
            ('billing', {
                    'fields': ('first_name', 'last_name', 'email', 'telephone', 'address1', 'address2', 'address3', 'city', 'county', 'postcode', 'country'), 
                    'legend':'Billing details', 'classes':('half', 'billing')}),
            ('delivery', {
                    'fields': ('delivery_first_name', 'delivery_last_name', 'delivery_telephone', 'delivery_address1', 'delivery_address2', 'delivery_address3', 'delivery_city', 'delivery_county', 'delivery_postcode', 'delivery_country'), 
                    'legend':'Delivery details <span>(if different from billing details)</span>', 'classes':('half', 'delivery')}),
            )