From 3a2877ac63cdd835532707bbe85df9c8241b4de6 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Thu, 9 Mar 2017 10:40:32 -0300 Subject: [PATCH] Verifica se usuario existente --- sapl/parlamentares/forms.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index 3d85c3045..bdcf2d232 100644 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -3,6 +3,7 @@ from datetime import date, timedelta from crispy_forms.helper import FormHelper from crispy_forms.layout import Fieldset, Layout from django import forms +from django.contrib.auth import get_user_model from django.contrib.auth.models import Group, User from django.core.exceptions import ValidationError from django.db import transaction @@ -289,6 +290,11 @@ class VotanteForm(ModelForm): def clean(self): cd = self.cleaned_data + username = cd['username'] + if get_user_model().objects.filter(username=username).exists(): + raise ValidationError(_('Não foi possível salvar registro,\ + pois usuário existente')) + if ('senha' not in cd or 'senha_confirma' not in cd or not cd['senha'] or not cd['senha_confirma']): raise ValidationError(_(