コード例 #1
0
class ClientPaymentInformation(MemberForm):

    facturation = forms.ChoiceField(
        label=_("Billing Type"),
        choices=RATE_TYPE,
        widget=forms.Select(attrs={'class': 'ui dropdown'}))

    same_as_client = forms.BooleanField(
        label=_("Same As Client"),
        required=False,
        help_text=_('If checked, the personal information '
                    'of the client will be used as billing information.'),
        widget=forms.CheckboxInput(attrs={}))

    billing_payment_type = forms.ChoiceField(
        label=_("Payment Type"),
        choices=PAYMENT_TYPE,
        widget=forms.Select(attrs={'class': 'ui dropdown'}),
        required=False)

    number = forms.IntegerField(label=_("Street Number"), required=False)

    apartment = forms.CharField(
        label=_("Apt #"),
        widget=forms.TextInput(attrs={'placeholder': _('Apt #')}),
        required=False)

    floor = forms.IntegerField(label=_("Floor"), required=False)

    street = forms.CharField(label=_("Street Name"), required=False)

    city = forms.CharField(label=_("City Name"), required=False)

    postal_code = CAPostalCodeField(label=_("Postal Code"), required=False)

    def clean(self):
        cleaned_data = super(ClientPaymentInformation, self).clean()

        if cleaned_data.get('same_as_client') is True:
            return cleaned_data

        member = cleaned_data.get('member')
        if member:
            member_id = member.split(' ')[0].replace('[', '').replace(']', '')
            member_obj = Member.objects.get(pk=member_id)
            if not member_obj.address:
                msg = _('This member has not a valid address, '
                        'please add a valid address to this member, so it can '
                        'be used for the billing.')
                self.add_error('member', msg)
        else:
            msg = _("This field is required")
            fields = ['street', 'city', 'postal_code']
            for field in fields:
                field_data = cleaned_data.get(field)
                if not field_data:
                    self.add_error(field, msg)
        return cleaned_data
コード例 #2
0
class CheckoutForm(forms.Form):
    first_name = forms.CharField()
    last_name = forms.CharField()
    street_address_1 = forms.CharField(widget=forms.TextInput(
        attrs={
            'class': "form-control",
            'placeholder': "1234 Main St."
        }))
    apartment = forms.CharField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': "form-control",
            'placeholder': "Apartment or suite"
        }))
    country = forms.ChoiceField(choices=COUNTRY_CHOICES,
                                widget=forms.Select(
                                    attrs={
                                        'onChange': 'countrySelect(this)',
                                        'class': 'custom-select d-block w-100',
                                    }))
    province = CAProvinceField(widget=CAProvinceSelect(
        attrs={
            'type': 'hidden',
            'class': 'custom-select d-block w-100',
        }))
    ca_postal_code = CAPostalCodeField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': 'custom-select d-block w-100',
        }))
    us_state = USStateField(
        widget=USStateSelect(attrs={
            'class': 'custom-select d-block w-100',
        }),
        required=False)
    us_zip_code = USZipCodeField(
        required=False,
        widget=forms.TextInput(attrs={
            'class': 'custom-select d-block w-100',
        }))
    same_billing_address = forms.BooleanField(widget=forms.CheckboxInput(),
                                              required=False)
    save_info = forms.BooleanField(widget=forms.CheckboxInput(),
                                   required=False)
    payment_option = forms.ChoiceField(choices=PAYMENT_CHOICE,
                                       widget=forms.RadioSelect())
コード例 #3
0
ファイル: validators.py プロジェクト: jayvdb/bluebottle
from clamd import ConnectionError, ClamdUnixSocket

from localflavor.be.forms import BEPostalCodeField
from localflavor.ca.forms import CAPostalCodeField
from localflavor.de.forms import DEZipCodeField
from localflavor.fr.forms import FRZipCodeField
from localflavor.nl.forms import NLZipCodeField

logger = logging.getLogger(__name__)

mime = magic.Magic(mime=True)

# Can safely add more post code form fields here.
postal_code_mapping = {
    'BE': BEPostalCodeField(),
    'CA': CAPostalCodeField(),
    'DE': DEZipCodeField(),
    'FR': FRZipCodeField(),
    'NL': NLZipCodeField(),
}


def validate_postal_code(value, country_code):
    if country_code in postal_code_mapping:
        field = postal_code_mapping[country_code]
        field.clean(value)


# Taken from django 1.11
# TODO: use normal validator once we have upgraded
class FileExtensionValidator(object):
コード例 #4
0
class ClientAddressInformation(forms.Form):

    apartment = forms.CharField(
        label=_("Apt #"),
        widget=forms.TextInput(attrs={
            'placeholder': _('Apt #'),
            'class': 'apartment'
        }),
        required=False)

    street = forms.CharField(
        max_length=100,
        label=_("Address Information"),
        widget=forms.TextInput(attrs={
            'placeholder': _('7275 Rue Saint-Urbain'),
            'class': 'street name'
        }))

    city = forms.CharField(max_length=50,
                           label=_("City"),
                           widget=forms.TextInput(attrs={
                               'placeholder': _('Montreal'),
                               'class': 'city'
                           }))

    postal_code = CAPostalCodeField(
        max_length=7,
        label=_("Postal Code"),
        widget=forms.TextInput(attrs={
            'placeholder': _('H2R 2Y5'),
            'class': 'postal code'
        }))

    latitude = forms.CharField(
        label=_('Latitude'),
        required=False,
        initial=0,
        widget=forms.TextInput(attrs={'class': 'latitude'}))

    longitude = forms.CharField(
        label=_('Longitude'),
        required=False,
        initial=0,
        widget=forms.TextInput(attrs={'class': 'longitude'}))

    distance = forms.CharField(
        label=_('Distance from Santropol'),
        required=False,
        initial=0,
        widget=forms.TextInput(attrs={'class': 'distance'}))

    route = forms.ModelChoiceField(
        label=_('Route'),
        required=True,
        widget=forms.Select(attrs={'class': 'ui search dropdown'}),
        queryset=Route.objects.all(),
    )

    delivery_note = forms.CharField(
        label=_("Delivery Note"),
        required=False,
        widget=forms.Textarea(attrs={
            'rows': 2,
            'placeholder': _('Delivery Note here ...')
        }))