Пример #1
0
class EditOrderForm(Bootstrap3Form):

    status = fields.ChoiceField(choices=Order.status_in_choices, label='Статус',
                                widget=forms.RadioSelect, required=True)
    prepay = fields.FloatField(label='Сумма предоплаты', required=True)
    relay_free = fields.FloatField(label='Сумма оплаты за пересылку')
    total = fields.FloatField(label='Итоговая сумма', required=True)
    type_of_dispatch = fields.ChoiceField(choices=Order.dispatch, label='Тип отправления', widget=forms.Select, required=True)
    track_number = fields.CharField(label='Номер для отслеживания',  min_length=0, max_length=20, required=False)
    linked_orders = fields.CharField(label='Связанные заказы', min_length=0, max_length=100, required=False)
class SubscribeForm(NgFormValidationMixin, Bootstrap3Form):
    use_required_attribute = False

    CONTINENT_CHOICES = [('am', 'America'), ('eu', 'Europe'), ('as', 'Asia'),
                         ('af', 'Africa'), ('au', 'Australia'),
                         ('oc', 'Oceania'), ('an', 'Antartica')]
    TRAVELLING_BY = [('foot', 'Foot'), ('bike', 'Bike'), ('mc', 'Motorcycle'),
                     ('car', 'Car'), ('public', 'Public Transportation'),
                     ('train', 'Train'), ('air', 'Airplane')]
    NOTIFY_BY = [('email', 'EMail'), ('phone', 'Phone'), ('sms', 'SMS'),
                 ('postal', 'Postcard')]

    first_name = fields.CharField(label='First name',
                                  min_length=3,
                                  max_length=20)

    last_name = fields.RegexField(
        r'^[A-Z][a-z -]?',
        label='Last name',
        error_messages={'invalid': 'Last names shall start in upper case'})

    sex = fields.ChoiceField(
        choices=(('m', 'Male'), ('f', 'Female')),
        widget=widgets.RadioSelect,
        error_messages={'invalid_choice': 'Please select your sex'})

    email = fields.EmailField(label='E-Mail',
                              required=True,
                              help_text='Please enter a valid email address')

    subscribe = fields.BooleanField(label='Subscribe Newsletter',
                                    initial=False,
                                    required=False)

    phone = fields.RegexField(
        r'^\+?[0-9 .-]{4,25}$',
        label='Phone number',
        error_messages={
            'invalid': 'Phone number have 4-25 digits and may start with +'
        })

    birth_date = fields.DateField(
        label='Date of birth',
        widget=widgets.DateInput(
            attrs={'validate-date': '^(\d{4})-(\d{1,2})-(\d{1,2})$'}),
        help_text='Allowed date format: yyyy-mm-dd')

    continent = fields.ChoiceField(
        label='Living on continent',
        choices=CONTINENT_CHOICES,
        error_messages={'invalid_choice': 'Please select your continent'})

    weight = fields.IntegerField(
        label='Weight in kg',
        min_value=42,
        max_value=95,
        error_messages={'min_value': 'You are too lightweight'})

    height = fields.FloatField(
        label='Height in meters',
        min_value=1.48,
        max_value=1.95,
        step=0.05,
        error_messages={'max_value': 'You are too tall'})

    traveling = fields.MultipleChoiceField(
        label='Traveling by',
        choices=TRAVELLING_BY,
        help_text='Choose one or more carriers',
        required=True)

    notifyme = fields.MultipleChoiceField(
        label='Notify by',
        choices=NOTIFY_BY,
        widget=widgets.CheckboxSelectMultiple,
        required=True,
        help_text='Must choose at least one type of notification')

    annotation = fields.CharField(label='Annotation',
                                  required=True,
                                  widget=widgets.Textarea(attrs={
                                      'cols': '80',
                                      'rows': '3'
                                  }))

    agree = fields.BooleanField(label='Agree with our terms and conditions',
                                initial=False,
                                required=True)

    password = fields.CharField(label='Password',
                                widget=widgets.PasswordInput,
                                validators=[validate_password],
                                help_text='The password is "secret"')

    confirmation_key = fields.CharField(max_length=40,
                                        required=True,
                                        widget=widgets.HiddenInput(),
                                        initial='hidden value')