class RegistrationForm(Html5Form):
    """
    Form for registering a new user account.

    Validates that the email is not already registered, and
    requires the password to be entered twice to catch typos.

    Subclasses should feel free to add any additional validation they
    need, but should avoid defining a ``save()`` method -- the actual
    saving of collected user data is delegated to the active
    registration backend.

    """
    first_name = forms.CharField(label=_('First Name'),
                                 max_length=50,
                                 required=False)
    last_name = forms.CharField(label=_('Last Name'),
                                max_length=100,
                                required=False)
    email = forms.EmailField(label=_("Email Address"),
                             max_length=75,
                             required=True)

    password = forms.CharField(label=_("Password"),
                               widget=forms.PasswordInput,
                               min_length=6,
                               max_length=50)
    password2 = forms.CharField(label=_("Password (again)"),
                                widget=forms.PasswordInput,
                                min_length=6,
                                max_length=50)

    cpf = br_forms.BRCPFField(required=False, label=_("CPF"))
    tos = forms.BooleanField(
        label=_(u'I have read and agree to the Terms of Service'),
        required=True,
        error_messages={
            'required':
            _(u"Você precisa ler e concordar com os termos de serviço")
        })

    def clean(self):
        """
        Verifiy that the values entered into the two password fields
        match. Note that an error here will end up in
        ``non_field_errors()`` because it doesn't apply to a single
        field.

        """
        if 'password' in self.cleaned_data and 'password2' in self.cleaned_data:
            if self.cleaned_data['password'] != self.cleaned_data['password2']:
                raise forms.ValidationError(
                    _(u"As senhas informadas são diferentes."))
        return self.cleaned_data
Beispiel #2
0
class VisitorAdminForm(forms.ModelForm):
	if LANGUAGE_CODE in ('pt_BR','pt-br'):
		from django.contrib.localflavor.br import forms as br_forms
		from real_estate_app.localflavor.br.widgets import CPFInputWidget, RGInputWidget,\
														   CNPJInputWidget
		cpf = br_forms.BRCPFField(
			label='CPF',
			widget=CPFInputWidget,
		)

		rg = forms.CharField(
			label='RG',
			widget=RGInputWidget,
		)

		zip = br_forms.BRZipCodeField(
			label='CEP',
			widget=ZipInputWidget

		)

		work_zip = br_forms.BRZipCodeField(
			label='CEP Trabalho',
			widget=ZipInputWidget,
		)

		work_phone = br_forms.BRPhoneNumberField(
			label='Telefone trabalho',
			widget=PhoneInputWidget
		)
		celphone = br_forms.BRPhoneNumberField(
			label='Celular',
			widget=CelphoneInputWidget
		)

		phone = br_forms.BRPhoneNumberField(
			label='Telefone',
			widget=PhoneInputWidget
		)


	class Meta:
		model = Visitor
Beispiel #3
0
class RealtorAdminForm(ModelForm):
	if LANGUAGE_CODE in ('pt_BR','pt-br'):
		from django.contrib.localflavor.br import forms as br_forms
		from real_estate_app.localflavor.br.widgets import CPFInputWidget, RGInputWidget,\
														   CNPJInputWidget

		cpf = br_forms.BRCPFField(
							label=u'CPF',
							widget=CPFInputWidget,
							required=False
		)

		cnpj = br_forms.BRCNPJField(
							label=u'CNPJ',
							widget=CNPJInputWidget,
							required=False
		)

		phone = br_forms.BRPhoneNumberField(
							label=_('Phone'),
							widget=PhoneInputWidget,
							required=False
		)

		celphone = br_forms.BRPhoneNumberField(
							label=_('Celphone'),
							widget=CelphoneInputWidget,
							required=False
		)

		rg = CharField(
							label='RG',
							widget=RGInputWidget,
							required=False
		)



	class Meta:
		model = Realtor
class IdentityInformationForm(Html5Form):
    """
    Form for updating user's data. All fields compulsory. Email and password
    not changeable here.
    """
    first_name = forms.CharField(max_length=50,
                                 widget=forms.TextInput(),
                                 required=False,
                                 label=_("Nome"))
    last_name = forms.CharField(max_length=100,
                                widget=forms.TextInput(),
                                required=False,
                                label=_("Sobrenome"))
    send_myfreecomm_news = forms.BooleanField(
        label=_(u"Quero receber novidades e promoções do Passaporte Web"),
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-checkbox-input'}),
    )
    send_partner_news = forms.BooleanField(
        label=_(u"Quero receber novidades e promoções de parceiros"),
        required=False,
        widget=forms.CheckboxInput(attrs={'class': 'form-checkbox-input'}),
    )
    cpf = br_forms.BRCPFField(required=False, label=_("CPF"))
Beispiel #5
0
class PessoaForm(ModelForm):
    class Meta:
        exclude = [
            'created_at', 'updated_at', 'enderecos', 'telefones', 'emails',
            'contatos'
        ]

    inlines = [
        EnderecoModelFormSet, TelefoneModelFormSet, EmailModelFormSet,
        ContatoModelFormSet
    ]

    id = forms.IntegerField(required=False, widget=widgets.HiddenInput())
    cnpj = br_forms.BRCNPJField(required=False,
                                widget=MaskCNPJ(),
                                label='CNPJ')
    cpf = br_forms.BRCPFField(required=False, widget=MaskCPF(), label='CPF')
    rg = forms.IntegerField(required=False,
                            widget=Mask('999999999999999999999999999'),
                            label='RG')
    orgao_emissor = forms.CharField(required=False,
                                    label=u'Órgão Emissor',
                                    widget=Mask('aaaaaaaaaaaaaaa'))
    razao_social = forms.CharField(required=False, label=u'Razão Social')

    def __init__(self, *args, **kwargs):
        super(PessoaForm, self).__init__(*args, **kwargs)
        if self.fields.has_key('orgao_emissor'):
            self.fields['orgao_emissor'].widget = Mask('aaaaaaaaaaaaaaa')

    def _get_media(self):
        media = Media()
        for field in self.fields.values():
            media = media + field.widget.media
        for formset in self.inlines:
            media = media + formset(
                queryset=formset.model.objects.none()).media
        return media

    media = property(_get_media)

    def get_formsets(self, POST=None, obj_pessoa=None):
        formsets = []

        if POST:
            for index, formset in enumerate(self.inlines):
                if obj_pessoa:
                    formsets.append(
                        formset(POST,
                                queryset=formset.model.objects.filter(
                                    pessoa=obj_pessoa),
                                prefix='fs%s' % index))
                else:
                    formsets.append(
                        formset(POST,
                                queryset=formset.model.objects.none(),
                                prefix='fs%s' % index))
        else:
            for index, formset in enumerate(self.inlines):
                if obj_pessoa:
                    formsets.append(
                        formset(queryset=formset.model.objects.filter(
                            pessoa=obj_pessoa),
                                prefix='fs%s' % index))
                else:
                    formsets.append(
                        formset(queryset=formset.model.objects.none(),
                                prefix='fs%s' % index))
        return formsets

    def save_formsets(self, formsets, obj_pessoa):
        for index, formset in enumerate(formsets):
            for object in formset.save():
                if index == 0:
                    obj_pessoa.enderecos.add(object)
                if index == 1:
                    obj_pessoa.telefones.add(object)
                if index == 2:
                    obj_pessoa.emails.add(object)
                if index == 3:
                    obj_pessoa.contatos.add(object)
        # return self.get_formsets(obj_pessoa=obj_pessoa)

    def valid_formsets(self, formsets):
        form_is_valid = True
        for formset in formsets:
            form_is_valid = form_is_valid and formset.is_valid()
        return form_is_valid