diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 21c590349..2a973edc4 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,38 @@ class ProposicaoCrud(Crud): class UpdateView(BaseLocalMixin, Crud.UpdateView): logger = logging.getLogger(__name__) + form_class = ProposicaoForm + + def form_valid(self, form): + 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 = 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 = datetime.now() + self.object.save() + break + + return super().form_valid(form) def _action_is_valid(self, request, *args, **kwargs): @@ -994,6 +1031,14 @@ 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) + + 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" %}

-