class inForm(forms.Form): age = forms.ChoiceField(label="是否适龄", choices=[(0, u'否'), (1, u'是')], initial='', widget=forms.Select(), required=True) credit = forms.ChoiceField(label="个人信用", choices=[(3, u'好'), (2, u'信用一般'), (3, u'信用差')], initial='', widget=forms.Select(), required=True) guarantee = forms.ChoiceField(label="有无担保", choices=[(1, u'有担保'), (0, '无担保')], initial='', widget=forms.Select(), required=True) income = forms.ChoiceField(label="收入水平", choices=[(1, u'收入低'), (2, u'一般'), (3, u'中'), (4, u'高')], initial='', widget=forms.Select(), required=True) house = forms.ChoiceField(label="有无房产", choices=[(1, u'有'), (0, u'无')], initial='', widget=forms.Select(), required=True)
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 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 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 UserUpdateGTIForm(ModelForm): pk_user = None 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) email = forms.EmailField(label="Correo electrónico") foto = forms.FileField(required=False) USER_GTI = 2 ROLE_CHOICES = ( (USER_GTI, 'Miembro GTI'), ) roles = forms.ChoiceField(choices=ROLE_CHOICES) class Meta: model = User fields = ['username', 'first_name', 'last_name', 'email', 'roles', 'foto'] # verificacion correo unico def clean_email(self): email = self.cleaned_data['email'] busqueda = User.objects.filter(email=email) if busqueda: user = len(busqueda) if user > 1: raise forms.ValidationError('Correo ya ha sido registrado') else: return email return email def clean_username(self): username = self.cleaned_data['username'] if User.objects.exclude(pk=self.instance.id).filter(username=username).exists(): raise forms.ValidationError(u'Usuario "%s" ya esta en uso.' % username) return username
class ReporteCargaTrabajoForm(forms.Form): CHOICES = ( ("rubro", "Rubro"), ("tecnico", "Técnico"), ) filtros = forms.ChoiceField( CHOICES, widget=forms.Select(attrs={'class': 'form-control chart-input-carga'}))
class CreateApplyForm(forms.ModelForm): use = forms.ChoiceField(label=ugettext('贷款用途及贷款用途子类'), choices=LOAN_USES, widget=forms.Select(attrs={ 'class': 'form-control', })) description = forms.CharField(label=ugettext(''), widget=forms.Textarea(attrs={ 'class': 'form-control', 'rows': 5, })) amount = forms.ChoiceField(label=ugettext('申请金额'), choices=LOAN_AMOUNTS, widget=forms.Select(attrs={ 'class': 'form-control', })) education = forms.ChoiceField(label=ugettext('教育程度'), choices=EDUCATION_LEVEL, widget=forms.RadioSelect()) marriage = forms.ChoiceField(label=ugettext('婚姻状况'), choices=MARRIAGE_STATE, widget=forms.RadioSelect()) members = forms.ChoiceField(label=ugettext('家庭人口'), choices=MEMBER_OF_FAMILY, widget=forms.RadioSelect()) incoming = forms.ChoiceField(label=ugettext('收入水平(全年收入月平均)'), choices=INCOMING_LEVEL, widget=forms.RadioSelect()) property = forms.ChoiceField(label=ugettext('居住类型'), choices=PROPERTIES, widget=forms.RadioSelect()) vehicle = forms.ChoiceField(label=ugettext('主要出行交通工具'), choices=VEHICLES, widget=forms.RadioSelect()) residence = forms.CharField(label=ugettext('住宅地址'), widget=forms.HiddenInput()) employment = forms.ChoiceField(label=ugettext('受雇类型'), choices=EMPLOYMENTS, widget=forms.RadioSelect()) company = forms.CharField( label=ugettext('公司名称'), required=False, widget=forms.TextInput(attrs={ 'class': 'form-control', 'style': 'display:none', })) class Meta: model = Loan fields = []
class HerramientaForm(ModelForm): 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) 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) 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) PLATAFORMAS = ( ('Plataforma 1', 'Plataforma 1'), ('Plataforma 2', 'Plataforma 2'), ('Plataforma 3', 'Plataforma 3'), ('Plataforma 4', 'Plataforma 4'), ) plataforma = forms.ChoiceField(label="Plataforma", choices=PLATAFORMAS) LICENCIA = ( ('Licencia 1', 'Licencia 1'), ('Licencia 2', 'Licencia 2'), ('Licencia 3', 'Licencia 3'), ('Licencia 4', 'Licencia 4'), ) licencia = forms.ChoiceField(label="Licencia", choices=LICENCIA) class Meta: model = Herramienta fields = ['nombre', 'logo', 'urlReferencia', 'sistemaOperativo', 'plataforma', 'licencia', 'fichaTecnica', 'descripcion', 'estado']
class ClientForm(ModelForm): nombre = forms.CharField( max_length=User._meta.get_field('first_name').max_length, label='Nombres') apellido = forms.CharField( max_length=User._meta.get_field('last_name').max_length, label='Apellidos') departamento = forms.ChoiceField( choices=Cliente._meta.get_field('departamento').choices, label='Departamento') ciudad = forms.ChoiceField( choices=Cliente._meta.get_field('ciudad').choices, label='Ciudad') numero_identificacion = forms.CharField(max_length=20) tipo_identificacion = forms.ChoiceField( choices=Cliente._meta.get_field('tipo_identificacion').choices) telefono_contacto = forms.CharField(max_length=15, label='Telefono de Contacto') correo = forms.EmailField(max_length=50, label='Correo electrónico') direccion = forms.CharField(max_length=150, label='Direcció de Residencia') contrasena = forms.CharField(widget=forms.PasswordInput(), label='Contraseña') contrasena2 = forms.CharField(widget=forms.PasswordInput(), label='Confirma tu contraseña') class Meta: model = User fields = [ 'nombre', 'apellido', 'departamento', 'ciudad', 'numero_identificacion', 'tipo_identificacion', 'telefono_contacto', 'correo', 'direccion', 'contrasena', 'contrasena2' ] def clean_contrasena2(self): password = self.cleaned_data['contrasena'] password2 = self.cleaned_data['contrasena2'] if password != password2: raise forms.ValidationError('Las claves no coinciden.') return password2 def clean_correo(self): email = self.cleaned_data['correo'] if User.objects.filter(email=email): raise forms.ValidationError('Ya existe un email igual registrado.') return email
class ReporteProductoForm(forms.Form): CHOICES = ( ("rubro", "Rubro"), ("tipo_servicio", "Tipo de servicio"), ) filtros = forms.ChoiceField( CHOICES, widget=forms.Select(attrs={'class': 'form-control'})) fecha_ini = forms.DateTimeField(input_formats=[FORMATO_FECHA]) fecha_fin = forms.DateTimeField(input_formats=[FORMATO_FECHA])
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 UserReg(forms.Form): first_name = forms.CharField(label="First Name", max_length=15) last_name = forms.CharField(label="Last Name", max_length=15) nid = forms.IntegerField(label="NID") email_address = forms.CharField(label="Email Address") home_address = forms.CharField(label="Home Address") gender = forms.ChoiceField(choices=[('1', 'Male'), ('2', 'Female')], widget=forms.RadioSelect) mobile_number = forms.CharField(label="Mobile Number", max_length=15) password = forms.CharField(label="Password", widget=forms.PasswordInput)
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 SpectatorForm(forms.Form): ticket_class = forms.ChoiceField(models.Spectator.TICKET_CHOICES) coupon_code = forms.CharField(max_length=5) def save(self, user, commit=True): spectator = models.Spectator.objects.create(user=user) spectator.ticket_class = self.cleaned_data['ticket_class'] spectator.coupon_code = self.cleaned_data['coupon_code'] if commit: spectator.save() return spectator
class AddressForm(forms.Form): email = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'Email'})) password = forms.CharField(widget=forms.PasswordInput()) address_1 = forms.CharField( label='Address1', widget=forms.TextInput(attrs={'placeholder': '1234 Main St'})) address_2 = forms.CharField(widget=forms.TextInput( attrs={'placeholder': 'Apartment, studio, or floor'})) city = forms.CharField() state = forms.ChoiceField(choices=STATES) zip_code = forms.CharField(label='Zip') check_me_out = forms.BooleanField(required=False)
class PlayerForm(forms.Form): game = forms.ChoiceField(models.Player.GAME_CHOICES) team_name = forms.CharField(max_length=100) def save(self, user, commit=True): player = models.Player.objects.create(user=user) player.user = user player.game = self.cleaned_data['game'] player.team_name = self.cleaned_data['team_name'] if commit: player.save() return player
class ReporteTotalOrdenesForm(forms.Form): CHOICES = ( ("rubro", "Rubro"), ("tipo_servicio", "Tipo de servicio"), ("cliente", "Cliente"), ("tecnico", "Técnico"), ) filtros = forms.ChoiceField( CHOICES, widget=forms.Select(attrs={'class': 'form-control chart-input'}), label="Criterio:") fecha_ini = forms.DateTimeField(input_formats=[FORMATO_FECHA]) fecha_fin = forms.DateTimeField(input_formats=[FORMATO_FECHA])
class ActividadForm(ModelForm): nombre = forms.CharField(label="Nombre", max_length=100) descripcion = forms.CharField(label="Descripción", widget=forms.Textarea, max_length=520) instrucciones = forms.CharField(label="Instrucciones", widget=forms.Textarea, max_length=2000) url = forms.CharField(label="Url Actividad", max_length=500) 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) class Meta: model = Actividad fields = ['nombre', 'url', 'instrucciones', 'descripcion', 'estado']
class BasicInfoForm(UserCreationForm): choices = [(0, '--------'), (1, 'Spectator'), (2, 'Player')] user_type = forms.ChoiceField(choices=choices, initial=None) class Meta: model = User fields = ['username', 'password1', 'password2', 'email', 'user_type'] def save(self, commit=True): user = super(UserCreationForm, self).save(commit=False) LOG.debug("user_type from form:" + self.cleaned_data['user_type']) if commit: user.save() # First save the created user, user.basicinfo.user_type = self.cleaned_data['user_type'] user.save() # save the basic info return user
class PaymentForm(ModelForm): nombre = forms.CharField(max_length=150, label='Nombre') email = forms.EmailField(max_length=50, label='Correo electrónico') direccion = forms.CharField(max_length=150, label='Direcció de Residencia') celular = forms.CharField(max_length=15, label='Celular') telefono = forms.CharField(max_length=15, label='Telefono') observaciones = forms.CharField(max_length=500, label='Observaciones') nombre_completo = forms.CharField(max_length=150, label='Nombre') tipo_documento = forms.ChoiceField( choices=Pedido._meta.get_field('tipo_identificacion').choices) numero_documento = forms.CharField(max_length=20) class Meta: model = Pedido fields = [ 'nombre', 'email', 'direccion', 'celular', 'telefono', 'observaciones', 'nombre_completo', 'tipo_documento', 'numero_documento' ]
class CustomerForm(forms.Form): product = forms.ChoiceField(label=ugettext('产品'), choices=PRODUCT_TYPES, widget=forms.Select(attrs={ 'class': 'form-control', })) salesman = forms.CharField(label=ugettext('销售人员'), widget=forms.TextInput(attrs={ 'class': 'form-control', })) customer_source = forms.CharField( label=ugettext('客户来源'), widget=forms.TextInput(attrs={ 'class': 'form-control', })) phone_number = forms.CharField(label=ugettext('客户手机号'), widget=forms.TextInput( attrs={ 'class': 'form-control', 'placeholder': ugettext('请填写客户手机号'), 'id': 'phone_number', 'name': 'phone_number', })) verified_code = forms.CharField( label=ugettext('验证码'), widget=forms.TextInput(attrs={ 'class': 'form-control', 'placeholder': ugettext('请填写验证码'), })) class Meta: fields = [ 'product', 'salesman', 'customer_source', 'phone_number', 'verified_code', ]