Changeset 90160be in sicp
- Timestamp:
- May 15, 2015, 1:25:12 PM (9 years ago)
- Branches:
- master
- Children:
- 53dfbdb
- Parents:
- 0471d7a
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
apps/usuario/views.py
r3f2382d r90160be 1 from django.shortcuts import render 1 # coding=utf-8 2 """ 3 Simulador Integral de Cadenas Productivas (SICP) 2 4 3 # Create your views here. 5 Copyleft (@) 2015 CENDITEL nodo Mérida - https://miv.cenditel.gob.ve/simulacion/ 6 """ 7 # # @package usuario.urls 8 # 9 # Clases y funciones a implementar en las vistas del módulo de usuarios 10 # @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) 11 # @author Centro Nacional de Desarrollo e Investigación en Tecnologías Libres (CENDITEL) nodo Mérida - Venezuela 12 # @copyright GNU/GPLv2 13 # @date 05-05-2015 14 # @version 3.0.0 15 16 ## Muestra el autor del script cuando es invocado 17 __author__ = "Ing. Roldan Vargas (rvargas at cenditel.gob.ve)" 18 ## Muestra documentación breve sobre el script 19 __doc__ = "Clases y funciones a implementar en las vistas del módulo de usuarios" 20 21 from django.views.generic import ListView 22 from django.views.generic.edit import CreateView, UpdateView 23 from django.contrib.messages.views import SuccessMessageMixin 24 from django.core.urlresolvers import reverse_lazy 25 from django.contrib.auth.models import User 26 from apps.comun.constantes import CREATE_MESSAGE, APROBATION_MESSAGE, DELETE_MESSAGE, UPDATE_MESSAGE 27 from apps.usuario.models import UserProfile, Institucion, Cargo 28 from apps.usuario.forms import RegistroForm 29 from apps.usuario.functions import generar_password 30 31 class RegistroCreate(SuccessMessageMixin, CreateView): 32 model = UserProfile 33 form_class = RegistroForm 34 template_name = 'registro.html' 35 success_url = reverse_lazy('inicio') 36 success_message = "%s %s" % (CREATE_MESSAGE, APROBATION_MESSAGE) 37 38 def form_valid(self, form): 39 """! 40 Metodo que valida si el formulario es valido, en cuyo caso se procede a registrar los datos del usuario 41 42 @author Ing. Roldan Vargas (rvargas at cenditel.gob.ve) 43 @copyright GNU/GPLv2 44 @date 14-05-2015 45 @return Retorna el formulario validado 46 """ 47 self.object = form.save(commit=False) 48 clave = generar_password() 49 usr = User.objects.create_user( 50 username=form.cleaned_data['cedula'], 51 email=form.cleaned_data['correo'], 52 first_name=form.cleaned_data['nombre'], 53 last_name=form.cleaned_data['apellido'], 54 password=clave 55 ) 56 usr.is_active = False 57 usr.save() 58 institucion = Institucion.objects.get(nombre=form.cleaned_data['institucion']) 59 cargo = Cargo.objects.get(nombre=form.cleaned_data['cargo']) 60 form.instance.user = usr 61 form.instance.institucion = institucion 62 form.instance.cargo = cargo 63 self.object.save() 64 return super(RegistroCreate, self).form_valid(form)
Note: See TracChangeset
for help on using the changeset viewer.