Browse Source

Adiciona USER, IP e DATETIME da última edição em Proposição (#2908)

* Adicionar novos campos no model Proposicao

* Adicionar migrações

* Adicionar novos widgets em ProposicaoForm

* Salvar e apresentar dados - última edição

* Identificar e salvar timezone

* Salvar e apresentar dados - criação
pull/2758/head
João Rodrigues 5 years ago
committed by Cesar Carvalho
parent
commit
9d91c3218e
  1. 11
      sapl/materia/forms.py
  2. 28
      sapl/materia/migrations/0052_auto_20190731_1554.py
  3. 20
      sapl/materia/migrations/0053_proposicao_ultima_edicao.py
  4. 18
      sapl/materia/models.py
  5. 50
      sapl/materia/views.py
  6. 68
      sapl/templates/materia/proposicao_detail.html

11
sapl/materia/forms.py

@ -1826,12 +1826,19 @@ class ProposicaoForm(FileFieldCheckMixin, forms.ModelForm):
'ano_materia', 'ano_materia',
'tipo_texto', 'tipo_texto',
'hash_code', 'hash_code',
'numero_materia_futuro'] 'numero_materia_futuro',
'user',
'ip',
'ultima_edicao']
widgets = { widgets = {
'descricao': widgets.Textarea(attrs={'rows': 4}), 'descricao': widgets.Textarea(attrs={'rows': 4}),
'tipo': TipoProposicaoSelect(), '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): def __init__(self, *args, **kwargs):
self.texto_articulado_proposicao = AppConfig.attr( self.texto_articulado_proposicao = AppConfig.attr(

28
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'),
),
]

20
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'),
),
]

18
sapl/materia/models.py

@ -833,6 +833,24 @@ class Proposicao(models.Model):
documento_gerado = models.ForeignKey( documento_gerado = models.ForeignKey(
DocumentoAcessorio, blank=True, null=True)""" 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 @property
def perfis(self): def perfis(self):
return self.tipo.perfis.all() return self.tipo.perfis.all()

50
sapl/materia/views.py

@ -772,6 +772,11 @@ class ProposicaoCrud(Crud):
context['title'] = '%s <small>(%s)</small>' % ( context['title'] = '%s <small>(%s)</small>' % (
self.object, self.object.autor) self.object, self.object.autor)
context['user'] = self.request.user
context['proposicao'] = Proposicao.objects.get(
pk=self.kwargs['pk']
)
return context return context
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
@ -940,6 +945,40 @@ class ProposicaoCrud(Crud):
class UpdateView(BaseLocalMixin, Crud.UpdateView): class UpdateView(BaseLocalMixin, Crud.UpdateView):
logger = logging.getLogger(__name__) 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): def _action_is_valid(self, request, *args, **kwargs):
@ -994,6 +1033,17 @@ class ProposicaoCrud(Crud):
form_class = ProposicaoForm form_class = ProposicaoForm
layout_key = None 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): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['subnav_template_name'] = '' context['subnav_template_name'] = ''

68
sapl/templates/materia/proposicao_detail.html

@ -1,8 +1,8 @@
{% extends "crud/detail.html" %} {% extends "crud/detail.html" %}
{% load i18n common_tags %} {% load i18n common_tags %}
{% load tz %} {% load tz %}
{% block sub_actions %}{{block.super}} {% block sub_actions %}
{{block.super}}
<div class="actions btn-group btn-group-sm {%block sub_actions_pull%}{% endblock%}" role="group"> <div class="actions btn-group btn-group-sm {%block sub_actions_pull%}{% endblock%}" role="group">
{% if object.texto_articulado.exists %} {% if object.texto_articulado.exists %}
<a class="btn btn-success" href="{% url 'sapl.materia:proposicao_ta' object.pk%}">{% trans "Texto Eletrônico" %}</a> <a class="btn btn-success" href="{% url 'sapl.materia:proposicao_ta' object.pk%}">{% trans "Texto Eletrônico" %}</a>
@ -12,9 +12,7 @@
{% endif %} {% endif %}
</div> </div>
{% endblock sub_actions%} {% endblock sub_actions%}
{% block editions %} {% block editions %}
{% if object.data_envio %} {% if object.data_envio %}
{% if user == object.autor.user %} {% if user == object.autor.user %}
{% block editions_actions_return %} {% block editions_actions_return %}
@ -26,31 +24,21 @@
</div> </div>
{% endblock %} {% endblock %}
{% endif %} {% endif %}
{% else %} {% else %}
{% block editions_actions_send %} {% block editions_actions_send %}
<div class="actions btn-group" role="group"> <div class="actions btn-group" role="group">
<a href="{{ view.detail_url }}?action=send" class="btn btn-primary">{% trans 'Enviar' %}</a> <a href="{{ view.detail_url }}?action=send" class="btn btn-primary">{% trans 'Enviar' %}</a>
</div> </div>
<div class="actions btn-group" role="group"> <div class="actions btn-group" role="group">
<a href="{{ view.update_url }}" class="btn btn-outline-primary">{% trans 'Editar' %}</a> <a href="{{ view.update_url }}" class="btn btn-outline-primary">{% trans 'Editar' %}</a>
<a href="{{ view.delete_url }}" class="btn btn-outline-primary btn-outline-danger">{% trans 'Excluir' %}</a> <a href="{{ view.delete_url }}" class="btn btn-outline-primary btn-outline-danger">{% trans 'Excluir' %}</a>
</div> </div>
{% endblock %} {% endblock %}
{% endif %} {% endif %}
{% endblock editions %} {% endblock editions %}
{% block detail_content %} {% block detail_content %}
<h2 class="legend">{% model_verbose_name 'sapl.materia.models.Proposicao' %}</h2> <h2 class="legend">{% model_verbose_name 'sapl.materia.models.Proposicao' %}</h2>
<div class="row"> <div class="row">
<div class="col-sm-3"> <div class="col-sm-3">
<div id="div_id_tipo" class="form-group"> <div id="div_id_tipo" class="form-group">
<p class="control-label">{%field_verbose_name object 'tipo'%}</p> <p class="control-label">{%field_verbose_name object 'tipo'%}</p>
@ -60,16 +48,13 @@
</div> </div>
</div> </div>
{% if object.data_devolucao %} {% if object.data_devolucao %}
<div class="col-sm-9"> <div class="col-sm-9">
<div class="alert alert-danger alert-dismissible " role="alert"> <div class="alert alert-danger alert-dismissible " role="alert">
<strong>{% trans "Proposição devolvida em:" %} {{ object.data_devolucao}}</strong> <strong>{% trans "Proposição devolvida em:" %} {{ object.data_devolucao}}</strong>
<div >{% trans "Justificativa:" %} {{object.justificativa_devolucao}}</div> <div >{% trans "Justificativa:" %} {{object.justificativa_devolucao}}</div>
</div> </div>
</div> </div>
{% else %} {% else %}
{% if object.data_envio %} {% if object.data_envio %}
<div class="col-sm-3"> <div class="col-sm-3">
<div id="div_id_data_envio" class="form-group"> <div id="div_id_data_envio" class="form-group">
@ -80,7 +65,6 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if object.data_recebimento %} {% if object.data_recebimento %}
<div class="col-sm-3"> <div class="col-sm-3">
<div id="div_id_data_envio" class="form-group"> <div id="div_id_data_envio" class="form-group">
@ -99,7 +83,6 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
<div id="div_id_descricao" class="form-group"> <div id="div_id_descricao" class="form-group">
@ -110,8 +93,6 @@
</div> </div>
</div> </div>
</div> </div>
{% if object.observacao %} {% if object.observacao %}
<div class="row"> <div class="row">
<div class="col-sm-12"> <div class="col-sm-12">
@ -124,7 +105,6 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
<div class="row"> <div class="row">
{% if object.conteudo_gerado_related %} {% if object.conteudo_gerado_related %}
<div class="col-sm-6"> <div class="col-sm-6">
@ -168,10 +148,8 @@
</div> </div>
</div> </div>
{% endif %} {% endif %}
{% if not AppConfig.receber_recibo_proposicao %} {% if not AppConfig.receber_recibo_proposicao %}
{% if object.hash_code %} {% if object.hash_code %}
<div class="col-sm-12"> <div class="col-sm-12">
<div id="div_id_hash_code" class="form-group"> <div id="div_id_hash_code" class="form-group">
<p class="control-label">{%field_verbose_name object 'hash_code'%}</p> <p class="control-label">{%field_verbose_name object 'hash_code'%}</p>
@ -183,4 +161,46 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
</div> </div>
{% if user.is_superuser %}
<div class="row">
{% if proposicao.user %}
<div class="col-sm-4">
<div id="div_id_user" class="form-group">
<p class="control-label">Usuário</p>
<div class="controls">
<div class="form-control-static">
<div class="dont-break-out">
<a href="{% url 'sapl.base:user_edit' proposicao.user.pk %}">{{ proposicao.user }}</a>
</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if proposicao.ip %}
<div class="col-sm-4">
<div id="div_ip_user" class="form-group">
<p class="control-label">IP</p>
<div class="controls">
<div class="form-control-static">
<div class="dont-break-out">{{ proposicao.ip }}</div>
</div>
</div>
</div>
</div>
{% endif %}
{% if proposicao.ultima_edicao %}
<div class="col-sm-4">
<div id="div_ud_user" class="form-group">
<p class="control-label">Data e Hora da Edição</p>
<div class="controls">
<div class="form-control-static">
<div class="dont-break-out">{{ proposicao.ultima_edicao }}</div>
</div>
</div>
</div>
</div>
{% endif %}
</div>
{% endif %}
{% endblock detail_content %} {% endblock detail_content %}

Loading…
Cancel
Save