Example #1
0
class UpdateForm_(Bootstrap3Form):

    # login = forms.CharField(label='Логин', min_length=2, max_length=20, required=True,
    #                       error_messages={'invalid': 'Поле должно быть заполнено'})
    firstname = fields.CharField(label='Имя',
                                 min_length=2,
                                 max_length=100,
                                 required=True)
    lastname = fields.CharField(label='Фамилия',
                                min_length=2,
                                max_length=100,
                                required=True)
    middlename = fields.CharField(label='Отчество',
                                  min_length=2,
                                  max_length=100,
                                  required=True)
    address = fields.CharField(label='Адрес',
                               required=True,
                               widget=forms.Textarea(attrs={
                                   'cols': '80',
                                   'rows': '3'
                               }))
    tel = fields.RegexField(
        r'^\+?[0-9 .-]{4,14}$',
        label='Телефон',
        max_length=15,
        error_messages={'invalid': '4-14 цифр, начинается с \'+\''})
    old_password = fields.CharField(
        label='Текущий пароль',
        widget=forms.PasswordInput,
        required=False,
        min_length=5,
        error_messages={'invalid': 'Не менее 5 символов'})
    password_re = fields.CharField(
        label='Новый пароль',
        widget=forms.PasswordInput,
        required=False,
        min_length=5,
        error_messages={'invalid': 'Не менее 5 символов'})
    password_re2 = fields.CharField(
        label='Новый пароль еще раз',
        widget=forms.PasswordInput,
        required=False,
        min_length=5,
        error_messages={'invalid': 'Не менее 5 символов'})
Example #2
0
class NotLoginForm_(Bootstrap3Form):

    firstname = fields.CharField(
        label='Имя',
        min_length=2,
        max_length=100,
        required=True,
        error_messages={'invalid': 'Минимум 2 символа'})
    lastname = fields.CharField(
        label='Фамилия',
        min_length=2,
        max_length=100,
        required=True,
        error_messages={'invalid': 'Минимум 2 символа'})
    middlename = fields.CharField(
        label='Отчество',
        min_length=2,
        max_length=100,
        required=True,
        error_messages={'invalid': 'Минимум 2 символа'})
    email = fields.EmailField(
        label='E-Mail',
        required=True,
        error_messages={'invalid': '*****@*****.**'},
        help_text='Информация о  заказе будет выслана на указанный Вами e-mail'
    )
    address = fields.CharField(label='Адрес',
                               required=True,
                               widget=forms.Textarea(attrs={
                                   'cols': '80',
                                   'rows': '3'
                               }))
    tel = fields.RegexField(
        r'^\+?[0-9 .-]{4,25}$',
        label='Телефон',
        error_messages={'invalid': '4-25 цифр, начинается с \'+\''})

    comment = fields.CharField(label='Комментарий к заказу',
                               required=False,
                               widget=forms.Textarea(attrs={
                                   'cols': '80',
                                   'rows': '5'
                               }))
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')