Beispiel #1
0
 def __init__(self, *args, **kwargs):
     super(BaseCadastroPessoaForm, self).__init__(*args, **kwargs)
     self.fields['estado'] = BRStateChoiceField(initial="PR")
     self.fields['cpf'] = BRCPFField(required=False, label=_(u"CPF"))
     self.fields['cep'] = BRZipCodeField(required=False)
     self.fields['telefone'] = BRPhoneNumberField(required=False)
     self.fields['celular'] = BRPhoneNumberField(required=False)
Beispiel #2
0
class TokensForm(ModelForm):
    cpf = BRCPFField(required=False, max_length=14, min_length=11)
    cnpj = BRCNPJField(required=False, min_length=16)
    cep = BRZipCodeField()

    class Meta:
        model = Headhunter
        fields = '__all__'
        labels = {
            'address': 'Endereço',
            'address2': '',
        }

    def __init__(self, *args, **kwargs):
        super(TokensForm, self).__init__(*args, **kwargs)

        # add custom error messages
        self.fields['cnpj'].error_messages.update({
            'invalid':
            'CNPJ inválido',
            'max_digits':
            'CNPJ requer pelo menos 14 dígitos',
        })

        self.fields['cpf'].error_messages.update({
            'invalid':
            'CPF inválido',
            'max_digits':
            'CPF requer pelo menos 11 dígitos ou 14 caracteres',
        })
Beispiel #3
0
class EnderecoForm(forms.ModelForm):
    cep = BRZipCodeField(
        required=True,
        widget=forms.TextInput(attrs={'placeholder': '______-___'}))

    class Meta:
        model = Endereco
        fields = ['endereco', 'cep']
Beispiel #4
0
class ClientForm(forms.ModelForm):
    class Meta:
        model = Client
        form = Client
        widgets = {'state': BRStateSelect(), 'country': CountrySelectWidget()}
        fields = ['name', 'cpf', 'phone', 'cep', 'cnpj', 'state']

    cpf = BRCPFField()
    cep = BRZipCodeField(required=True)
    cnpj = BRCNPJField(label='CNPJ', required=False)
    phone = BRPhoneNumberField(label='Telefone')
Beispiel #5
0
 def __init__(self, *args, **kwargs):
     super(AgenciaForm, self).__init__(*args, **kwargs)
     self.fields['cidade'].widget.attrs[
         'class'] = 'input-small campo-cidade'
     self.fields['estado'] = BRStateChoiceField(initial="PR")
     self.fields['estado'].widget.attrs[
         'class'] = 'input-small campo-estado'
     self.fields['cep'] = BRZipCodeField(required=False)
     self.fields['cep'].widget.attrs['class'] = 'input-mini campo-cep'
     self.fields['contato'] = BRPhoneNumberField(required=False)
     self.fields['contato'].widget.attrs[
         'class'] = 'input-small campo-contato'
Beispiel #6
0
class CasaLegislativaForm(forms.ModelForm):
    # cnpj = BRCNPJField(
    #    label=_(u'CNPJ'),
    #    required=False,
    #    help_text=_(u'Utilize o formato <em>XX.XXX.XXX/XXXX-XX</em> ou insira apenas os dígitos.')
    #)
    cep = BRZipCodeField(label=_(u'CEP'),
                         help_text=_(u'Formato') + ': <em>XXXXX-XXX</em>.')

    class Meta:
        model = CasaLegislativa
        fields = '__all__'
Beispiel #7
0
class EnderecoEntregaForm(forms.ModelForm):
    class Meta:
        model = Pedido
        fields = ('endereco_entrega', 'complemento_entrega', 'cep_entrega',
                  'cidade_entrega', 'uf_entrega')

    endereco_entrega = forms.CharField(
        error_messages={'required': 'Campo obrigatório'},
        widget=forms.TextInput(attrs={
            'class': 'form-control form-control-sm',
            'maxlength': '50'
        }),
        required=True)

    complemento_entrega = forms.CharField(
        error_messages={'required': 'Campo obrigatório'},
        widget=forms.TextInput(attrs={
            'class': 'form-control form-control-sm',
            'maxlength': '10'
        }),
        required=True)

    cep_entrega = BRZipCodeField(
        error_messages={'required': 'Campo obrigatório'},
        widget=forms.TextInput(
            attrs={
                'class': 'form-control form-control-sm',
                "onblur": "pesquisacep(this.value);"
            }),
        required=True,
        max_length=9)

    cidade_entrega = forms.CharField(
        error_messages={'required': 'Campo obrigatório'},
        widget=forms.TextInput(attrs={
            'class': 'form-control form-control-sm',
            'maxlength': '15'
        }),
        required=True)

    uf_entrega = forms.ChoiceField(
        error_messages={'required': 'Campo obrigatório'},
        widget=forms.Select(attrs={'class': 'form-control form-control-sm'}),
        required=True,
        choices=UF_CHOICES)
Beispiel #8
0
class EnderecoForm(forms.ModelForm):
    cep = BRZipCodeField(label='CEP')

    class Meta:
        model = Endereco
        fields = ('logradouro','numero','complemento', 'bairro', 'cep', 'estado','cidade')

    def __init__(self, *args, **kwargs):
        super(EnderecoForm, self).__init__(*args, **kwargs)
        self.fields['cep'].widget.attrs['class'] = 'form-control cep'
        self.fields['cidade'].queryset = Cidade.objects.none()

        if 'estado' in self.data:
            try:
                estado_id = int(self.data.get('estado'))
                print('Estado: '+str(estado_id))
                self.fields['cidade'].queryset = Cidade.objects.filter(estado_id=estado_id).order_by('nome')
            except (ValueError, TypeError):
                pass

        elif self.instance.pk:
            self.fields['cidade'].queryset = self.instance.estado.cidade_set.order_by('nome')
class AddressForm(forms.ModelForm):
    u"""
    Class of model form Adress
    """

    zip_code = BRZipCodeField(
        label=_(u'Zip Code'),
        help_text=_(u'Enter a zip code in the format XXXXX-XXX.'),
        max_length=9,
        required=True)

    class Meta:
        u"""
        Define attributes of this forms
        """

        model = Address
        u"""
        Define model used
        """

        exclude = ['created', 'modified']
        u"""
Beispiel #10
0
class AddressForm(forms.Form):
    zip_code = BRZipCodeField(label='CEP', max_length=9)
    street = forms.CharField(label='Rua', max_length=100)
    district = forms.CharField(label='Bairro', max_length=100)
    city = forms.CharField(label='Cidade', max_length=100)
    state = forms.CharField(label='Estado', max_length=100)
Beispiel #11
0
 def __init__(self, *args, **kwargs):
     super(EnderecoEntregaClienteForm, self).__init__(*args, **kwargs)
     self.fields['estado'] = BRStateChoiceField(initial="PR")
     self.fields['estado'].widget.attrs['class'] = 'campo-estado'
     self.fields['cpf'] = BRCPFField(required=False, label=_(u"CPF"))
     self.fields['cep'] = BRZipCodeField(required=False)
Beispiel #12
0
class FormNeighborhood(forms.ModelForm):
    cep = BRZipCodeField(label='CEP')

    class Meta:
        model = Neighborhood
        fields = '__all__'
Beispiel #13
0
class PessoaJuridicaSignUpForm(SignupForm):
    nome = forms.CharField(
        label='Nome Completo',
        required=True,
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Digite seu nome completo'}
        )
    )

    cnpj = BRCNPJField(
        label='CNPJ',
        required=True,
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Digite o CNPJ'}
        )

    )

    endereco = forms.CharField(
        label='Endereço',
        required=True,
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Digite seu endereço'}
        )
    )

    bairro = forms.CharField(
        label='Bairro',
        required=True,
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Digite seu bairro'}
        )
    )

    estado = forms.ModelChoiceField(
        queryset=Estado.objects.all(),
        required=True,
        widget=forms.Select(
            attrs={'class': 'selectpicker', 'data-style': "select-with-transition"}
        )
    )

    cidade = forms.ModelChoiceField(
        queryset=Cidade.objects.all(),
        required=True,
        widget=forms.Select(
            attrs={'class': 'selectpicker', 'data-style': "select-with-transition"}
        )
    )

    cep = BRZipCodeField(
        label='CEP',
        required=True,
        max_length=9,
        widget=forms.TextInput(
            attrs={'class': 'form-control', 'placeholder': 'Digite seu CEP'}
        )
    )

    profile_pic = forms.ImageField(
        label='Foto',
        required=False,
        widget=forms.FileInput(
            attrs={'class': 'fileinput'}
        )
    )

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # self.fields['username'].widget.attrs.update({'class': 'form-control', 'placeholder': 'Username'})
        self.fields['email'].widget.attrs.update({'class': 'form-control', 'placeholder': 'Email'})
        self.fields['password1'].widget.attrs.update({'class': 'form-control', 'placeholder': 'Password'})
        self.fields['password2'].widget.attrs.update({'class': 'form-control', 'placeholder': 'Password'})
        field_order = ['email', 'password1', 'password2', ]
        set_form_field_order(self, field_order)

    # Override the save method to save the extra fields
    # (otherwise the form will save the User instance only)
    @transaction.atomic
    def save(self, request):
        # Save the User instance and get a reference to it
        self.cleaned_data['is_pj'] = True
        user = super().save(request)
        # Create an instance of your model with the extra fields
        # then save it.
        # (N.B: the are already cleaned, but if you want to do some
        # extra cleaning just override the clean method as usual)
        pessoa_juridica = PessoaJuridica(
            user=user,
            cnpj=self.cleaned_data.get('cnpj'),
            nome=self.cleaned_data.get('nome'),
            endereco=self.cleaned_data.get('endereco'),
            bairro=self.cleaned_data.get('bairro'),
            estado=self.cleaned_data.get('estado'),
            cidade=self.cleaned_data.get('cidade'),
            cep=self.cleaned_data.get('cep'),
            profile_pic=self.cleaned_data.get('profile_pic'),
        )
        pessoa_juridica.save()

        # Remember to return the User instance (not your custom user,
        # the Django one), otherwise you will get an error when the
        # complete_signup method will try to look at it.
        return pessoa_juridica.user
class OrderCreateForm(forms.ModelForm):
    postal_code = BRZipCodeField()

    class Meta:
        model = Order
        fields = ['first_name', 'last_name', 'email', 'address', 'postal_code', 'city']