From 28139f6a78421311ac6f8755b6a54c02c0bbf322 Mon Sep 17 00:00:00 2001 From: Cesar Carvalho Date: Fri, 14 Jun 2019 14:32:13 -0300 Subject: [PATCH] HOT-FIX: Adiciona Autor como PrimeiroAutor ao criar Materia Legislativa --- sapl/materia/forms.py | 2 +- sapl/materia/views.py | 11 +++++------ 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 8b33a7f55..8955ebc31 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -285,7 +285,7 @@ class MateriaLegislativaForm(FileFieldCheckMixin, ModelForm): materia = super(MateriaLegislativaForm, self).save(commit) materia.save() - + if self.cleaned_data['autor']: autoria = Autoria() autoria.primeiro_autor = primeiro_autor diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 4d31993dd..e1c7f099c 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -1619,14 +1619,13 @@ class MateriaLegislativaCrud(Crud): form_class = MateriaLegislativaForm - def form_valid(self, form): - self.object = form.instance + def get_initial(self): + initial = super(CreateView, self).get_initial() - self.object.user = self.request.user - self.object.ip = get_client_ip(self.request) - self.object.save() + initial['user'] = self.request.user + initial['ip'] = get_client_ip(self.request) - return super().form_valid(form) + return initial @property def cancel_url(self):