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)
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'
class ProfileCreateForm(forms.ModelForm): state = BRStateChoiceField(label='Estado') date_of_birth = forms.DateField( label='Data de nascimento', widget=forms.widgets.DateInput(attrs={'type': 'date'}), ) class Meta: model = Profile fields = ('full_name', 'date_of_birth', 'state', 'city') labels = { 'full_name': 'Nome completo', 'city': 'Cidade', }
class AddressForm(ModelForm): postal_code = CharField(label="CEP") country = BRStateChoiceField(label="Estado", disabled=True) city = CharField(label="Cidade", widget=Textarea(attrs={ 'rows': 1, 'style': 'resize:none;', 'disabled': True })) street = CharField(label="Rua") district = CharField(label="Complemento/Bairro") class Meta: model = Address fields = '__all__' labels = {'number': 'Número'}
class CustomUserCreationForm(UserCreationForm): error_messages = { 'password_mismatch': 'As senhas não coincidem', } state = BRStateChoiceField(required=True) phone = forms.CharField(required=False) class Meta: model = get_user_model() fields = ('email', 'username', 'first_name', 'last_name', 'state', 'phone') labels = { 'username': '******', 'first_name': 'Nome', 'last_name': 'Sobrenome', } def __init__(self, *args, **kwargs): super(CustomUserCreationForm, self).__init__(*args, **kwargs) # Custom fields labels self.fields['phone'].label = 'Telefone/Celular' self.fields['state'].label = 'Estado' # Error messages self.fields['username'].error_messages.update({ 'unique': 'Esse usuário já existe', }) self.fields['email'].error_messages.update({ 'unique': 'E-mail já cadastrado', }) self.fields['phone'].error_messages.update({ 'unique': 'Número de telefone já cadastrado', }) def save(self, commit=False): user = super().save(commit=False) user.state = self.cleaned_data['state'] user.phone = self.cleaned_data['phone'] if commit: user.save() return user
class UserRegister(UserCreationForm): def __init__(self, *args, **kwargs): super(UserRegister, self).__init__(*args, **kwargs) estado = BRStateChoiceField() cidade = forms.CharField(label='Cidade') sexo = forms.CharField(label='Sexo') nascimento = forms.DateField(label='Nascimento') password1 = forms.CharField(label='Senha', widget=forms.PasswordInput) password2 = forms.CharField( label='Confirmação de senha', widget=forms.PasswordInput) class Meta: model = User fields = ('email', 'username', 'password1', 'password2') # fields = UserCreationForm.Meta.fields + ('estado',) def clean_password2(self): # Check that the two password entries match password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError("Senhas não correspondem") return password1
class ConnectionForm(ModelForm): state = BRStateChoiceField() class Meta: model = Job fields = [ 'title', 'state', 'working_years', 'implementations', 'supports', 'modules', 'industries', 'methodology', 'languages', 'knowledge' ] labels = { 'title': 'titulo da busca', 'working_years': 'anos de experiência', 'supports': 'número de suportes', 'implementations': 'número de implantações', 'languages': 'Conhecimento em idiomas', 'knowledge': 'Conhecimentos complementares', } def save(self, commit=True): connection = super().save(commit=False) connection.state = self.cleaned_data['state'] if commit: connection.save() return connection
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)
def __init__(self, *args, **kwargs): super(CidadeForm, self).__init__(*args, **kwargs) self.fields['estado'] = BRStateChoiceField(initial="PR")