示例#1
0
class ComboFieldForm(forms.Form):
    description = "ComboField options"

    field1 = forms.ComboField(
        help_text='reference sample',
        fields=[forms.CharField(max_length=20),
                forms.EmailField()])
    field2 = forms.ComboField(
        help_text='disabled',
        disabled=True,
        required=False,
        fields=[forms.CharField(max_length=20),
                forms.EmailField()])
示例#2
0
class LotesAdminForm(forms.ModelForm):
    class Meta(object):
        model = Lotes

    oproduccion = forms.CharField(
        label='Orden Produccion',
        widget=selectable.AutoComboboxSelectWidget(OProduccionLookup),
        required=True)
    fecha = forms.DateField()
    lote = forms.CharField()
    analiticas = forms.ComboField()
    procesos = forms.ComboField()
    templote = forms.CharField()
    carorganolep = forms.CharField()
    observaciones = forms.CharField()
示例#3
0
class CorsoForm(forms.ModelForm):
    url_stato_corso = 'corsi:ajax_lista_stati_corso'

    codice_edizione = forms.CharField(required=True,
                                      widget=JqxTextInput(jqxattrs={'height': 30, 'width': 80, 'minLength': 6}))
    denominazione = forms.CharField(required=True,
                                    widget=JqxTextInput(jqxattrs={'height': 30, 'width': 400, 'minLength': 5}))
    durata = forms.IntegerField(required=True,
                                widget=JqxTextInput(jqxattrs={'height': 30, 'width': 50}))
    cdc_txt = forms.CharField(required=True, widget=forms.TextInput(attrs={'readonly': 'True'}))
    stato_corso = forms.ComboField(
        fields=[forms.CharField(), ], required=False,
        widget=JqxComboInput(
            jqxattrs={'height': 30, 'width': 150, 'minLength': 5,
                      'displayMember': 'descrizione', 'valueMember': "id",
                      'data_adapter_url': url_stato_corso},
            attrs={'style': 'float: left; margin-right: 5px;'}))
    data_inizio = forms.DateField(required=True,
                                  widget=JqxDateInput(jqxattrs={'height': 30, 'width': '150'}))
    data_fine = forms.DateField(required=True,
                                widget=JqxDateInput(jqxattrs={'height': 30, 'width': '150'}))
    note = forms.CharField(required=False,
                           widget=JqxTextArea(jqxattrs={'height': 200, 'width': 500, 'minLength': 1}))

    class Meta:
        model = Corso
        fields = ['codice_edizione', 'denominazione', 'durata', 'cdc', 'stato_corso', 'note',
                  'data_inizio', 'data_fine']
        widgets = {
            'cdc': forms.HiddenInput(),
        }
示例#4
0
 class NameForm(forms.Form):
     your_name = forms.CharField(label='Your name', max_length=100)
     your_name1 = forms.CharField(label='Your 333', max_length=100)
     your_name2 = forms.CharField(label='Your 222', max_length=100)
     sender = forms.EmailField()
     cc_myself = forms.BooleanField(required=False)
     cc_myself1 = forms.URLField(required=False)
     abc = forms.ComboField()
     aaa = forms.CheckboxInput()
示例#5
0
文件: forms.py 项目: idlweb/psy
class noFS_Form(forms.Form):

    campo1 = forms.CharField(label='campo1', max_length=100)
    campo2 = forms.CharField(label='campo2')
    campo3 = forms.CharField(label='campo3')
    campo4 = forms.EmailField(label='email', required=False)
    campo5 = forms.IntegerField(label='numero intero')
    campo6 = forms.DateField(initial = datetime.date.today)
    campo7 = forms.CharField(widget=forms.Textarea)
    campo8 = forms.ComboField(label='combo', fields=[forms.CharField(max_length=20), forms.EmailField()])
示例#6
0
class DatingForm(ModelForm):
    type = forms.ComboField(label='Type')
    name = forms.CharField(label='Name')
    description = forms.CharField(label='Pet Description',
                                  widget=Textarea(attrs={
                                      'cols': 50,
                                      'rows': 20
                                  }))

    class Meta:
        model = Pet
        fields = ('type', 'name', 'description', 'owner')
示例#7
0
class MovieSearchByLanguageForm(SearchForm):
    lang = forms.ComboField(required=False)
    video_format = forms.ComboField(required=False)
    video_codec = forms.ComboField(required=False)
    video_source = forms.ComboField(required=False)
    audio_source = forms.ComboField(required=False)

    def search(self):

        sqs = super(MovieSearchByLanguageForm, self).search()

        sqs = sqs.exclude(is_broken=True)

        if not self.is_valid():
            return self.no_query_found()

        if self.cleaned_data['lang']:
            lang_code = self.cleaned_data['lang'].upper()
            print lang_code
            sqs = sqs.filter(language__iexact=lang_code)

        if self.cleaned_data['video_format']:
            code = self.cleaned_data['video_format']
            sqs = sqs.filter(video_format__iexact=code)

        if self.cleaned_data['video_codec']:
            code = self.cleaned_data['video_codec']
            sqs = sqs.filter(video_codec__iexact=code)

        if self.cleaned_data['video_source']:
            code = self.cleaned_data['video_source']
            sqs = sqs.filter(video_source__iexact=code)

        if self.cleaned_data['audio_source']:
            code = self.cleaned_data['audio_source']
            sqs = sqs.filter(audio_source__iexact=code)

        sqs = sqs.order_by('-seed', '-leech')

        return sqs
示例#8
0
class AllElementsForm(forms.Form):
    boolean_checkbox = forms.BooleanField()
    text_input = forms.CharField(help_text="Sample text input",
                                 max_length=50,
                                 min_length=10)
    textarea_input = forms.CharField(help_text="Sample textarea",
                                     max_length=50,
                                     min_length=10,
                                     widget=forms.Textarea)
    choices_field = forms.ChoiceField(choices=((('1', 'One'), ('2', 'Two'),
                                                ('3', 'Three'))))
    choices_radio_field = forms.ChoiceField(choices=((('1', 'One'), ('2',
                                                                     'Two'),
                                                      ('3', 'Three'))),
                                            widget=forms.RadioSelect)
    date_field = forms.DateField(input_formats=['%d.%m.%Y'],
                                 initial=datetime.now())
    datetime_field = forms.DateTimeField(input_formats=['%d.%m.%Y %H:%M'],
                                         initial=datetime.now())
    decimal_field = forms.DecimalField(max_value=100,
                                       min_value=10,
                                       max_digits=5,
                                       decimal_places=2)
    email_field = forms.EmailField(min_length=5, max_length=50)
    file_field = forms.FileField(max_length=250,
                                 help_text='Attach any file here')
    filepath_field = forms.FilePathField(path=os.path.join(
        settings.BASE_DIR, 'tests/templates'),
                                         recursive=True)
    float_field = forms.FloatField(min_value=10, max_value=100)
    image_field = forms.ImageField()
    integer_field = forms.IntegerField(min_value=10, max_value=100)
    ipaddress_field = forms.IPAddressField()
    generic_ipaddress_field = forms.GenericIPAddressField(protocol='IPv6')
    multiplechoice_field = forms.MultipleChoiceField(
        (('1', 'One'), ('2', 'Two'), ('3', 'Three'), ('4', 'Four'),
         ('5', 'Five'), ('6', 'Siz')))
    nullboolean_field = forms.NullBooleanField()
    regex_field = forms.RegexField(regex='[a-zA-Z]+')
    slug_field = forms.SlugField()
    time_field = forms.TimeField(input_formats=['%H:%M'],
                                 initial=datetime.now())
    url_field = forms.URLField(min_length=10, max_length=100)
    combo_field = forms.ComboField(
        fields=[forms.CharField(
            max_length=20), forms.EmailField()])
    splitdatetime_field = forms.SplitDateTimeField(
        input_date_formats=['%d.%m.%Y'], input_time_formats=['%H:%M'])
示例#9
0
class AcquistoConOrdineForm(BaseOrdiniForm):
    url_tipo_ordini = 'acquisti:ajax_lista_tipo_ordini'
    url_lista_fornitori = 'acquisti:ajax_lista_fornitori'
    
    tipo = forms.ComboField(
        fields=[forms.CharField(), ], required=True, widget=JqxComboInput(
            jqxattrs={'height': 30, 'width': 300, 'minLength': 3, 'displayMember': 'descrizione', 'valueMember': "id",
                      'data_adapter_url': url_tipo_ordini},
            attrs={'style': 'float: left; margin-right: 5px;'}))
    
    fornitore = forms.ModelChoiceField(queryset=Fornitore.objects.all(), required=True, widget=JqxComboInput(
            jqxattrs={'height': 30, 'width': 300, 'minLength': 3, 'displayMember': 'azienda__ragione_sociale',
                      'valueMember': 'pk', 'data_adapter_url': url_lista_fornitori},
            attrs={'style': 'float: left; margin-right: 5px;'}))
    
    descrizione = forms.CharField(required=True,
                                  widget=JqxTextInput(jqxattrs={'height': 30, 'width': 500, 'minLength': 6}))
    
    class Meta:
        model = AcquistoConOrdine
        fields = ['numero_protocollo', 'data_ordine', 'stato', 'tipo', 'descrizione', 'fornitore',
                  'imponibile', 'aliquota_IVA', 'percentuale_IVA_indetraibile', 'note']
示例#10
0
class RubSberbankForm(forms.Form):
    # date
    date = forms.DateField(label=_('Date'), input_formats=('%d.%m.%Y',))
    # done
    bank_date = forms.DateField(label=_('Bank Date'), input_formats=('%d.%m.%Y',))
    # opid
    bank_ta_id = forms.CharField(label=_('Transaction ID'), max_length=20, required=False)
    # summ
    value_in_curr = forms.DecimalField(label=_('Value in currency'), max_digits=14, decimal_places=2)
    # curr
    currency = forms.ComboField(label=_('Currency'), fields=[forms.ChoiceField(
        choices=currencies.ISO_4217_CURRENCIES + ((643, 'RUR'),)), forms.IntegerField()], required=False)
    # total
    value = forms.DecimalField(label=_('Value in RUB currency'), max_digits=14, decimal_places=2)
    # text
    description = forms.CharField(label=_('Description'), max_length=200, required=False)

    def clean(self):
        cd = self.cleaned_data
        if cd.get('value_in_curr') == 0 and cd.get('value') != 0:
            cd['value_in_curr'] = cd.get('value')
        return cd
示例#11
0
class BaseOrdiniForm(forms.ModelForm):
    url_stato_spesa = 'acquisti:ajax_lista_stati_ordine'
    url_tipo_spesa = 'acquisti:ajax_lista_tipo_ordini'
    
    numero_protocollo = forms.CharField(required=False,
                                        widget=JqxTextInput(jqxattrs={'height': 30, 'width': 80, 'minLength': 6}))
    data_ordine = forms.DateField(required=True,
                                  widget=JqxDateInput(jqxattrs={'height': 30, 'width': '150'}))

    stato = forms.ComboField(
        fields=[forms.CharField(), ], required=True, widget=JqxComboInput(
            jqxattrs={'height': 30, 'width': 300, 'minLength': 5, 'displayMember': 'descrizione', 'valueMember': "id",
                      'data_adapter_url': url_stato_spesa},
            attrs={'style': 'float: left; margin-right: 5px;'}))

    """
    tipo = forms.ComboField(
        fields=[forms.CharField(), ], required=True, widget=JqxComboInput(
            jqxattrs={'height': 30, 'width': 300, 'minLength': 6, 'displayMember': 'descrizione', 'valueMember': "id",
                      'data_adapter_url': url_tipo_spesa},
            attrs={'style': 'float: left; margin-right: 5px;'}))
    """
    imponibile = forms.CharField(required=True,
                                 widget=JqxTextInput(jqxattrs={'height': 30, 'width': 200, 'minLength': 6}))

    aliquota_IVA = forms.CharField(required=True,
                                   widget=JqxTextInput(jqxattrs={'height': 30, 'width': 80, 'minLength': 6}))

    percentuale_IVA_indetraibile = \
        forms.CharField(required=True, widget=JqxTextInput(jqxattrs={'height': 30, 'width': 80, 'minLength': 6}))

    note = forms.CharField(required=False,
                           widget=JqxTextArea(jqxattrs={'height': 200, 'width': 500, 'minLength': 1}))

    class Meta:
        model = AcquistoConOrdine
        fields = ['numero_protocollo', 'data_ordine', 'stato', 'tipo', 'imponibile', 'aliquota_IVA',
                  'percentuale_IVA_indetraibile', 'note']
示例#12
0
class MultipleChoiceForm(forms.Form):
    name = forms.CharField(max_length=500)
    choice = forms.ChoiceField(choices=[(1, 'Mon'), (2, 'Tue')])
    choice_field = forms.ChoiceField(widget=forms.RadioSelect, choices=CHOICES)
    workdays = forms.MultipleChoiceField(choices=[
        (1, 'Mon'),
        (2, 'Tue'),
        (3, 'Wed'),
        (4, 'Thur'),
        (5, 'Fri'),
        (6, 'Sat'),
        (7, 'Sun'),
        (8, 'Mon'),
    ])
    typedchoice = forms.TypedChoiceField(choices=CHOICES, coerce=int)
    typed_multichoice = forms.TypedMultipleChoiceField(choices=CHOICES,
                                                       coerce=int)
    combo = forms.ComboField(
        fields=[forms.CharField(
            max_length=20), forms.EmailField()])
    boolfield = forms.TypedChoiceField(coerce=lambda x: x == 'True',
                                       choices=((False, 'False'), (True,
                                                                   'True')),
                                       widget=forms.RadioSelect)
    phonefield = PhoneField()
    birth_year = forms.DateField(widget=forms.SelectDateWidget(
        years=BIRTH_YEAR_CHOICES))
    initialed_birth_year = forms.DateField(widget=forms.SelectDateWidget(),
                                           initial=timezone.now())
    favorite_colors = forms.MultipleChoiceField(
        required=False,
        widget=forms.CheckboxSelectMultiple,
        choices=FAVORITE_COLORS_CHOICES,
    )
    name = forms.CharField(widget=forms.TextInput(attrs={'class': 'special'}))
    url = forms.URLField()
    comment = forms.CharField(widget=forms.TextInput(attrs={'size': '40'}))
    myAdminDateWidget = forms.DateField(widget=AdminDateWidget())
示例#13
0
文件: forms.py 项目: yulaymusin/aqsa
class TransactionPairTransfer(forms.Form):
    for_check_csv = forms.BooleanField(required=False)

    date = forms.DateField()
    date2 = forms.DateField()

    value1 = forms.DecimalField(max_digits=14, decimal_places=2)
    value2 = forms.DecimalField(max_digits=14, decimal_places=2)

    wallet1 = forms.CharField(max_length=50,
                              validators=[wte_v.two_or_more_spaces])
    wallet1_curr = forms.ComboField(fields=[
        forms.ChoiceField(choices=ISO_4217_CURRENCIES),
        forms.IntegerField()
    ])
    wallet2 = forms.CharField(max_length=50,
                              validators=[wte_v.two_or_more_spaces])
    wallet2_curr = forms.ComboField(fields=[
        forms.ChoiceField(choices=ISO_4217_CURRENCIES),
        forms.IntegerField()
    ])

    currency = forms.ComboField(fields=[
        forms.ChoiceField(choices=ISO_4217_CURRENCIES),
        forms.IntegerField()
    ])
    currency2 = forms.ComboField(fields=[
        forms.ChoiceField(choices=ISO_4217_CURRENCIES),
        forms.IntegerField()
    ])
    value_in_curr = forms.DecimalField(max_digits=14, decimal_places=2)
    value_in_curr2 = forms.DecimalField(max_digits=14, decimal_places=2)

    category = forms.CharField(max_length=50, required=False)
    category2 = forms.CharField(max_length=50, required=False)

    description1 = forms.CharField(max_length=200, required=False)
    description2 = forms.CharField(max_length=200, required=False)

    tag1 = forms.CharField(max_length=50, required=False)
    tag2 = forms.CharField(max_length=50, required=False)

    contact = forms.CharField(max_length=50, required=False)
    contact2 = forms.CharField(max_length=50, required=False)

    bank_date1 = forms.DateField(required=False)
    bank_date2 = forms.DateField(required=False)
    bank_ta_id1 = forms.CharField(max_length=20, required=False)
    bank_ta_id2 = forms.CharField(max_length=20, required=False)

    def clean(self):
        def value1_should_be_equal_to_value2(value, value2, err_in_field, msg):
            if ta_fx.is_nnt(value) and ta_fx.is_nnt(
                    value2) and value != value2:
                self.add_error(err_in_field, msg)

        cd = self.cleaned_data

        cd['wallet1'] = wte_m.Wallet(name=cd.get('wallet1'),
                                     currency=cd.get('wallet1_curr'))
        if cd.get('wallet1') != cd.get('wallet2'):
            cd['wallet2'] = wte_m.Wallet(name=cd.get('wallet2'),
                                         currency=cd.get('wallet2_curr'))
        else:
            cd['wallet2'] = cd['wallet1']

        if cd.get('for_check_csv'):
            # If date and date2 not the same.
            value1_should_be_equal_to_value2(
                cd.get('date'), cd.get('date2'), 'date2',
                _('Date should be the same in both transactions.'))

            # If currency and currency2 not the same.
            value1_should_be_equal_to_value2(
                cd.get('currency'), cd.get('currency2'), 'currency2',
                _('Currency should be the same in both transactions.'))

            # If value_in_curr + value_in_curr2 not equal to 0.
            if ta_fx.is_nnt(cd.get('value_in_curr')) and ta_fx.is_nnt(cd.get('value_in_curr2')) \
                    and cd.get('value_in_curr') + cd.get('value_in_curr2') != 0:
                msg = _(
                    'Sum of "Value_in_curr" both transactions should be equal to 0.'
                )
                self.add_error('value_in_curr2', msg)

            # If category and category2 not the same.
            value1_should_be_equal_to_value2(
                cd.get('category'), cd.get('category2'), 'category2',
                _('Category should be the same in both transactions.'))

            # If contact and contact2 not the same.
            value1_should_be_equal_to_value2(
                cd.get('contact'), cd.get('contact2'), 'contact2',
                _('Contact should be the same in both transactions.'))

            ta_fx.clean_for_pair_transfer_form(cd,
                                               self.add_error,
                                               with_auto_fill=False)

        return cd
class BuiltinForm(ConfigurableForm):
    '''Form to test the rendering of all built-in fields types'''
    boolean_field = forms.BooleanField()
    char_field = forms.CharField(min_length=3, max_length=5)
    choice_field = forms.ChoiceField(
        choices=[('1', 'tomato'), ('2', 'apple'), ('3', 'cherry')])
    typedchoice_field = forms.TypedChoiceField(choices=[(1, 'tomato'),
                                                        (2, 'apple'),
                                                        (3, 'cherry')],
                                               coerce=int,
                                               empty_value=None)
    date_field = forms.DateField()
    datetime_field = forms.DateTimeField()
    decimal_field = forms.DecimalField(min_value=0,
                                       max_value=99,
                                       max_digits=5,
                                       decimal_places=3)
    duration_field = forms.DurationField()
    email_field = forms.EmailField(min_length=5, max_length=50)
    file_field = forms.FileField(max_length=100)
    filepath_field = forms.FilePathField(path='/tmp')
    float_field = forms.FloatField()
    image_field = forms.ImageField()
    integer_field = forms.IntegerField(min_value=0, max_value=100)
    genericipaddress_field = forms.GenericIPAddressField()
    multiplechoice_field = forms.MultipleChoiceField(
        choices=[('1', 'tomato'), ('2', 'apple'), ('3', 'cherry')])
    typedmultiplechoice_field = forms.TypedMultipleChoiceField(
        choices=[(1, 'tomato'), (2, 'apple'), (3, 'cherry')],
        coerce=int,
        empty_value=None)
    nullboolean_field = forms.NullBooleanField()
    regex_field = forms.RegexField(regex=r'\w+')
    slug_field = forms.SlugField()
    time_field = forms.TimeField()
    url_field = forms.URLField(min_length=3, max_length=100)
    uuid_field = forms.UUIDField()
    combo_field = forms.ComboField(
        fields=[forms.CharField(
            max_length=20), forms.EmailField()])
    splitdatetime_field = forms.SplitDateTimeField()
    modelchoice_field = forms.ModelChoiceField(
        queryset=ContentType.objects.all())
    modelmultiplechoice_field = forms.ModelMultipleChoiceField(
        queryset=ContentType.objects.all())
    hidden = forms.CharField(widget=forms.HiddenInput)
    textarea = forms.CharField(widget=forms.Textarea)
    password = forms.CharField(widget=forms.PasswordInput)
    radio = forms.ChoiceField(choices=[('1', 'tomato'), ('2', 'apple'),
                                       ('3', 'cherry')],
                              widget=forms.RadioSelect)
    helptext = forms.CharField(help_text='Some help text')
    initial = forms.CharField(initial='Some initial value')
    label = forms.CharField(label='Some specific label')

    def get_initial(self):
        initial = super().get_initial()

        class FakeFile:
            url = 'http://www.test.com'

            def __str__(self):
                return self.url

        initial.update({
            'boolean_field':
            True,
            'char_field':
            'test',
            'choice_field':
            '2',
            'typedchoice_field':
            2,
            'date_field':
            date.today(),
            'datetime_field':
            datetime.now(),
            'decimal_field':
            0.1,
            'duration_field':
            timedelta(1),
            'email_field':
            '*****@*****.**',
            'file_field':
            FakeFile(),
            'filepath_field':
            '/tmp',
            'float_field':
            0.1,
            'image_field':
            FakeFile(),
            'integer_field':
            0,
            'genericipaddress_field':
            '127.0.0.1',
            'multiplechoice_field': ['1', '2'],
            'typedmultiplechoice_field': [1, 2],
            'nullboolean_field':
            False,
            'regex_field':
            'test',
            'slug_field':
            'test',
            'time_field':
            datetime.now().time(),
            'url_field':
            'http://127.0.0.1',
            'uuid_field':
            '12345678123456781234567812345678',
            'combo_field':
            '*****@*****.**',
            'splitdatetime_field':
            datetime.now(),
            'modelchoice_field':
            ContentType.objects.all()[2],
            'modelmultiplechoice_field':
            ContentType.objects.all()[:2],
            'hidden':
            'test',
            'textarea':
            'multiline\ntest',
            'password':
            '******',
            'radio':
            '3',
            'helptext':
            'test',
            'initial':
            'Some OTHER initial value',
            'label':
            'test',
        })

        return initial
示例#15
0
class FieldForm(forms.Form):
    name = forms.CharField(
        label='Enter Name',
        label_suffix=" : ",
        min_length=5,
        max_length=50,
        required=False,
        disabled=False,
        strip=True,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text="Name length should be 50 character.",
        error_messages={'required': "Please Enter your Name"})
    slug = forms.SlugField(
        label='Enter slug',
        label_suffix=" : ",
        required=False,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text=
        "Enter a valid slug consisting of letters, numbers, underscores or hyphens.",
        error_messages={'required': "Please Enter slug"},
        disabled=False)
    post_update = forms.DurationField(
        label='Enter post update duration',
        label_suffix=" : ",
        required=False,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text="Duration format should be(45:15:10)",
        error_messages={'required': "Please enter post update duration"},
        disabled=False)
    loopback = forms.GenericIPAddressField(
        label='Enter Loopback IP Address',
        label_suffix=" : ",
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text="Loopback IP Address format should be(100.10.0.1)",
        protocol='IPv4',
        unpack_ipv4=False,
        disabled=False,
        error_messages={'required': "Please enter Loopback IP Address"})
    regex = forms.RegexField(
        label='Enter Regex',
        label_suffix=" : ",
        min_length=5,
        max_length=10,
        regex=r'^[a-zA-Z0-9]+$',
        required=True,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text="Regex format should be[a-z, A-Z, 0-9]",
        disabled=False,
        error_messages={'required': "Please enter regex"})
    uuid = forms.UUIDField(
        label='Enter uuid',
        label_suffix=" : ",
        required=True,
        disabled=False,
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text="UUID format should be[123e4567-e89b-12d3-a456-426614174000]",
        error_messages={'required': "Please enter uuid"})

    combo_field = forms.ComboField(
        label='Enter Email Id',
        label_suffix=" : ",
        required=True,
        disabled=False,
        fields=[CharField(max_length=20),
                EmailField()],
        widget=forms.TextInput(attrs={'class': 'form-control'}),
        help_text="Pass valid email id with max length 20",
        error_messages={'required': "Please Email Id"})
示例#16
0
文件: forms.py 项目: yulaymusin/aqsa
class Transaction(forms.Form):
    for_check_csv = forms.BooleanField(required=False)

    id = forms.IntegerField(min_value=1, required=False)

    # "transfer" could be Boolean, but will be better, if user can use only "-" and "+" symbols
    transfer = forms.CharField(min_length=1,
                               max_length=1,
                               validators=[v.plus_minus_symbol])
    transfer_related = forms.IntegerField(min_value=1, required=False)

    date = forms.DateField()
    value = forms.DecimalField(max_digits=14, decimal_places=2)
    wallet = forms.CharField(max_length=50,
                             validators=[wte_v.two_or_more_spaces])
    wallet_curr = forms.ComboField(fields=[
        forms.ChoiceField(choices=ISO_4217_CURRENCIES),
        forms.IntegerField()
    ])
    category = forms.CharField(max_length=50, required=False)
    description = forms.CharField(max_length=200, required=False)
    tag = forms.CharField(max_length=50, required=False)

    currency = forms.ComboField(fields=[
        forms.ChoiceField(choices=ISO_4217_CURRENCIES),
        forms.IntegerField()
    ])
    value_in_curr = forms.DecimalField(max_digits=14, decimal_places=2)

    contact = forms.CharField(max_length=50, required=False)

    # "not_ignore" could be Boolean, but will be better, if user can use only "-" and "+" symbols
    not_ignore = forms.CharField(min_length=1,
                                 max_length=1,
                                 validators=[v.plus_minus_symbol])

    bank_date = forms.DateField(required=False)
    bank_ta_id = forms.CharField(max_length=20, required=False)

    def clean(self):
        cd = self.cleaned_data

        cd['transfer'] = True if cd.get('transfer') == '+' else False
        cd['wallet'] = wte_m.Wallet(name=cd.get('wallet'),
                                    currency=cd.get('wallet_curr'))
        cd['not_ignore'] = True if cd.get('not_ignore') == '+' else False

        if cd.get('for_check_csv'):
            # <If Income/expense (not transfer).
            # Check fields which not for income/expense.
            if not cd.get('transfer') and ta_fx.is_num(
                    cd.get('transfer_related')):
                msg = _(
                    'This field should be used only in money transfer transactions'
                )
                self.add_error('transfer_related', msg)

            if not cd.get('transfer'):
                ta_fx.clean_for_income_expense_form(cd,
                                                    self.add_error,
                                                    with_auto_fill=False)
            # </If Income/expense (not transfer).

            # <If transfer transaction.
            # If "value" bigger than 0, but not "id".
            if cd.get('transfer') and not cd.get('id') and ta_fx.is_num(cd.get('value')) \
                    and cd.get('value') > 0:
                msg = _(
                    'If "Value" is bigger than 0, then "id" should not be empty.'
                )
                self.add_error('id', msg)

            # If "value" bigger than 0, but "transfer_related".
            if cd.get('transfer') and cd.get('transfer_related') and ta_fx.is_num(cd.get('value')) \
                    and cd.get('value') > 0:
                msg = _(
                    'If "Value" is bigger than 0, then "transfer_related" should be empty.'
                )
                self.add_error('transfer_related', msg)

            # If "value" less than 0, but not "transfer_related".
            if cd.get('transfer') and not ta_fx.is_num(cd.get('transfer_related')) \
                    and ta_fx.is_num(cd.get('value')) and cd.get('value') < 0:
                msg = _(
                    'If "Value" is less than 0, then "transfer_related" should not be empty.'
                )
                self.add_error('transfer_related', msg)

            # not_ignore should be True
            if cd.get('transfer') and cd.get('not_ignore') is not True:
                msg = _(
                    'This field should be True in money transfer transactions.'
                )
                self.add_error('not_ignore', msg)
            # </If transfer transaction.

        return cd
示例#17
0
class ExampleForm(forms.Form):
    """Demonstration of all Django form fields / widgets"""

    boolean_required = forms.BooleanField(
        help_text="boolean required field’s help text")
    boolean_optional = forms.BooleanField(
        help_text="boolean optional field’s help text", required=False)
    boolean_disabled = forms.BooleanField(
        help_text="boolean disabled field’s help text", disabled=True)

    char_required = forms.CharField(
        help_text="char required field’s help text", required=True)
    char_optional = forms.CharField(
        help_text="char optional field’s help text", required=False)
    char_disabled = forms.CharField(
        help_text="char disabled field’s help text", disabled=True)

    password_required = forms.CharField(help_text="field’s help text",
                                        required=True,
                                        widget=forms.PasswordInput())
    password_optional = forms.CharField(help_text="field’s help text",
                                        required=False,
                                        widget=forms.PasswordInput())
    password_disabled = forms.CharField(help_text="field’s help text",
                                        disabled=True,
                                        widget=forms.PasswordInput())

    char_hidden = forms.CharField(widget=forms.HiddenInput())

    multiline_required = forms.CharField(
        widget=forms.Textarea(attrs={
            "rows": 10,
            "cols": 40
        }),
        help_text="field’s help text",
        required=True,
    )
    multiline_optional = forms.CharField(
        widget=forms.Textarea(attrs={
            "rows": 10,
            "cols": 40
        }),
        help_text="field’s help text",
        required=False,
    )
    multiline_disabled = forms.CharField(
        widget=forms.Textarea(attrs={
            "rows": 10,
            "cols": 40
        }),
        help_text="field’s help text",
        required=False,
    )

    choices = (("one", "One"), ("two", "Two"), ("three", "Three"), ("four",
                                                                    "Four"))

    choice_required = forms.ChoiceField(help_text="field’s help text",
                                        choices=choices,
                                        required=True)
    choice_optional = forms.ChoiceField(help_text="field’s help text",
                                        choices=choices,
                                        required=False)
    choice_disabled = forms.ChoiceField(help_text="field’s help text",
                                        choices=choices,
                                        disabled=True)

    radio_choice_required = forms.ChoiceField(help_text="field’s help text",
                                              choices=choices,
                                              required=True,
                                              widget=forms.RadioSelect())
    radio_choice_optional = forms.ChoiceField(help_text="field’s help text",
                                              choices=choices,
                                              required=False,
                                              widget=forms.RadioSelect())
    radio_choice_disabled = forms.ChoiceField(help_text="field’s help text",
                                              choices=choices,
                                              disabled=True,
                                              widget=forms.RadioSelect())

    date_required = forms.DateField(
        help_text="date required field’s help text", required=True)
    date_optional = forms.DateField(
        help_text="date optional field’s help text", required=False)
    date_disabled = forms.DateField(
        help_text="date disabled field’s help text", disabled=True)

    datetime_required = forms.DateTimeField(
        help_text="datetime required field’s help text", required=True)
    datetime_optional = forms.DateTimeField(
        help_text="datetime optional field’s help text", required=False)
    datetime_disabled = forms.DateTimeField(
        help_text="datetime disabled field’s help text", disabled=True)

    decimal_required = forms.DecimalField(
        help_text="decimal required field’s help text", required=True)
    decimal_optional = forms.DecimalField(
        help_text="decimal optional field’s help text", required=False)
    decimal_disabled = forms.DecimalField(
        help_text="decimal disabled field’s help text", disabled=True)

    duration_required = forms.DurationField(
        help_text="duration required field’s help text", required=True)
    duration_optional = forms.DurationField(
        help_text="duration optional field’s help text", required=False)
    duration_disabled = forms.DurationField(
        help_text="duration disabled field’s help text", disabled=True)

    email_required = forms.EmailField(
        help_text="email required field’s help text", required=True)
    email_optional = forms.EmailField(
        help_text="email optional field’s help text", required=False)
    email_disabled = forms.EmailField(
        help_text="email disabled field’s help text", disabled=True)

    file_required = forms.FileField(
        help_text="file required field’s help text", required=True)
    file_optional = forms.FileField(
        help_text="file optional field’s help text", required=False)
    file_disabled = forms.FileField(
        help_text="file disabled field’s help text", disabled=True)

    # FilePathField

    float_required = forms.FloatField(
        help_text="float required field’s help text", required=True)
    float_optional = forms.FloatField(
        help_text="float optional field’s help text", required=False)
    float_disabled = forms.FloatField(
        help_text="float disabled field’s help text", disabled=True)

    image_required = forms.ImageField(
        help_text="image required field’s help text", required=True)
    image_optional = forms.ImageField(
        help_text="image optional field’s help text", required=False)
    image_disabled = forms.ImageField(
        help_text="image disabled field’s help text", disabled=True)

    integer_required = forms.IntegerField(
        help_text="integer required field’s help text", required=True)
    integer_optional = forms.IntegerField(
        help_text="integer optional field’s help text", required=False)
    integer_disabled = forms.IntegerField(
        help_text="integer disabled field’s help text", disabled=True)

    json_required = forms.JSONField(
        label="JSON required",
        help_text="json required field’s help text",
        required=True)
    json_optional = forms.JSONField(
        label="JSON optional",
        help_text="json optional field’s help text",
        required=False)
    json_disabled = forms.JSONField(
        label="JSON disabled",
        help_text="json disabled field’s help text",
        disabled=True)

    generic_ip_address_required = forms.GenericIPAddressField(
        help_text="generic ip address required field’s help text",
        required=True)
    generic_ip_address_optional = forms.GenericIPAddressField(
        help_text="generic ip address optional field’s help text",
        required=False)
    generic_ip_address_disabled = forms.GenericIPAddressField(
        help_text="generic ip address disabled field’s help text",
        disabled=True)

    select_multiple = forms.MultipleChoiceField(choices=choices)
    checkboxes_multiple = forms.MultipleChoiceField(
        choices=choices, widget=forms.CheckboxSelectMultiple())

    # TypedMultipleChoiceField

    null_boolean_required = forms.NullBooleanField(
        help_text="null boolean required field’s help text")
    null_boolean_optional = forms.NullBooleanField(
        help_text="null boolean optional field’s help text", required=False)
    null_boolean_disabled = forms.NullBooleanField(
        help_text="null boolean disabled field’s help text", disabled=True)

    # SlugField

    regex_required = forms.RegexField(
        regex="\w",
        help_text="regex required field’s help text",
        required=True)
    regex_optional = forms.RegexField(
        regex="\w",
        help_text="regex optional field’s help text",
        required=False)
    regex_disabled = forms.RegexField(
        regex="\w",
        help_text="regex disabled field’s help text",
        disabled=True)

    slug_required = forms.SlugField(
        help_text="slug required field’s help text", required=True)
    slug_optional = forms.SlugField(
        help_text="slug optional field’s help text", required=False)
    slug_disabled = forms.SlugField(
        help_text="slug disabled field’s help text", disabled=True)

    time_required = forms.TimeField(
        help_text="time required field’s help text", required=True)
    time_optional = forms.TimeField(
        help_text="time optional field’s help text", required=False)
    time_disabled = forms.TimeField(
        help_text="time disabled field’s help text", disabled=True)

    url_required = forms.URLField(label="URL required",
                                  help_text="url required field’s help text",
                                  required=True)
    url_optional = forms.URLField(label="URL optional",
                                  help_text="url optional field’s help text",
                                  required=False)
    url_disabled = forms.URLField(label="URL disabled",
                                  help_text="url disabled field’s help text",
                                  disabled=True)

    uuid_required = forms.UUIDField(
        label="UUID required",
        help_text="uuid required field’s help text",
        required=True)
    uuid_optional = forms.UUIDField(
        label="UUID optional",
        help_text="uuid optional field’s help text",
        required=False)
    uuid_disabled = forms.UUIDField(
        label="UUID disabled",
        help_text="uuid disabled field’s help text",
        disabled=True)

    combo_required = forms.ComboField(
        fields=[forms.CharField(max_length=20),
                forms.EmailField()],
        help_text="combo required field’s help text",
        required=True)
    combo_optional = forms.ComboField(
        fields=[forms.CharField(max_length=20),
                forms.EmailField()],
        help_text="combo optional field’s help text",
        required=False)
    combo_disabled = forms.ComboField(
        fields=[forms.CharField(max_length=20),
                forms.EmailField()],
        help_text="combo disabled field’s help text",
        disabled=True)
示例#18
0
class UsualForm(forms.Form):
    """по умолчанию эти две настройки (почти) нормально работают только в .as_table()
    но если форму вывожу в шаблон поэлементно - то в нужном месте можно вставить
    item.css_classes и тогда в этом месте будут классы в соответсвии с этими настройками"""
    error_css_class = "error123"  # работает в контейнере
    required_css_class = "field123"  # работает в элементе

    booleanfield = forms.BooleanField(required=False, label="BooleanField")
    charfield = forms.CharField(
        max_length=5,
        label="CharField",
        required=True,
        widget=forms.TextInput(attrs={'class': 'anna'}))

    YEAR_IN_SCHOOL_CHOICES = [
        ('FR', 'Freshman'),
        ('SO', 'Sophomore'),
        ('JR', 'Junior'),
        ('SR', 'Senior'),
        ('GR', 'Graduate'),
    ]
    choicefield = forms.ChoiceField(choices=YEAR_IN_SCHOOL_CHOICES,
                                    label="ChoiceField")

    typedchoicefield = forms.TypedChoiceField(choices=YEAR_IN_SCHOOL_CHOICES,
                                              coerce=str,
                                              label="TypedChoiceField")
    datefield = forms.DateField(initial=timezone.now, label="DateField")
    datetimefield = forms.DateTimeField(initial=timezone.now,
                                        label="DateTimeField")
    decimalfield = forms.DecimalField(
        required=True,
        max_digits=4,
        decimal_places=2,
        label='DecimalField',
        error_messages={'max_digits': 'Слишком много цифр!'})
    durationfield = forms.DurationField(required=False, label="")
    emailfield = forms.EmailField(required=False, label="DurationField")
    # filefield = forms.FileField(label="FileField")
    # filepathfield = forms.FilePathField(label="FilePathField")
    floatfield = forms.FloatField(required=False, label="FloatField")
    # imagefield = forms.ImageField(label="ImageField")
    integerfield = forms.IntegerField(required=False, label="IntegerField")
    genericipaddresfield = forms.GenericIPAddressField(
        required=False, label="GenericIPAddressField")
    multiplechoicefield = forms.MultipleChoiceField(
        choices=YEAR_IN_SCHOOL_CHOICES,
        required=False,
        label="MultipleChoiceField")
    typedmultiplechoicefield = forms.TypedMultipleChoiceField(
        choices=YEAR_IN_SCHOOL_CHOICES,
        required=False,
        coerce=str,
        label="TypedMultipleChoiceField")
    nullbooleanfield = forms.NullBooleanField(label="NullBooleanField")
    # regexfield = forms.RegexField(label="RegexField")
    slugfield = forms.SlugField(required=False,
                                allow_unicode=True,
                                label="SlugField")
    timefield = forms.TimeField(initial=timezone.now, label="TimeField")
    urlfield = forms.URLField(required=False, label="URLField")
    uuidfield = forms.UUIDField(required=False, label="UUIDField")

    # Достаточно сложные встроенные классы Field
    combofield = forms.ComboField(
        help_text='валидируется по нескольким полям',
        required=False,
        label="ComboField",
        fields=[forms.CharField(max_length=10),
                forms.EmailField()])
    # multivaluefield = forms.MultiValueField(label="MultiValueField")

    splitdatetimefield = forms.SplitDateTimeField(initial=timezone.now,
                                                  label="SplitDateTimeField")
示例#19
0
class NewCollaboratoreForm(forms.ModelForm):
    url_telefoni = 'collaboratori:ajax_lista_tipo_telefoni_persona'
    url_mail = 'collaboratori:ajax_lista_tipo_mail_persona'

    tel1 = forms.CharField(required=False,
                           widget=JqxTextInput(jqxattrs={
                               'height': 30,
                               'width': 150,
                               'minLength': 1
                           }))
    tel2 = forms.CharField(required=False,
                           widget=JqxTextInput(jqxattrs={
                               'height': 30,
                               'width': 150,
                               'minLength': 1
                           }))
    tel3 = forms.CharField(required=False,
                           widget=JqxTextInput(jqxattrs={
                               'height': 30,
                               'width': 150,
                               'minLength': 1
                           }))
    tel4 = forms.CharField(required=False,
                           widget=JqxTextInput(jqxattrs={
                               'height': 30,
                               'width': 150,
                               'minLength': 1
                           }))

    doc_tel1 = forms.ComboField(
        fields=[
            forms.CharField(),
        ],
        required=False,
        widget=JqxComboInput(
            jqxattrs={
                'height': 30,
                'width': 150,
                'minLength': 1,
                'displayMember': 'descrizione_telefono',
                'valueMember': "descrizione_telefono",
                'data_adapter_url': url_telefoni
            },
            attrs={'style': 'float: left; margin-right: 5px;'}))

    doc_tel2 = forms.ComboField(
        fields=[
            forms.CharField(),
        ],
        required=False,
        widget=JqxComboInput(
            jqxattrs={
                'height': 30,
                'width': 150,
                'minLength': 1,
                'displayMember': 'descrizione_telefono',
                'valueMember': "descrizione_telefono",
                'data_adapter_url': url_telefoni
            },
            attrs={'style': 'float: left; margin-right: 5px;'}))

    doc_tel3 = forms.ComboField(
        fields=[
            forms.CharField(),
        ],
        required=False,
        widget=JqxComboInput(
            jqxattrs={
                'height': 30,
                'width': 150,
                'minLength': 1,
                'displayMember': 'descrizione_telefono',
                'valueMember': "descrizione_telefono",
                'data_adapter_url': url_telefoni
            },
            attrs={'style': 'float: left; margin-right: 5px;'}))

    doc_tel4 = forms.ComboField(
        fields=[
            forms.CharField(),
        ],
        required=False,
        widget=JqxComboInput(
            jqxattrs={
                'height': 30,
                'width': 150,
                'minLength': 1,
                'displayMember': 'descrizione_telefono',
                'valueMember': "descrizione_telefono",
                'data_adapter_url': url_telefoni
            },
            attrs={'style': 'float: left; margin-right: 5px;'}))

    mail1 = forms.CharField(required=False,
                            widget=JqxTextInput(jqxattrs={
                                'height': 30,
                                'width': 150,
                                'minLength': 1
                            }))
    mail2 = forms.CharField(required=False,
                            widget=JqxTextInput(jqxattrs={
                                'height': 30,
                                'width': 150,
                                'minLength': 1
                            }))

    doc_mail1 = forms.ComboField(
        fields=[
            forms.CharField(),
        ],
        required=False,
        widget=JqxComboInput(
            jqxattrs={
                'height': 30,
                'width': 150,
                'minLength': 1,
                'displayMember': 'descrizione_mail',
                'valueMember': "descrizione_mail",
                'data_adapter_url': url_mail
            },
            attrs={'style': 'float: left; margin-right: 5px;'}))

    doc_mail2 = forms.ComboField(
        fields=[
            forms.CharField(),
        ],
        required=False,
        widget=JqxComboInput(
            jqxattrs={
                'height': 30,
                'width': 150,
                'minLength': 1,
                'displayMember': 'descrizione_mail',
                'valueMember': "descrizione_mail",
                'data_adapter_url': url_mail
            },
            attrs={'style': 'float: left; margin-right: 5px;'}))

    note = forms.CharField(required=False,
                           widget=JqxTextArea(jqxattrs={
                               'height': 200,
                               'width': 500,
                               'minLength': 1
                           }))

    class Meta:
        model = Collaboratore
        fields = [
            'persona', 'tel1', 'tel2', 'tel3', 'tel4', 'doc_tel1', 'doc_tel2',
            'doc_tel3', 'doc_tel4', 'mail1', 'mail2', 'doc_mail1', 'doc_mail2',
            'note'
        ]
        widgets = {'persona': forms.HiddenInput()}