From 025dbfbae3e61f69e861b346ce2e4300781f20d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Cantu=C3=A1ria?= Date: Wed, 27 Feb 2019 14:23:34 -0300 Subject: [PATCH] =?UTF-8?q?Fix=20#2555=20-=20Informar=20erro=20ao=20tentar?= =?UTF-8?q?=20criar=20usu=C3=A1rio=20sem=20selecionar=20roles=20(#2564)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Fix #2555 * Corrige lugar da mensagem de erro --- sapl/base/forms.py | 4 ++-- sapl/base/views.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 9a8dd811e..0c8bab476 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -84,7 +84,7 @@ class UsuarioCreateForm(ModelForm): 'password1', 'password2', 'user_active', 'roles'] def clean(self): - super(UsuarioCreateForm, self).clean() + super().clean() if not self.is_valid(): return self.cleaned_data @@ -99,7 +99,7 @@ class UsuarioCreateForm(ModelForm): def __init__(self, *args, **kwargs): - super(UsuarioCreateForm, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) row0 = to_row([('username', 12)]) diff --git a/sapl/base/views.py b/sapl/base/views.py index e41b9e9de..00271babc 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1329,17 +1329,19 @@ class CreateUsuarioView(PermissionRequiredMixin, CreateView): model = get_user_model() form_class = UsuarioCreateForm success_message = 'Usuário criado com sucesso!' + fail_message = 'Usuário não criado!' permission_required = ('base.add_appconfig',) def get_success_url(self): return reverse('sapl.base:usuario') def form_valid(self, form): - data = form.cleaned_data new_user = get_user_model().objects.create( - username=data['username'], email=data['email']) + username=data['username'], + email=data['email'] + ) new_user.first_name = data['firstname'] new_user.last_name = data['lastname'] new_user.set_password(data['password1']) @@ -1354,6 +1356,10 @@ class CreateUsuarioView(PermissionRequiredMixin, CreateView): messages.success(self.request, self.success_message) return HttpResponseRedirect(self.get_success_url()) + def form_invalid(self, form): + messages.error(self.request, self.fail_message) + return super().form_invalid(form) + class DeleteUsuarioView(PermissionRequiredMixin, DeleteView): model = get_user_model()