diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index 85e202139..7a2bf61d8 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -1826,12 +1826,19 @@ class ProposicaoForm(FileFieldCheckMixin, forms.ModelForm): 'ano_materia', 'tipo_texto', 'hash_code', - 'numero_materia_futuro'] + 'numero_materia_futuro', + 'user', + 'ip', + 'ultima_edicao'] widgets = { 'descricao': widgets.Textarea(attrs={'rows': 4}), 'tipo': TipoProposicaoSelect(), - 'hash_code': forms.HiddenInput(), } + 'hash_code': forms.HiddenInput(), + 'user': forms.HiddenInput(), + 'ip': forms.HiddenInput(), + 'ultima_edicao': forms.HiddenInput() + } def __init__(self, *args, **kwargs): self.texto_articulado_proposicao = AppConfig.attr( diff --git a/sapl/materia/migrations/0052_auto_20190731_1554.py b/sapl/materia/migrations/0052_auto_20190731_1554.py new file mode 100644 index 000000000..e78a0f58c --- /dev/null +++ b/sapl/materia/migrations/0052_auto_20190731_1554.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-31 18:54 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('materia', '0051_auto_20190703_1414'), + ] + + operations = [ + migrations.AddField( + model_name='proposicao', + name='ip', + field=models.CharField(blank=True, default='', max_length=30, verbose_name='IP'), + ), + migrations.AddField( + model_name='proposicao', + name='user', + field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL, verbose_name='Usuário'), + ), + ] diff --git a/sapl/materia/migrations/0053_proposicao_ultima_edicao.py b/sapl/materia/migrations/0053_proposicao_ultima_edicao.py new file mode 100644 index 000000000..0a89d6670 --- /dev/null +++ b/sapl/materia/migrations/0053_proposicao_ultima_edicao.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.20 on 2019-07-31 22:26 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0052_auto_20190731_1554'), + ] + + operations = [ + migrations.AddField( + model_name='proposicao', + name='ultima_edicao', + field=models.DateTimeField(blank=True, null=True, verbose_name='Data e Hora da Edição'), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index d9a5e344a..7a7f305ff 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -833,6 +833,24 @@ class Proposicao(models.Model): documento_gerado = models.ForeignKey( DocumentoAcessorio, blank=True, null=True)""" + user = models.ForeignKey( + get_settings_auth_user_model(), + verbose_name=_('Usuário'), + on_delete=models.PROTECT, + null=True, + blank=True + ) + ip = models.CharField( + verbose_name=_('IP'), + max_length=30, + blank=True, + default='' + ) + ultima_edicao = models.DateTimeField( + verbose_name=_('Data e Hora da Edição'), + blank=True, null=True + ) + @property def perfis(self): return self.tipo.perfis.all() diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 21c590349..5adcc38d1 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -772,6 +772,11 @@ class ProposicaoCrud(Crud): context['title'] = '%s (%s)' % ( self.object, self.object.autor) + + context['user'] = self.request.user + context['proposicao'] = Proposicao.objects.get( + pk=self.kwargs['pk'] + ) return context def get(self, request, *args, **kwargs): @@ -940,6 +945,40 @@ class ProposicaoCrud(Crud): class UpdateView(BaseLocalMixin, Crud.UpdateView): logger = logging.getLogger(__name__) + form_class = ProposicaoForm + + def form_valid(self, form): + tz = timezone.get_current_timezone() + + objeto_antigo = Proposicao.objects.get( + pk=self.kwargs['pk'] + ) + dict_objeto_antigo = objeto_antigo.__dict__ + + tipo_texto = self.request.POST.get('tipo_texto', '') + if tipo_texto=='D' and objeto_antigo.texto_articulado.exists() or tipo_texto=='T' and not objeto_antigo.texto_articulado.exists(): + self.object.user = self.request.user + self.object.ip = get_client_ip(self.request) + self.object.ultima_edicao = tz.localize(datetime.now()) + self.object.save() + + self.object = form.save() + dict_objeto_novo = self.object.__dict__ + + atributos = [ + 'tipo_id', 'descricao', 'observacao', 'texto_original', + 'materia_de_vinculo_id' + ] + + for atributo in atributos: + if dict_objeto_antigo[atributo] != dict_objeto_novo[atributo]: + self.object.user = self.request.user + self.object.ip = get_client_ip(self.request) + self.object.ultima_edicao = tz.localize(datetime.now()) + self.object.save() + break + + return super().form_valid(form) def _action_is_valid(self, request, *args, **kwargs): @@ -994,6 +1033,17 @@ class ProposicaoCrud(Crud): form_class = ProposicaoForm layout_key = None + def get_initial(self): + initial = super().get_initial() + + initial['user'] = self.request.user + initial['ip'] = get_client_ip(self.request) + + tz = timezone.get_current_timezone() + initial['ultima_edicao'] = tz.localize(datetime.now()) + + return initial + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) context['subnav_template_name'] = '' diff --git a/sapl/templates/materia/proposicao_detail.html b/sapl/templates/materia/proposicao_detail.html index b83946761..b35d3de8b 100644 --- a/sapl/templates/materia/proposicao_detail.html +++ b/sapl/templates/materia/proposicao_detail.html @@ -1,8 +1,8 @@ {% extends "crud/detail.html" %} {% load i18n common_tags %} {% load tz %} -{% block sub_actions %}{{block.super}} - +{% block sub_actions %} + {{block.super}}
{% if object.texto_articulado.exists %} {% trans "Texto Eletrônico" %} @@ -12,9 +12,7 @@ {% endif %}
{% endblock sub_actions%} - {% block editions %} - {% if object.data_envio %} {% if user == object.autor.user %} {% block editions_actions_return %} @@ -26,161 +24,183 @@ {% endblock %} {% endif %} - {% else %} - {% block editions_actions_send %}
{% trans 'Enviar' %}
-
{% trans 'Editar' %} {% trans 'Excluir' %}
{% endblock %} {% endif %} - {% endblock editions %} - - {% block detail_content %} - -

{% model_verbose_name 'sapl.materia.models.Proposicao' %}

-
- -
-
-

{%field_verbose_name object 'tipo'%}

-
-
{{object.tipo}}
-
+
+
+

{%field_verbose_name object 'tipo'%}

+
+
{{object.tipo}}
- {% if object.data_devolucao %} - -
- +
+ {% if object.data_devolucao %} +
+ - - {% else %} - - {% if object.data_envio %} -
-
+
+ {% else %} + {% if object.data_envio %} +
+

{%field_verbose_name object 'data_envio' %}

-
-
{{object.data_envio}}
-
+
+
{{object.data_envio}}
- {% endif %} - - {% if object.data_recebimento %} -
-
+
+ {% endif %} + {% if object.data_recebimento %} +
+

{%field_verbose_name object 'data_recebimento'%}

-
-
{{object.data_recebimento}}
-
+
+
{{object.data_recebimento}}
- {% elif object.data_envio %} -
- +
+ {% elif object.data_envio %} +
+ - {% endif %} +
{% endif %} + {% endif %}
-
-
-
-

{%field_verbose_name object 'descricao'%}

-
-
{{object.descricao}}
-
+
+
+

{%field_verbose_name object 'descricao'%}

+
+
{{object.descricao}}
+
- - {% if object.observacao %}
-
-
-

{%field_verbose_name object 'observacao'%}

-
-
{{object.observacao}}
-
+
+
+

{%field_verbose_name object 'observacao'%}

+
+
{{object.observacao}}
+
{% endif %} -
{% if object.conteudo_gerado_related %} -
-

{% trans "Conteúdo Gerado" %}

-