From dcb75f0d7ca6ef29e098d6ef1e417fe75eafa554 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 8 Aug 2016 17:53:53 -0300 Subject: [PATCH 01/18] =?UTF-8?q?Habilita=20campos=20de=20mat=C3=A9ria=20s?= =?UTF-8?q?e=20proposi=C3=A7=C3=A3o=20for=20Emenda?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/templates/materia/proposicao_form.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapl/templates/materia/proposicao_form.html b/sapl/templates/materia/proposicao_form.html index d71a27b12..996e72258 100644 --- a/sapl/templates/materia/proposicao_form.html +++ b/sapl/templates/materia/proposicao_form.html @@ -34,7 +34,7 @@ $(function () { disable_fields(); $("#id_tipo").change(function() { - if ($("#id_tipo").val() == 9) { // parecer + if ($('#id_tipo option:selected').text() == 'Emenda') { // parecer enable_fields(); }else { disable_fields(); From bdde858993c8dfe11eed13e8e165a3097c93df19 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 8 Aug 2016 17:54:15 -0300 Subject: [PATCH 02/18] =?UTF-8?q?Torna=20arquivo=20obrigat=C3=B3rio?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../migrations/0039_auto_20160808_1753.py | 42 +++++++++++++++++++ sapl/materia/models.py | 10 ++--- 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100644 sapl/materia/migrations/0039_auto_20160808_1753.py diff --git a/sapl/materia/migrations/0039_auto_20160808_1753.py b/sapl/materia/migrations/0039_auto_20160808_1753.py new file mode 100644 index 000000000..a7473aa59 --- /dev/null +++ b/sapl/materia/migrations/0039_auto_20160808_1753.py @@ -0,0 +1,42 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.5 on 2016-08-08 20:53 +from __future__ import unicode_literals + +from django.db import migrations, models +import sapl.materia.models +import sapl.utils + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0038_auto_20160612_1506'), + ] + + operations = [ + migrations.RemoveField( + model_name='proposicao', + name='data_devolucao', + ), + migrations.AddField( + model_name='proposicao', + name='data_incorporação', + field=models.DateTimeField(blank=True, null=True, verbose_name='Data de Incorporação'), + ), + migrations.AlterField( + model_name='proposicao', + name='data_recebimento', + field=models.DateTimeField(blank=True, null=True, verbose_name='Data de Recebimento'), + ), + migrations.AlterField( + model_name='proposicao', + name='status', + field=models.CharField(blank=True, choices=[('E', 'Enviada'), ('R', 'Recebida'), ('I', 'Incorporada')], max_length=1, verbose_name='Status Proposição'), + ), + migrations.AlterField( + model_name='proposicao', + name='texto_original', + field=models.FileField(default='', upload_to=sapl.materia.models.texto_upload_path, validators=[sapl.utils.restringe_tipos_de_arquivo_txt], verbose_name='Texto Original'), + preserve_default=False, + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index ca433d7a6..0b74e7b9f 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -447,10 +447,10 @@ class Proposicao(models.Model): data_envio = models.DateTimeField( null=True, blank=True, verbose_name=_('Data de Envio')) data_recebimento = models.DateTimeField( - blank=True, null=True, verbose_name=_('Data de Incorporação')) + blank=True, null=True, verbose_name=_('Data de Recebimento')) descricao = models.TextField(max_length=100, verbose_name=_('Descrição')) - data_devolucao = models.DateTimeField( - blank=True, null=True, verbose_name=_('Data de devolução')) + data_incorporação = models.DateTimeField( + blank=True, null=True, verbose_name=_('Data de Incorporação')) justificativa_devolucao = models.CharField( max_length=200, blank=True, @@ -461,7 +461,7 @@ class Proposicao(models.Model): status = models.CharField(blank=True, max_length=1, choices=(('E', 'Enviada'), - ('D', 'Devolvida'), + ('R', 'Recebida'), ('I', 'Incorporada')), verbose_name=_('Status Proposição')) # mutually exclusive (depend on tipo.materia_ou_documento) @@ -470,8 +470,6 @@ class Proposicao(models.Model): documento = models.ForeignKey( DocumentoAcessorio, blank=True, null=True, verbose_name=_('Documento')) texto_original = models.FileField( - blank=True, - null=True, upload_to=texto_upload_path, verbose_name=_('Texto Original'), validators=[restringe_tipos_de_arquivo_txt]) From aa210b1c0771b00e65913a4a8fc64b901e2affae Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 9 Aug 2016 10:33:04 -0300 Subject: [PATCH 03/18] =?UTF-8?q?Gera=20recibo=20do=20envio=20da=20proposi?= =?UTF-8?q?=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/forms.py | 2 +- sapl/materia/models.py | 6 +- sapl/materia/urls.py | 13 ++-- sapl/materia/views.py | 25 ++++++- sapl/templates/crud/confirm_delete.html | 8 ++- sapl/templates/crud/detail.html | 2 +- .../materia/proposicao_confirm_delete.html | 10 +++ sapl/templates/materia/proposicao_detail.html | 6 +- sapl/templates/materia/recibo_proposicao.html | 70 +++++++++++++++++++ sapl/utils.py | 8 +++ 10 files changed, 134 insertions(+), 16 deletions(-) create mode 100644 sapl/templates/materia/proposicao_confirm_delete.html create mode 100644 sapl/templates/materia/recibo_proposicao.html diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index de0ebf143..bf8771654 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -81,7 +81,7 @@ class ProposicaoForm(ModelForm): def clean(self): cleaned_data = self.cleaned_data if 'tipo' in cleaned_data: - if cleaned_data['tipo'].descricao == 'Parecer': + if cleaned_data['tipo'].descricao == 'Emenda': try: materia = MateriaLegislativa.objects.get( tipo_id=cleaned_data['tipo_materia'], diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 0b74e7b9f..f6c0ec39f 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -443,14 +443,16 @@ class TipoProposicao(models.Model): class Proposicao(models.Model): autor = models.ForeignKey(Autor, null=True, blank=True) tipo = models.ForeignKey(TipoProposicao, verbose_name=_('Tipo')) + # XXX data_envio was not null, but actual data said otherwise!!! data_envio = models.DateTimeField( - null=True, blank=True, verbose_name=_('Data de Envio')) + blank=True, null=True, verbose_name=_('Data de Envio')) data_recebimento = models.DateTimeField( blank=True, null=True, verbose_name=_('Data de Recebimento')) - descricao = models.TextField(max_length=100, verbose_name=_('Descrição')) data_incorporação = models.DateTimeField( blank=True, null=True, verbose_name=_('Data de Incorporação')) + + descricao = models.TextField(max_length=100, verbose_name=_('Descrição')) justificativa_devolucao = models.CharField( max_length=200, blank=True, diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index dbc6499fc..38286a6ab 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -9,11 +9,12 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, MateriaLegislativaPesquisaView, MateriaTaView, NumeracaoCrud, OrgaoCrud, OrigemCrud, ProposicaoCrud, ProposicaoTaView, - RegimeTramitacaoCrud, RelatoriaCrud, - StatusTramitacaoCrud, TipoAutorCrud, - TipoDocumentoCrud, TipoFimRelatoriaCrud, - TipoMateriaCrud, TipoProposicaoCrud, - TramitacaoCrud, UnidadeTramitacaoCrud) + ReciboProposicaoView, RegimeTramitacaoCrud, + RelatoriaCrud, StatusTramitacaoCrud, + TipoAutorCrud, TipoDocumentoCrud, + TipoFimRelatoriaCrud, TipoMateriaCrud, + TipoProposicaoCrud, TramitacaoCrud, + UnidadeTramitacaoCrud) from .apps import AppConfig @@ -31,6 +32,8 @@ urlpatterns = [ DocumentoAcessorioCrud.get_urls())), url(r'^proposicao/', include(ProposicaoCrud.get_urls())), + url(r'^proposicao/recibo/(?P\d+)', ReciboProposicaoView.as_view(), + name='recibo-proposicao'), # Integração com Compilação url(r'^materia/(?P[0-9]+)/ta$', diff --git a/sapl/materia/views.py b/sapl/materia/views.py index b63efc737..205ae004e 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -21,7 +21,8 @@ from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudListView, CrudUpdateView, make_pagination) from sapl.crud.masterdetail import MasterDetailCrud from sapl.norma.models import LegislacaoCitada -from sapl.utils import autor_label, autor_modal, get_base_url +from sapl.utils import (autor_label, autor_modal, gerar_hash_arquivo, + get_base_url) from .forms import (AcompanhamentoMateriaForm, AnexadaForm, AutoriaForm, DespachoInicialForm, DocumentoAcessorioForm, @@ -68,7 +69,8 @@ class ProposicaoCrud(Crud): help_path = '' class BaseMixin(CrudBaseMixin): - list_field_names = ['data_envio', 'descricao', 'tipo'] + list_field_names = ['data_envio', 'descricao', + 'tipo', 'data_recebimento'] class CreateView(CrudCreateView): form_class = ProposicaoForm @@ -85,13 +87,15 @@ class ProposicaoCrud(Crud): return 'ProposicaoCreate' class ListView(CrudListView): - ordering = ['-data_envio', 'descricao'] + ordering = ['-data_envio', '-descricao'] def get_rows(self, object_list): for obj in object_list: if obj.data_envio is None: obj.data_envio = 'Em elaboração...' + if obj.data_recebimento is None: + obj.data_recebimento = 'Não recebida' return [self._as_row(obj) for obj in object_list] @@ -112,6 +116,21 @@ class ProposicaoCrud(Crud): kwargs={'pk': proposicao.pk})) +class ReciboProposicaoView(TemplateView): + + template_name = "materia/recibo_proposicao.html" + + def get_context_data(self, **kwargs): + context = super(ReciboProposicaoView, self).get_context_data( + **kwargs) + proposicao = Proposicao.objects.get(pk=self.kwargs['pk']) + context.update({'proposicao': proposicao, + 'hash': gerar_hash_arquivo( + proposicao.texto_original.path, + self.kwargs['pk'])}) + return context + + class RelatoriaCrud(MasterDetailCrud): model = Relatoria parent_field = 'materia' diff --git a/sapl/templates/crud/confirm_delete.html b/sapl/templates/crud/confirm_delete.html index 685c0d4ac..0bf9795dd 100644 --- a/sapl/templates/crud/confirm_delete.html +++ b/sapl/templates/crud/confirm_delete.html @@ -5,9 +5,11 @@
{% csrf_token %}
- {% blocktrans %} - Confirma exclusão de "{{ object }}"? - {% endblocktrans %} + {% block msg %} + {% blocktrans %} + Confirma exclusão de "{{ object }}"? + {% endblocktrans %} + {% endblock msg %}
{% trans 'Cancelar' %} diff --git a/sapl/templates/crud/detail.html b/sapl/templates/crud/detail.html index 5eb502d19..c8c983367 100644 --- a/sapl/templates/crud/detail.html +++ b/sapl/templates/crud/detail.html @@ -11,7 +11,7 @@
{% endblock actions %}
- + {% block extra_msg %}{% endblock extra_msg %} {% block detail_content %} {% for fieldset in view.layout_display %}

{{ fieldset.legend }}

diff --git a/sapl/templates/materia/proposicao_confirm_delete.html b/sapl/templates/materia/proposicao_confirm_delete.html new file mode 100644 index 000000000..be402a125 --- /dev/null +++ b/sapl/templates/materia/proposicao_confirm_delete.html @@ -0,0 +1,10 @@ +{% extends "crud/confirm_delete.html" %} +{% load i18n %} + +{% block msg %} + {% if proposicao.data_envio %} + Confirma o retorno de "{{ object }}"? + {% else %} + Confirma exclusão de "{{ object }}"? + {% endif %} +{% endblock msg %} diff --git a/sapl/templates/materia/proposicao_detail.html b/sapl/templates/materia/proposicao_detail.html index 25834b48d..d440dba35 100644 --- a/sapl/templates/materia/proposicao_detail.html +++ b/sapl/templates/materia/proposicao_detail.html @@ -4,7 +4,6 @@ {% block actions %}
{% if proposicao.data_envio %} - {% trans 'Editar Proposição' %} {% trans 'Retornar Proposição Enviada' %} {% else %} {% trans 'Enviar/Editar Proposição' %} @@ -12,3 +11,8 @@ {% endif %}
{% endblock actions %} +{% block extra_msg %} + {% if proposicao.data_envio and not propos.data_recebimento %} +

[Imprimir Recibo]

+ {% endif %} +{% endblock extra_msg %} diff --git a/sapl/templates/materia/recibo_proposicao.html b/sapl/templates/materia/recibo_proposicao.html new file mode 100644 index 000000000..a8b15d2b7 --- /dev/null +++ b/sapl/templates/materia/recibo_proposicao.html @@ -0,0 +1,70 @@ +{% load i18n %} +{% load crispy_forms_tags %} +{% load static %} + +{% block detail_content %} + + +
+ +
+ +
+ + + + + + + +
+ Logotipo +
+
+ {% if nome %} + {{ nome }} {% trans 'de' %} {{ municipio }} - {{ uf }} + {% else %} + {% trans 'Sem Nome Cadastrado' %} + {% endif %} +
+ {% trans 'Sistema de Apoio ao Processo Legislativo' %} +
RECIBO DE ENVIO DE PROPOSIÇÃO
+ +

+ + + + + + + + + + + + + +
Código do Documento: {{hash}}Tipo de Proposição: {{proposicao.tipo.descricao}}
Autor: {{proposicao.autor}}Data de Envio: {{proposicao.data_envio|date:"d/m/Y H:i:s"}}
Descrição: {{proposicao.descricao}}
+ +

+ + + + + + + +
+ Declaro que o conteúdo do texto impresso em anexo é idêntico ao conteúdo enviado eletronicamente por meio do sistema SAPL para esta proposição. +



________________________________________________________________
{{proposicao.autor}}
+{% endblock detail_content %} diff --git a/sapl/utils.py b/sapl/utils.py index c4a6f8a70..08b0dbeaf 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -1,3 +1,4 @@ +import hashlib from datetime import date from functools import wraps @@ -218,3 +219,10 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim): maior_inicio = max(a_inicio, b_inicio) menor_fim = min(a_fim, b_fim) return maior_inicio <= menor_fim + + +def gerar_hash_arquivo(arquivo, pk, hasher=hashlib.md5(), blocksize=65536): + with open(arquivo, 'rb') as arq: + for chunk in iter(lambda: arq.read(blocksize), b''): + hasher.update(chunk) + return 'P' + hasher.hexdigest() + '/' + pk From eacc95143304805aacdcac828377f5dec5db53bd Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 9 Aug 2016 11:06:48 -0300 Subject: [PATCH 04/18] =?UTF-8?q?Gera=20hash=20da=20proposi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/utils.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/sapl/utils.py b/sapl/utils.py index 08b0dbeaf..922dc90f4 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -221,8 +221,12 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim): return maior_inicio <= menor_fim -def gerar_hash_arquivo(arquivo, pk, hasher=hashlib.md5(), blocksize=65536): - with open(arquivo, 'rb') as arq: - for chunk in iter(lambda: arq.read(blocksize), b''): - hasher.update(chunk) - return 'P' + hasher.hexdigest() + '/' + pk +def gerar_hash_arquivo(arquivo, pk, block_size=2**20): + md5 = hashlib.md5() + file = open(arquivo, 'rb') + while True: + data = file.read(block_size) + if not data: + break + md5.update(data) + return 'P' + md5.hexdigest() + '/' + pk From e44759975726e68d294f8316685a86f69bbdc6a1 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 9 Aug 2016 11:16:59 -0300 Subject: [PATCH 05/18] =?UTF-8?q?Muda=20formato=20como=20data=20=C3=A9=20m?= =?UTF-8?q?ostrada=20na=20listagem?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/views.py | 2 ++ sapl/utils.py | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 205ae004e..e06359f7e 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -94,6 +94,8 @@ class ProposicaoCrud(Crud): for obj in object_list: if obj.data_envio is None: obj.data_envio = 'Em elaboração...' + else: + obj.data_envio = obj.data_envio.strftime("%d/%m/%Y %H:%M") if obj.data_recebimento is None: obj.data_recebimento = 'Não recebida' diff --git a/sapl/utils.py b/sapl/utils.py index 922dc90f4..28492f45e 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -223,9 +223,9 @@ def intervalos_tem_intersecao(a_inicio, a_fim, b_inicio, b_fim): def gerar_hash_arquivo(arquivo, pk, block_size=2**20): md5 = hashlib.md5() - file = open(arquivo, 'rb') + arq = open(arquivo, 'rb') while True: - data = file.read(block_size) + data = arq.read(block_size) if not data: break md5.update(data) From caa90ebec120e16e4a5a9560524028497610107d Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 9 Aug 2016 11:41:36 -0300 Subject: [PATCH 06/18] =?UTF-8?q?Altera=20label=20do=20bot=C3=A3o=20de=20e?= =?UTF-8?q?nviar=20proposi=C3=A7=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/templates/materia/proposicao_detail.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sapl/templates/materia/proposicao_detail.html b/sapl/templates/materia/proposicao_detail.html index d440dba35..65e2ae86a 100644 --- a/sapl/templates/materia/proposicao_detail.html +++ b/sapl/templates/materia/proposicao_detail.html @@ -6,7 +6,7 @@ {% if proposicao.data_envio %} {% trans 'Retornar Proposição Enviada' %} {% else %} - {% trans 'Enviar/Editar Proposição' %} + {% trans 'Enviar Proposição' %} {% trans 'Excluir Proposição' %} {% endif %} From f97afb6449a6113062240d7f8a970c7a754761f7 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 9 Aug 2016 12:40:04 -0300 Subject: [PATCH 07/18] =?UTF-8?q?Tela=20de=20recebimento=20de=20proposi?= =?UTF-8?q?=C3=A7=C3=B5es?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/materia/forms.py | 19 ++++++++ sapl/materia/urls.py | 14 +++--- sapl/materia/views.py | 46 +++++++++++++++++-- sapl/templates/base.html | 1 + .../templates/materia/receber_proposicao.html | 4 ++ 5 files changed, 75 insertions(+), 9 deletions(-) create mode 100644 sapl/templates/materia/receber_proposicao.html diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index bf8771654..e53e5976c 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -31,6 +31,25 @@ def em_tramitacao(): (False, 'Não')] +class ReceberProposicaoForm(ModelForm): + cod_hash = forms.CharField(label='Código do Documento', required=True) + + class Meta: + model = Proposicao + exclude = ['texto_original', 'descricao', 'tipo'] + + def __init__(self, *args, **kwargs): + row1 = to_row([('cod_hash', 12)]) + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset( + _('Incorporar Proposição'), row1, + form_actions(save_label='Buscar Proposição') + ) + ) + super(ReceberProposicaoForm, self).__init__(*args, **kwargs) + + class UnidadeTramitacaoForm(ModelForm): class Meta: diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index 38286a6ab..cda704b4a 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -9,12 +9,12 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, MateriaLegislativaPesquisaView, MateriaTaView, NumeracaoCrud, OrgaoCrud, OrigemCrud, ProposicaoCrud, ProposicaoTaView, - ReciboProposicaoView, RegimeTramitacaoCrud, - RelatoriaCrud, StatusTramitacaoCrud, - TipoAutorCrud, TipoDocumentoCrud, - TipoFimRelatoriaCrud, TipoMateriaCrud, - TipoProposicaoCrud, TramitacaoCrud, - UnidadeTramitacaoCrud) + ReceberProposicao, ReciboProposicaoView, + RegimeTramitacaoCrud, RelatoriaCrud, + StatusTramitacaoCrud, TipoAutorCrud, + TipoDocumentoCrud, TipoFimRelatoriaCrud, + TipoMateriaCrud, TipoProposicaoCrud, + TramitacaoCrud, UnidadeTramitacaoCrud) from .apps import AppConfig @@ -34,6 +34,8 @@ urlpatterns = [ url(r'^proposicao/', include(ProposicaoCrud.get_urls())), url(r'^proposicao/recibo/(?P\d+)', ReciboProposicaoView.as_view(), name='recibo-proposicao'), + url(r'^proposicao/receber/', ReceberProposicao.as_view(), + name='receber-proposicao'), # Integração com Compilação url(r'^materia/(?P[0-9]+)/ta$', diff --git a/sapl/materia/views.py b/sapl/materia/views.py index e06359f7e..cda6626e4 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -12,6 +12,7 @@ from django.http.response import HttpResponseRedirect from django.template import Context, loader from django.utils.translation import ugettext_lazy as _ from django.views.generic import CreateView, TemplateView, UpdateView +from django.views.generic.edit import FormMixin from django_filters.views import FilterView from sapl.base.models import CasaLegislativa @@ -27,8 +28,8 @@ from sapl.utils import (autor_label, autor_modal, gerar_hash_arquivo, from .forms import (AcompanhamentoMateriaForm, AnexadaForm, AutoriaForm, DespachoInicialForm, DocumentoAcessorioForm, LegislacaoCitadaForm, MateriaLegislativaFilterSet, - NumeracaoForm, ProposicaoForm, RelatoriaForm, - TramitacaoForm, UnidadeTramitacaoForm, + NumeracaoForm, ProposicaoForm, ReceberProposicaoForm, + RelatoriaForm, TramitacaoForm, UnidadeTramitacaoForm, filtra_tramitacao_destino, filtra_tramitacao_destino_and_status, filtra_tramitacao_status) @@ -64,6 +65,43 @@ class UnidadeTramitacaoCrud(Crud): form_class = UnidadeTramitacaoForm +class ReceberProposicao(CreateView): + template_name = "materia/receber_proposicao.html" + form_class = ReceberProposicaoForm + + def get_context_data(self, **kwargs): + context = super(ReceberProposicao, self).get_context_data( + **kwargs) + context.update({'form': self.get_form()}) + return context + + def post(self, request, *args, **kwargs): + flag = 0 + form = ReceberProposicaoForm(request.POST) + + if form.is_valid(): + proposicoes = Proposicao.objects.filter(data_envio__isnull=False) + for proposicao in proposicoes: + hasher = gerar_hash_arquivo(proposicao.texto_original.path, + str(proposicao.pk)) + if hasher == form.cleaned_data['cod_hash']: + proposicao.data_recebimento = datetime.now() + proposicao.save() + flag = 1 + + if flag == 0: + msg = 'Proposição não encontrada!' + return self.render_to_response({'form': form, 'msg': msg}) + + msg = 'Proposição recebida!' + return self.render_to_response({'form': form, 'msg': msg}) + else: + return self.render_to_response({'form': form}) + + def get_success_url(self): + return reverse('sapl.materia:receber-proposicao') + + class ProposicaoCrud(Crud): model = Proposicao help_path = '' @@ -98,6 +136,9 @@ class ProposicaoCrud(Crud): obj.data_envio = obj.data_envio.strftime("%d/%m/%Y %H:%M") if obj.data_recebimento is None: obj.data_recebimento = 'Não recebida' + else: + obj.data_recebimento = obj.data_recebimento.strftime( + "%d/%m/%Y %H:%M") return [self._as_row(obj) for obj in object_list] @@ -119,7 +160,6 @@ class ProposicaoCrud(Crud): class ReciboProposicaoView(TemplateView): - template_name = "materia/recibo_proposicao.html" def get_context_data(self, **kwargs): diff --git a/sapl/templates/base.html b/sapl/templates/base.html index 93dcc665f..5e0eabfe9 100644 --- a/sapl/templates/base.html +++ b/sapl/templates/base.html @@ -57,6 +57,7 @@