class EditProfile(UserChangeForm): name = forms.CharField(label='تغییر نام', widget=forms.TextInput(attrs={ 'class': 'form-control', 'dir': 'rtl', })) email = forms.EmailField(label='تغییر ایمیل', widget=forms.EmailInput(attrs={ 'class': 'form-control', })) bio = forms.CharField(label='تغییر بیو', widget=forms.Textarea( attrs={ 'rows': 1, 'cols': 15, 'autofocus': 'autofocus', 'class': 'form-control', 'dir': 'rtl', })) avatar = forms.ImageField(label='تغییر عکس') class Meta: model = User fields = ('email', 'name', 'bio', 'avatar', 'password')
class NewPasswordForm(forms.ModelForm): password = forms.CharField( min_length=8, widget=forms.PasswordInput(attrs={'placeholder': 'Password'}), help_text=[ "Your Password can't be too similar to your other personal information.", "Your Password must contain at least 8 characters." "Your Password can't be a commonly used password.", "Your Password can't be entirely numeric." ]) password1 = forms.CharField( min_length=8, widget=forms.PasswordInput(attrs={'placeholder': 'Confirm Password'}), help_text="Enter the same password as before,for validtion.") errors_messages = { 'password_mismatch': "The two password fields didn’t match.", } class Meta: model = User fields = ['password'] def clean(self, *args, **kwargs): password = self.cleaned_data.get('password') password1 = self.cleaned_data.get('password1') if password and password1 and password != password1: raise forms.ValidationError( self.errors_messages['password_mismatch'], code='password_mismatch') return super(NewPasswordForm, self).clean(*args, **kwargs)
class Subscribe(forms.Form): Name = forms.CharField() Email = forms.EmailField() Message = forms.CharField() def __str__(self): return self.Email
class UserCreationForm(BaseUserCreationForm): password1 = forms.CharField(label='گذرواژه', widget=forms.PasswordInput) password2 = forms.CharField(label='تکرار گذرواژه', widget=forms.PasswordInput) name = forms.CharField(label='نام کامل', widget=forms.TextInput(attrs={ 'class': 'form-control', 'dir': 'rtl', })) email = forms.EmailField(label='ایمیل', widget=forms.EmailInput(attrs={ 'class': 'form-control', })) class Meta: model = get_user_model() fields = ('email', 'name') def clean_password2(self): password1 = self.cleaned_data.get("password1") password2 = self.cleaned_data.get("password2") if password1 and password2 and password1 != password2: raise forms.ValidationError("Passwords don't match") return password2 def save(self, commit=True): """ Save the user in the database""" user = super().save(commit=False) user.set_password(self.cleaned_data['password1']) if commit: user.save() return user
class registerForm(forms.Form): username = forms.CharField(max_length=30) email = forms.EmailField(widget=forms.EmailInput, label='Email-Id') password1 = forms.CharField( widget=forms.PasswordInput, label='New Password') password2 = forms.CharField( widget=forms.PasswordInput, label='Confirm Password') CHOICES=[('M','Male'), ('F','Female')] Gender = forms.ChoiceField(choices=CHOICES, widget=forms.RadioSelect) def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout( 'username', 'email', 'Gender', Row( Column('password1', css_class='form-group col-md-6 mb-0'), Column('password2', css_class='form-group col-md-6 mb-0'), css_class='form-row' ), Submit('submit', 'Register') )
class EventoForm(ModelForm): nombre = forms.CharField(max_length=100) lugar = forms.CharField(max_length=500) direccion = forms.CharField(max_length=500) fecha_inicio = forms.DateField( widget=widgets.SelectDateWidget(empty_label=("Choose Year", "Choose Month", "Choose Day"), )) fecha_terminacion = forms.DateField( widget=widgets.SelectDateWidget(empty_label=("Choose Year", "Choose Month", "Choose Day"), )) CATEGORIA_CHOICES = ((1, 'Conferencia'), (2, 'Seminario'), (3, 'Congreso'), (4, 'Curso')) categoria = forms.ChoiceField(label="Sistema Operativo", choices=CATEGORIA_CHOICES) TIPO_CHOICES = ((1, 'Virtual'), (2, 'Presencial')) tipo = forms.ChoiceField(label="Tipo Evento", choices=TIPO_CHOICES) class Meta: model = Evento fields = [ 'nombre', 'lugar', 'direccion', 'fecha_inicio', 'fecha_terminacion', 'categoria', 'tipo' ]
class ExampleForm(forms.Form): like_website = forms.TypedChoiceField( label="Do you like this website?", choices=((1, "Yes"), (0, "No")), coerce=lambda x: bool(int(x)), widget=forms.RadioSelect, initial='1', required=True, ) favorite_food = forms.CharField( label="What is your favorite food?", max_length=80, required=True, ) favorite_color = forms.CharField( label="What is your favorite color?", max_length=80, required=True, ) favorite_number = forms.IntegerField( label="Favorite number", required=False, ) notes = forms.CharField( label="Additional notes or feedback", required=False, )
class UserForm(ModelForm): username = forms.CharField(max_length=50) first_name = forms.CharField(max_length=20) last_name = forms.CharField(max_length=20) email = forms.EmailField() password = forms.CharField(widget=forms.PasswordInput()) password2 = forms.CharField(widget=forms.PasswordInput()) class Meta: model = Usuario fields = ('picture', 'country', 'city') def clean_username(self): """Comprueba que no exista un username igual en la Base de Datos""" username = self.cleaned_data['username'] if User.objects.filter(username=username): raise forms.ValidationError('Nombre de usuario ya registrado.') return username def clean_email(self): """Comprueba que no exista un email igual en la Base de Datos""" email = self.cleaned_data['email'] if User.objects.filter(email=email): raise forms.ValidationError('Ya existe un email igual registado.') return email def clean_password2(self): """Comprueba que password y password2 segan iguales""" password = self.cleaned_data['password'] password2 = self.cleaned_data['password2'] if password != password2: raise forms.ValidationError('Las Claves no coinciden.') return password2
class SaboresForm(forms.ModelForm): nome = forms.CharField(max_length=30) ingredientes = forms.CharField(max_length=200) preco = forms.CharField(max_length=10) class Meta: model = Sabores fields = ['nome', 'ingredientes', 'preco']
class CustomPasswordResetForm(PasswordChangeForm): old_password = forms.CharField(max_length=20, widget=forms.PasswordInput) new_password1 = forms.CharField(max_length=20, widget=forms.PasswordInput) new_password2 = forms.CharField(max_length=20, widget=forms.PasswordInput) old_password.widget.attrs.update({'placeholder':('Old password'),'class':('form-control')}) new_password1.widget.attrs.update({'placeholder':('Password'),'class':('form-control')}) new_password2.widget.attrs.update({'placeholder':('Repeat password'),'class':('form-control')})
class LoginForm(forms.Form, FormMixMin): telephone = forms.CharField(max_length=11) password = forms.CharField(min_length=6, error_messages={ 'max_length': '密码最多不能超过20个字符', 'min_length': '密码不能少于6位' }) remember = forms.BooleanField(required=False)
class UserUpdateForm(forms.ModelForm): email = forms.EmailField() first_name = forms.CharField(max_length=20) last_name = forms.CharField(max_length=20) class Meta: model = User fields = ['first_name', 'last_name', 'email', 'username']
class loginForm(ModelForm): usernameL = forms.CharField(label="Usuario", max_length=50) passwordL = forms.CharField(label="Contraseña", widget=forms.PasswordInput()) class Meta: model = User fields = ['usernameL', 'passwordL']
class CadConsumidorForm(forms.ModelForm): nome = forms.CharField(max_length=50) endereço = forms.CharField(max_length=100) bairro = forms.CharField(max_length=50) cidade = forms.CharField(max_length=50) class Meta: model = CadConsumidor fields = ['nome', 'endereço', 'bairro', 'cidade']
class RegisterModelForm(UserCreationForm): password1 = forms.CharField( label="Password 1", widget=forms.PasswordInput, required=False, ) password2 = forms.CharField( label="Password 2", widget=forms.PasswordInput, required=False, ) class Meta(UserCreationForm.Meta): model = User fields = ('username', 'phone') widgets = { 'username': forms.widgets.TextInput(attrs={ 'class': 'form-control', 'placeholder': '烦请输入真实姓名' }), 'phone': forms.widgets.NumberInput(attrs={ 'class': 'form-control', 'placeholder': '请输入11位手机号码' }) } def clean_password2(self): # 覆写该方法, 为了不走注册时密码校验 # make_random_password return "我也不知道填什么" def clean_phone(self): # 从cleaned_data中取出我们需要的数据 phone = self.cleaned_data.get('phone') if not phone: raise forms.ValidationError('您并未输入电话号码') if not len(phone) == 11: # 号码长度不正确 raise forms.ValidationError("该手机号码位数不正确") phone_re = "1[3,4,5,7,8]\d{9}" if not re.match(phone_re, phone): # 号码不是合法号码 raise forms.ValidationError("您输入的手机号码不合法") return phone def save(self, commit=True): """ 重写方法, 设置默认密码。(如果没有给定密码,密码就会被设置成不使用,同用set_unusable_password()。 设置user无密码。 不同于密码为空,如果使用 check_password(),则不会返回True。) """ user = super(UserCreationForm, self).save(commit=False) user.set_password("0000") # 设置默认密码为 0000 if commit: user.save() return user
class HerramientaUpdateForm(ModelForm): pk_herramienta = None nombre = forms.CharField(label="Nombre", max_length=100) logo = forms.FileField(label="Logo", required=False) fichaTecnica = forms.CharField(label="Ficha Técnica", widget=forms.Textarea, max_length=2000) descripcion = forms.CharField(label="Descripción", widget=forms.Textarea, max_length=520) urlReferencia = forms.CharField(label="Url herramienta", max_length=500) SISTEMAS_OPERATIVOS = ( ('No aplica', 'No aplica'), ('MAC OS', 'MAC OS'), ('Windows', 'Windows'), ('IOS', 'IOS'), ('Android', 'Android'), ('Linux ', 'Linux'), ) sistemaOperativo = forms.MultipleChoiceField( required=True, widget=forms.CheckboxSelectMultiple, label="Sistema Operativo", choices=SISTEMAS_OPERATIVOS) ESTADO = ((6, 'Guardar en mis borradores'), (1, 'Enviar para revisión')) estado = forms.ChoiceField(required=True, widget=forms.RadioSelect, label="Seleccione una acción", choices=ESTADO) PLATAFORMAS = ( ('Moodle', 'Moodle'), ('Blackboard', 'Blackboard'), ('WordPress', 'WordPress'), ('Drupal', 'Drupal'), ('Joomla', 'Joomla'), ) plataforma = forms.ChoiceField(label="Plataforma", choices=PLATAFORMAS) LICENCIA = ( ('Apache License Version 2.0', 'Apache License Version 2.0'), ('GNU GENERAL PUBLIC ', 'GNU GENERAL PUBLIC '), ('MIT License', 'MIT License'), ('UnLicense', 'UnLicense'), ('GNU AFFERO GENERAL PUBLIC LICENSE', 'GNU AFFERO GENERAL PUBLIC LICENSE'), ) licencia = forms.ChoiceField(label="Licencia", choices=LICENCIA) class Meta: model = Herramienta fields = [ 'nombre', 'logo', 'urlReferencia', 'sistemaOperativo', 'plataforma', 'licencia', 'fichaTecnica', 'descripcion', 'estado' ]
class LoginForm(forms.Form): username = forms.CharField(max_length=100) password = forms.CharField(widget=forms.PasswordInput(render_value=False), max_length=100) def login(self, request): username = request.POST['username'] password = request.POST['password'] user = authenticate(request, username=username, password=password) return user
class SignUpForm(UserCreationForm): GENDER_CHOICES = (('Male', 'Male'), ('Female', 'Female')) first_name = forms.CharField(max_length=200, required=True) last_name = forms.CharField(max_length=200, required=True) male = forms.ChoiceField(choices=GENDER_CHOICES) class Meta(UserCreationForm.Meta): model = get_user_model() fields = ('username', 'first_name', 'last_name', 'male', 'email', 'password1', 'password2')
class ActividadRevisionForm(ModelForm): pk_actividad = None nombre = forms.CharField(label="Nombre", max_length=100) instrucciones = forms.CharField(label="Instrucciones", widget=forms.Textarea, max_length=2000) descripcion = forms.CharField(label="Descripción", widget=forms.Textarea, max_length=520) url = forms.CharField(label="Url", max_length=500) class Meta: model = Herramienta fields = ['nombre', 'url', 'instrucciones', 'descripcion']
class CreateConnectorForm(forms.ModelForm): conn_name = forms.CharField(label=ugettext('Connection name'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Connection name'), })) db_type = forms.ChoiceField(label=ugettext('Type'), choices=Connector.DB_TYPES, widget=forms.Select(attrs={ 'class': 'form-control', })) host = forms.CharField(label=ugettext('Host'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Host'), })) port = forms.IntegerField(label=ugettext('Port'), widget=forms.NumberInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Port'), })) username = forms.CharField(label=ugettext('Username'), required=False, widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Username'), })) password = forms.CharField(label=ugettext('Password'), required=False, widget=forms.PasswordInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Password'), })) db_instance = forms.CharField(label=ugettext('Database'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('Database'), })) def clean(self): cleaned_data = super().clean() try: create_connection(cleaned_data.get('db_type'), cleaned_data.get('username'), cleaned_data.get('password'), cleaned_data.get('host'), cleaned_data.get('port'), cleaned_data.get('db_instance')) except: raise forms.ValidationError( ugettext('Can not connect to database with settings, please recheck settings again.'), code='invalid' ) class Meta: model = Connector fields = [ 'conn_name', 'db_type', 'host', 'port', 'username', 'password', 'db_instance', ]
class UserForm(ModelForm): username = forms.CharField(label="Usuario", max_length=20) first_name = forms.CharField(label="Nombres", max_length=20) last_name = forms.CharField(label="Apellidos", max_length=20) foto = forms.FileField(required=False) email = forms.EmailField(label="Correo electrónico") password = forms.CharField(label="Contraseña", widget=forms.PasswordInput()) password2 = forms.CharField(label="Confirmación Contraseña", widget=forms.PasswordInput()) ADMINISTRADOR = 1 USER_GTI = 2 ROLE_CHOICES = ( (USER_GTI, 'Miembro GTI'), (ADMINISTRADOR, 'Administrador'), ) roles = forms.ChoiceField(choices=ROLE_CHOICES) class Meta: model = User fields = ['username', 'first_name', 'last_name', 'email', 'password', 'password2', 'roles', 'foto'] # Verificacion usuario unico def clean_username(self): username = self.cleaned_data['username'] if User.objects.filter(username=username): raise forms.ValidationError('Nombre de usuario ya ha sido tomado') return username # verificacion correo unico def clean_email(self): email = self.cleaned_data['email'] if User.objects.filter(email=email): raise forms.ValidationError('Correo ya ha sido registrado') return email # verificacion las contraseñas coinciden y seguridad def clean_password2(self): password = self.cleaned_data['password'] password2 = self.cleaned_data['password2'] if password != password2: raise forms.ValidationError('Contraseñas no coinciden') try: password_validation.validate_password(password2) except password_validation.ValidationError as errores: mensajes = [] for m in errores.messages: if m == 'This password is too short. It must contain at least 8 characters.': mensajes.append('Contraseña muy corta, debe contener más de 7 caracteres') if m == 'This password is too common.': mensajes.append('Contraseña muy común') if m == 'This password is entirely numeric.': mensajes.append('Contraseña no puede contener solo números') if m.startswith("The password is too similar"): mensajes.append('Contraseña muy similar a los datos del usuario') raise forms.ValidationError(mensajes) return password2
class UserRegisterForm(UserCreationForm): email = forms.EmailField() first_name = forms.CharField(max_length=20) last_name = forms.CharField(max_length=20) class Meta: model = User fields = [ 'first_name', 'last_name', 'email', 'username', 'password1', 'password2' ]
class CustomUserCreationForm(UserCreationForm): password1 = forms.CharField(label=_("Password"), widget=forms.PasswordInput) password2 = forms.CharField( label=_("Password confirmation"), widget=forms.PasswordInput, help_text=_("Enter the same password as above, for verification.")) class Meta: model = get_user_model() fields = ('email', 'password1', 'password2')
class EditUserForm(forms.ModelForm): first_name = forms.CharField(max_length=16) last_name = forms.CharField(max_length=16) email = forms.EmailField() class Meta: model = User fields = [ 'first_name', 'last_name', 'email', ]
class createElectionForm(forms.ModelForm): elec_name = forms.CharField() elec_type= forms.CharField(label='ElectionType', widget=forms.Select(choices=FRUIT_CHOICES)) cvc_file = forms.FileField() class Meta: model = Election fields = [ 'elec_name', 'elec_type', 'cvc_file', ]
class EditInfoForm(forms.ModelForm): name = forms.CharField() father_name = forms.CharField() mother_name = forms.CharField() profile_picture = forms.FileField() dob = forms.DateField() class Meta: model = DummyCitizenInfo fields = [ 'name', 'father_name', 'mother_name', 'profile_picture', 'dob' ]
class newPostForm(forms.Form): title = forms.CharField(max_length=150, label='Title') post = forms.CharField(widget=forms.Textarea(attrs={ "rows": 5, "cols": 20 }), label='Post') def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.helper = FormHelper() self.helper.layout = Layout('title', 'post', Submit('submit', 'Upload Post'))
class UpdateUserForm(forms.ModelForm): email = forms.CharField(widget=forms.EmailInput( attrs={'class': 'utf-submit-field'})) username = forms.CharField(widget=forms.TextInput( attrs={'class': 'utf-submit-field'})) first_name = forms.CharField(widget=forms.TextInput( attrs={'class': 'utf-submit-field'})) last_name = forms.CharField(widget=forms.TextInput( attrs={'class': 'utf-submit-field'})) class Meta: model = get_user_model() fields = ['email', 'first_name', 'last_name', 'username']
class UserRegistrationForm(forms.ModelForm): password = forms.CharField(label='Password', widget=forms.PasswordInput) password2 = forms.CharField(label='Repeat password', widget=forms.PasswordInput) class Meta: model = User fields = ('username', 'email') def clean_password2(self): cd = self.cleaned_data if cd['password'] != cd['password2']: raise forms.ValidationError('Las contraseñas no coinciden') return cd['password2']
class StudentForm(forms.ModelForm): student_id = forms.CharField(max_length=8) student_name = forms.CharField(max_length=25) email = forms.EmailField(max_length=19) section = forms.CharField(max_length=2) class Meta: model = StudentInfo fields = [ 'student_id', 'student_name', 'email', 'section', ]