Conjunto d9619ca en gestor_consulta
- Fecha y hora:
- 19/09/2017 15:21:57 (hace 7 años)
- Branches:
- master
- Children:
- 1ac8063
- Parents:
- 9b33f35
- Ficheros:
-
- 1 añadido
- 4 editados
Leyenda
- No modificado
- Añadido
- Eliminado
-
base/fields.py
rd7b19bc rd9619ca 16 16 17 17 from django.forms import MultiValueField, ChoiceField, CharField 18 19 from rest_framework import serializers 18 20 19 21 from .constant import SHORT_NACIONALIDAD … … 57 59 return ''.join(data_list) 58 60 return '' 61 62 class CedulaRestField(serializers.Field): 63 def to_representation(self, obj): 64 return "some here" 65 66 def to_representation(self, obj): 67 """ 68 Serialize the object's class name. 69 """ 70 return obj.__class__.__name__ -
rest/routers.py
rb1cb066 rd9619ca 16 16 from consulta.rest import ConsultaViewSet 17 17 from base.rest import EntidadViewSet, MunicipioViewSet, ParroquiaViewSet 18 from users.rest import FormViewSet 18 19 19 20 router = DefaultRouter() … … 23 24 router.register(r'municipio', MunicipioViewSet, 'municipio') 24 25 router.register(r'parroquia', ParroquiaViewSet, 'parroquia') 26 router.register(r'registro', FormViewSet, 'registro') -
users/serializers.py
rd821e95 rd9619ca 1 1 # -*- coding: utf-8 -*- 2 from django import forms 2 3 from rest_framework import serializers 3 4 from django.contrib.auth.models import User 5 from drf_braces.serializers.form_serializer import FormSerializer 6 from base.fields import CedulaField 7 from base.functions import ( 8 cargar_entidad, cargar_municipios, cargar_parroquias, 9 validate_cedula, validate_email 10 ) 4 11 5 12 … … 18 25 model = User 19 26 fields = ('id', 'username', 'email',) 27 28 29 class UserForm(forms.Form): 30 ## Nombre de usuario 31 username = forms.CharField(max_length=30, 32 widget=forms.TextInput(), 33 label="Nombre de Usuario" 34 ) 35 36 ## Contraseña 37 password = forms.CharField(max_length=20, 38 widget=forms.TextInput(attrs={'type':'password'}), 39 label="Constraseña" 40 ) 41 42 ## Repita la Contraseña 43 password_repeat = forms.CharField(max_length=20, 44 widget=forms.TextInput(attrs={'type':'password'}), 45 label="Repita su constraseña" 46 ) 47 48 ## nombre 49 nombre = forms.CharField(max_length=100, 50 widget=forms.TextInput(), 51 label="Nombre" 52 ) 53 54 ## apellido 55 apellido = forms.CharField(max_length=100, 56 widget=forms.TextInput(), 57 label="Apellido" 58 ) 59 60 ## correo 61 email = forms.EmailField( 62 widget=forms.TextInput(), 63 label="Correo" 64 ) 65 66 ## cedula 67 68 def clean_password_repeat(self): 69 """! 70 Método que valida si las contraseñas coinciden 71 72 @author Rodrigo Boet (rboet at cenditel.gob.ve) 73 @copyright GNU/GPLv2 74 @date 01-03-2017 75 @param self <b>{object}</b> Objeto que instancia la clase 76 @return Retorna el campo con la validacion 77 """ 78 password = self.cleaned_data['password'] 79 password_repeat = self.cleaned_data['password_repeat'] 80 if(password_repeat!=password): 81 raise forms.ValidationError("La contraseña no coincide") 82 return password_repeat 83 84 def clean_cedula(self): 85 """! 86 Método que valida si la cedula es única 87 88 @author Rodrigo Boet (rboet at cenditel.gob.ve) 89 @copyright GNU/GPLv2 90 @date 01-03-2017 91 @param self <b>{object}</b> Objeto que instancia la clase 92 @return Retorna el campo con la validacion 93 """ 94 cedula = self.cleaned_data['cedula'] 95 if(validate_cedula(cedula)): 96 raise forms.ValidationError("La cédula ingresada ya existe") 97 return cedula 98 99 def clean_email(self): 100 """! 101 Método que valida si el correo es única 102 103 @author Rodrigo Boet (rboet at cenditel.gob.ve) 104 @copyright GNU/GPLv2 105 @date 01-03-2017 106 @param self <b>{object}</b> Objeto que instancia la clase 107 @return Retorna el campo con la validacion 108 """ 109 email = self.cleaned_data['email'] 110 if(validate_email(email)): 111 raise forms.ValidationError("El correo ingresado ya existe") 112 return email 113 114 115 class MySerializer(FormSerializer): 116 class Meta(object): 117 form = UserForm
Nota: Vea TracChangeset
para ayuda en el uso del visor de conjuntos de cambios.