From fbc1a3f4734cfc3125bd46c2d381678ed10fa3eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Rodrigues?= Date: Tue, 17 Dec 2019 13:00:36 -0300 Subject: [PATCH] Fix #3059 (#3060) --- sapl/materia/views.py | 11 ++++++++++- sapl/protocoloadm/views.py | 32 ++++++++++++++++++++++++++------ 2 files changed, 36 insertions(+), 7 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 4ae4b4042..7cb3372d0 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -223,7 +223,16 @@ class CriarProtocoloMateriaView(CreateView): return context def form_valid(self, form): - materia = form.save() + materia = form.save() + + materia.user = self.request.user + materia.ip = get_client_ip(self.request) + + tz = timezone.get_current_timezone() + materia.ultima_edicao = tz.localize(datetime.now()) + + materia.save() + username = self.request.user.username try: diff --git a/sapl/protocoloadm/views.py b/sapl/protocoloadm/views.py index 496c3fcaa..af3736824 100755 --- a/sapl/protocoloadm/views.py +++ b/sapl/protocoloadm/views.py @@ -883,12 +883,22 @@ class ProtocoloMateriaView(PermissionRequiredMixin, CreateView): protocolo.user_data_hora_manual = '' protocolo.ip_data_hora_manual = '' protocolo.save() + data = form.cleaned_data if data['vincular_materia'] == 'True': - materia = MateriaLegislativa.objects.get(ano=data['ano_materia'], - numero=data['numero_materia'], - tipo=data['tipo_materia']) + materia = MateriaLegislativa.objects.get( + ano=data['ano_materia'], + numero=data['numero_materia'], + tipo=data['tipo_materia'] + ) + materia.numero_protocolo = protocolo.numero + materia.user = self.request.user + materia.ip = get_client_ip(self.request) + + tz = timezone.get_current_timezone() + materia.ultima_edicao = tz.localize(datetime.now()) + materia.save() return redirect(self.get_success_url(protocolo)) @@ -1464,10 +1474,20 @@ class DesvincularMateriaView(PermissionRequiredMixin, FormView): return reverse('sapl.protocoloadm:protocolo') def form_valid(self, form): - materia = MateriaLegislativa.objects.get(numero=form.cleaned_data['numero'], - ano=form.cleaned_data['ano'], - tipo=form.cleaned_data['tipo']) + materia = MateriaLegislativa.objects.get( + numero=form.cleaned_data['numero'], + ano=form.cleaned_data['ano'], + tipo=form.cleaned_data['tipo'] + ) + materia.numero_protocolo = None + + materia.user = self.request.user + materia.ip = get_client_ip(self.request) + + tz = timezone.get_current_timezone() + materia.ultima_edicao = tz.localize(datetime.now()) + materia.save() return redirect(self.get_success_url())