Changeset a5eec44 in sicp


Ignore:
Timestamp:
May 20, 2015, 11:42:23 AM (9 years ago)
Author:
Ing. Roldan D. Vargas G <rvargas@…>
Branches:
master
Children:
449d062
Parents:
c6e5d5e
Message:

se agregan mensajes de log en las vistas de usuarios

File:
1 edited

Legend:

Unmodified
Added
Removed
  • apps/usuario/views.py

    rfca2ef7 ra5eec44  
    3131from django.shortcuts import render_to_response
    3232from django.template.context import RequestContext
     33from django.utils.translation import ugettext_lazy as _
    3334from apps.comun.constantes import CREATE_MESSAGE, APROBATION_MESSAGE, DELETE_MESSAGE, UPDATE_MESSAGE
     35from apps.comun.functions import enviar_correo
    3436from apps.usuario.models import UserProfile, Institucion, Cargo
    3537from apps.usuario.forms import RegistroForm, AutenticarForm
    3638from apps.usuario.functions import generar_password
     39
     40
     41import logging
     42
     43logger = logging.getLogger('usuario')
    3744
    3845class RegistroCreate(SuccessMessageMixin, CreateView):
     
    5461        self.object = form.save(commit=False)
    5562        clave = generar_password()
    56         usr = User.objects.create_user(
    57             username=form.cleaned_data['cedula'],
    58             email=form.cleaned_data['correo'],
    59             first_name=form.cleaned_data['nombre'],
    60             last_name=form.cleaned_data['apellido'],
    61             password=clave
    62         )
     63        cedula = form.cleaned_data['cedula']
     64        correo = form.cleaned_data['correo'].lower()
     65        nombre, apellido = form.cleaned_data['nombre'], form.cleaned_data['apellido']
     66
     67        usr = User.objects.create_user(username=cedula,email=correo,first_name=nombre,last_name=apellido,password=clave)
    6368        usr.is_active = False
    6469        usr.save()
     
    6974        form.instance.cargo = cargo
    7075        self.object.save()
     76        logging.info(_(u"Se ha registrado el usuario [%s] de la institución [%s] con el cargo de [%s]"
     77                       % (form.cleaned_data['cedula'], institucion.nombre, cargo.nombre)))
     78        enviado = enviar_correo(correo, 'registro.mail', 'Registro de usuario en SICP', {
     79            'usuario': cedula, 'clave': clave, 'emailapp': settings.EMAIL_FROM
     80        })
     81        if not enviado:
     82            logging.warning(_(u"Ocurrió un inconveniente al enviar el correo de registro al usuario [%s]" % cedula))
    7183        return super(RegistroCreate, self).form_valid(form)
    7284
     
    91103            usr.last_login = datetime.now()
    92104            usr.save()
    93 
     105            logging.info(_(u"Acceso al sistema por el usuario [%s]" % request.POST['usuario']))
    94106            return HttpResponseRedirect(urlresolvers.reverse("inicio"))
    95107        else:
     
    113125    if user.is_authenticated():
    114126        logout(request)
     127        logging.info(_(u"El usuario [%s] salio del sistema" % user))
    115128    return HttpResponseRedirect(urlresolvers.reverse("inicio"))
Note: See TracChangeset for help on using the changeset viewer.