예제 #1
0
class DummyForm(NgModelFormMixin, NgForm):
    email = fields.EmailField(label='E-Mail')
    onoff = fields.BooleanField(initial=False, required=True)
    sex = fields.ChoiceField(choices=(('m', 'Male'), ('f', 'Female')),
                             widget=widgets.RadioSelect)
    select_multi = fields.MultipleChoiceField(choices=CHOICES)
    check_multi = fields.MultipleChoiceField(
        choices=CHOICES, widget=widgets.CheckboxSelectMultiple)
    hide_me = fields.CharField(widget=widgets.HiddenInput)
    scope_prefix = 'dataroot'

    def __init__(self, *args, **kwargs):
        kwargs.update(auto_id=False,
                      ng_class='fieldClass(\'%(identifier)s\')',
                      scope_prefix=self.scope_prefix)
        super(DummyForm, self).__init__(*args, **kwargs)
        self.sub1 = SubForm1(prefix='sub1', **kwargs)
        self.sub2 = SubForm2(prefix='sub2', **kwargs)

    def get_initial_data(self):
        data = super(DummyForm, self).get_initial_data()
        data.update({
            self.sub1.prefix: self.sub1.get_initial_data(),
            self.sub2.prefix: self.sub2.get_initial_data(),
        })
        return data

    def is_valid(self):
        if not self.sub1.is_valid():
            self.errors.update(self.sub1.errors)
        if not self.sub2.is_valid():
            self.errors.update(self.sub2.errors)
        return super(
            DummyForm,
            self).is_valid() and self.sub1.is_valid() and self.sub2.is_valid()
class CoordinatorsContactForm(RepanierForm):
    staff = fields.MultipleChoiceField(
        label=EMPTY_STRING,
        choices=(),
        widget=CheckboxSelectMultipleWidget(
            label=_("This message will only be sent to the member(s) of the management team that you select below:")
        )
    )
    your_email = fields.EmailField(label=_('My email address'))
    subject = fields.CharField(label=_('Subject'), max_length=100)
    message = fields.CharField(label=_('Message'), widget=widgets.Textarea)

    def __init__(self, *args, **kwargs):
        super(CoordinatorsContactForm, self).__init__(*args, **kwargs)
        choices = []
        for staff in Staff.objects.filter(
                is_active=True,
                translations__language_code=translation.get_language()
        ):
            if staff.is_coordinator or staff.is_invoice_manager or staff.is_invoice_referent or staff.is_webmaster:
                r = staff.customer_responsible
                if r is not None:
                    sender_function = staff.safe_translation_getter(
                        'long_name', any_language=True, default=EMPTY_STRING
                    )
                    phone = " ({})".format(r.phone1 if r.phone1 else EMPTY_STRING)
                    name = r.long_basket_name if r.long_basket_name else r.short_basket_name
                    signature = "<b>{}</b> : {}{}".format(sender_function, name, phone)
                    choices.append(("{}".format(staff.id), mark_safe(signature)))
        self.fields["staff"].choices = choices
예제 #3
0
class CheckboxChoicesForm(NgModelFormMixin, NgForm):
    scope_prefix = 'data'

    check_multi = fields.MultipleChoiceField(
        choices=[('a', 'Choice A'), ('b', 'Choice B'), ('c', 'Choice C')],
        widget=widgets.CheckboxSelectMultiple,
    )
예제 #4
0
 def __init__(self, *args, **kwargs):
     super(SearchForm, self).__init__(*args, **kwargs)
     self.fields['search_on'] = fields.MultipleChoiceField(
         label="Search On",
         widget=forms.CheckboxSelectMultiple,
         choices=[(place.id, place.name)
                  for place in SearchPlace.objects.all()])
예제 #5
0
class CoordinatorsContactForm(RepanierForm):
    staff = fields.MultipleChoiceField(label=EMPTY_STRING,
                                       choices=[],
                                       widget=CheckboxSelectMultipleWidget())
    your_email = fields.EmailField(label=_('Your Email'))
    subject = fields.CharField(label=_('Subject'), max_length=100)
    message = fields.CharField(label=_('Message'), widget=widgets.Textarea)

    def __init__(self, *args, **kwargs):
        super(CoordinatorsContactForm, self).__init__(*args, **kwargs)
        choices = []
        for staff in Staff.objects.filter(
                is_active=True,
                is_contributor=False,
                translations__language_code=translation.get_language()):
            r = staff.customer_responsible
            if r is not None:
                sender_function = staff.safe_translation_getter(
                    'long_name', any_language=True, default=EMPTY_STRING)
                phone = " (%s)" % r.phone1 if r.phone1 else EMPTY_STRING
                name = r.long_basket_name if r.long_basket_name else r.short_basket_name
                signature = "<b>%s</b> : %s%s" % (sender_function, name, phone)
                choices.append(("%d" % staff.id, mark_safe(signature)))
        self.fields["staff"] = fields.MultipleChoiceField(
            label=EMPTY_STRING,
            choices=choices,
            widget=CheckboxSelectMultipleWidget())
예제 #6
0
class SearchForm(Bootstrap3Form):
    """This object is representing a form used for searchng through searchplaces"""
    search_places = SearchPlace.objects.values('id', 'name')
    search_string = fields.CharField(label="Search", max_length=100)
    search_on = fields.MultipleChoiceField(choices=[])

    def __init__(self, *args, **kwargs):
        super(SearchForm, self).__init__(*args, **kwargs)
        self.fields['search_on'] = fields.MultipleChoiceField(
            label="Search On",
            widget=forms.CheckboxSelectMultiple,
            choices=[(place.id, place.name)
                     for place in SearchPlace.objects.all()])
예제 #7
0
class CheckboxChoicesForm(NgFormValidationMixin, NgForm):
    check_multi = fields.MultipleChoiceField(
        choices=[('a', 'Choice A'), ('b', 'Choice B'), ('c', 'Choice C')],
        widget=widgets.CheckboxSelectMultiple,
    )
예제 #8
0
class SelectMultipleChoicesForm(NgFormValidationMixin, NgForm):
    select_multi = fields.MultipleChoiceField(
        choices=[('a', 'Choice A'), ('b', 'Choice B'), ('c', 'Choice C')])
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')
예제 #10
0
class SelectMultipleChoicesForm(NgModelFormMixin, NgForm):
    scope_prefix = 'form_data'

    select_multi = fields.MultipleChoiceField(
        choices=[('a', 'Choice A'), ('b', 'Choice B'), ('c', 'Choice C')])