From 02fdb00fde0209629595fc596a3b8b71b9216510 Mon Sep 17 00:00:00 2001 From: Luciano Almeida Date: Thu, 30 Jun 2016 14:45:59 -0300 Subject: [PATCH] =?UTF-8?q?Corrige=20cadastro=20de=20usu=C3=A1rio,=20atual?= =?UTF-8?q?iza=C3=A7=C3=A3o=20de=20perfil=20e=20envio=20de=20email?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Luciano Almeida --- sigi/apps/usuarios/forms.py | 16 ++++++++++------ sigi/apps/usuarios/views.py | 5 ++--- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/sigi/apps/usuarios/forms.py b/sigi/apps/usuarios/forms.py index 69046f6..e204d5f 100644 --- a/sigi/apps/usuarios/forms.py +++ b/sigi/apps/usuarios/forms.py @@ -172,13 +172,14 @@ class UsuarioForm(ModelForm): return True def clean_username(self): + # import ipdb; ipdb.set_trace() usuario = User.objects.filter( username=self.cleaned_data[u'username']).exists() if usuario: raise ValidationError(u'Usuário existente.') - return self.cleaned_data + return self.cleaned_data[u'username'] def clean_primeiro_numero(self): cleaned_data = self.cleaned_data @@ -190,7 +191,7 @@ class UsuarioForm(ModelForm): telefone.principal = self.data[u'primeiro_principal'] cleaned_data[u'primeiro_telefone'] = telefone - return cleaned_data + return self.cleaned_data[u'primeiro_numero'] def clean_segundo_numero(self): cleaned_data = self.cleaned_data @@ -202,14 +203,13 @@ class UsuarioForm(ModelForm): telefone.principal = self.data[u'segundo_principal'] cleaned_data[u'segundo_telefone'] = telefone - return cleaned_data + return self.cleaned_data[u'segundo_numero'] def valida_email_existente(self): return Usuario.objects.filter( email=self.cleaned_data[u'email']).exists() def clean(self): - if (u'password' not in self.cleaned_data or u'password_confirm' not in self.cleaned_data): raise ValidationError(_(u'Favor informar senhas atuais ou novas')) @@ -309,15 +309,20 @@ class UsuarioEditForm(UsuarioForm): self.fields.pop(u'password') self.fields.pop(u'password_confirm') + def clean_username(self): + pass + def valida_email_existente(self): u'''Não permite atualizar emails para emails existentes de outro usuário ''' + return Usuario.objects.filter( email=self.cleaned_data[u'email']).exclude( - user__username=self.cleaned_data[u'username']).exists() + user__username=self.data[u'username']).exists() def clean(self): + self.cleaned_data[u'username'] = self.data[u'username'] if (u'email' not in self.cleaned_data or u'email_confirm' not in self.cleaned_data): raise ValidationError(_(u'Favor informar endereços de email')) @@ -327,7 +332,6 @@ class UsuarioEditForm(UsuarioForm): self.cleaned_data[u'email'], self.cleaned_data[u'email_confirm'], msg) - email_existente = self.valida_email_existente() if email_existente: diff --git a/sigi/apps/usuarios/views.py b/sigi/apps/usuarios/views.py index 2ec5e35..a0bd74c 100644 --- a/sigi/apps/usuarios/views.py +++ b/sigi/apps/usuarios/views.py @@ -161,9 +161,8 @@ class UsuarioCrud(Crud): reverse(u'usuarios:confirmar_email', kwargs=kwargs) + u"\n\nCaso você não tenha feito este cadastro, " + u"por favor, ignore esta mensagem.\n") - remetente = settings.EMAIL_HOST_USER - destinatario = [confirmar_email.email, - settings.EMAIL_HOST_USER] + remetente = settings.EMAIL_SEND_USER + destinatario = [confirmar_email.email] send_mail(assunto, mensagem, remetente, destinatario, fail_silently=False) return reverse(u'index_atendimento')