From c4225765bb3682f9cd90a9643871f8a2c9a7a62d Mon Sep 17 00:00:00 2001 From: VictorFabreF Date: Tue, 20 Feb 2018 17:46:12 -0300 Subject: [PATCH] Fix #1705 (#1710) * Fix #1705 * Fix #1705 --- sapl/materia/forms.py | 25 ++++++++++++++++--- .../migrations/0023_proposicao_hash_code.py | 20 +++++++++++++++ sapl/materia/models.py | 4 +++ sapl/materia/tests/test_materia.py | 1 + .../materia/prop_pendentes_list.html | 2 ++ sapl/templates/materia/proposicao_detail.html | 11 ++++++++ 6 files changed, 60 insertions(+), 3 deletions(-) create mode 100644 sapl/materia/migrations/0023_proposicao_hash_code.py diff --git a/sapl/materia/forms.py b/sapl/materia/forms.py index a693c1a3f..58a9811f9 100644 --- a/sapl/materia/forms.py +++ b/sapl/materia/forms.py @@ -40,7 +40,7 @@ from sapl.utils import (RANGE_ANOS, YES_NO_CHOICES, ChoiceWithoutValidationField, MateriaPesquisaOrderingFilter, RangeWidgetOverride, autor_label, autor_modal, models_with_gr_for_model, - qs_override_django_filter) + qs_override_django_filter, gerar_hash_arquivo) from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, DocumentoAcessorio, Numeracao, Proposicao, Relatoria, @@ -1113,9 +1113,14 @@ class ProposicaoForm(forms.ModelForm): widget=widgets.HiddenInput(), required=False) + receber_recibo = forms.TypedChoiceField( + choices=YES_NO_CHOICES, + label='Deseja protocolar com recibo?') + class Meta: model = Proposicao fields = ['tipo', + 'receber_recibo', 'descricao', 'texto_original', 'materia_de_vinculo', @@ -1123,11 +1128,13 @@ class ProposicaoForm(forms.ModelForm): 'tipo_materia', 'numero_materia', 'ano_materia', - 'tipo_texto'] + 'tipo_texto', + 'hash_code'] widgets = { 'descricao': widgets.Textarea(attrs={'rows': 4}), - 'tipo': TipoProposicaoSelect()} + 'tipo': TipoProposicaoSelect(), + 'hash_code': forms.HiddenInput(),} def __init__(self, *args, **kwargs): self.texto_articulado_proposicao = sapl.base.models.AppConfig.attr( @@ -1149,11 +1156,13 @@ class ProposicaoForm(forms.ModelForm): to_column(('ano_materia', 4)) ), + to_column(('receber_recibo', 3)), to_column( (Alert('teste', css_class="ementa_materia hidden alert-info", dismiss=False), 12)), to_column(('descricao', 12)), + ] if self.texto_articulado_proposicao: @@ -1196,6 +1205,7 @@ class ProposicaoForm(forms.ModelForm): "Arquivo muito grande. ( > {0}MB )".format(max_size)) return texto_original + def clean(self): super(ProposicaoForm, self).clean() @@ -1221,6 +1231,7 @@ class ProposicaoForm(forms.ModelForm): def save(self, commit=True): cd = self.cleaned_data inst = self.instance + if inst.pk: if 'tipo_texto' in cd: @@ -1245,6 +1256,14 @@ class ProposicaoForm(forms.ModelForm): inst.numero_proposicao = ( numero__max + 1) if numero__max else 1 + inst.save() + if cd['receber_recibo'] == 'True': + inst.hash_code = '' + else: + _hash = gerar_hash_arquivo(inst.texto_original.path, str(inst.pk)) + + inst.hash_code = _hash + inst.save() return inst diff --git a/sapl/materia/migrations/0023_proposicao_hash_code.py b/sapl/materia/migrations/0023_proposicao_hash_code.py new file mode 100644 index 000000000..ded096aa5 --- /dev/null +++ b/sapl/materia/migrations/0023_proposicao_hash_code.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.13 on 2018-02-20 17:53 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('materia', '0022_auto_20180206_0908'), + ] + + operations = [ + migrations.AddField( + model_name='proposicao', + name='hash_code', + field=models.CharField(blank=True, max_length=200, verbose_name='Código do Documento'), + ), + ] diff --git a/sapl/materia/models.py b/sapl/materia/models.py index 899cca6de..d82954262 100644 --- a/sapl/materia/models.py +++ b/sapl/materia/models.py @@ -649,6 +649,10 @@ class Proposicao(models.Model): numero_proposicao = models.PositiveIntegerField( blank=True, null=True, verbose_name=_('Número')) + hash_code = models.CharField(verbose_name=_('Código do Documento'), + max_length=200, + blank=True) + """ FIXME Campo não é necessário na modelagem e implementação atual para o módulo de proposições. diff --git a/sapl/materia/tests/test_materia.py b/sapl/materia/tests/test_materia.py index bbeec1393..c0a0358d6 100644 --- a/sapl/materia/tests/test_materia.py +++ b/sapl/materia/tests/test_materia.py @@ -465,6 +465,7 @@ def test_proposicao_submit(admin_client): 'autor': autor.pk, 'texto_original': texto, 'salvar': 'salvar', + 'receber_recibo': 'True', }, follow=True) diff --git a/sapl/templates/materia/prop_pendentes_list.html b/sapl/templates/materia/prop_pendentes_list.html index cff6c10b0..ddc1f0363 100644 --- a/sapl/templates/materia/prop_pendentes_list.html +++ b/sapl/templates/materia/prop_pendentes_list.html @@ -14,6 +14,7 @@ Tipo Descrição Autor + Código do Documento @@ -23,6 +24,7 @@ {{ prop.tipo.descricao }} {{ prop.descricao }} {{ prop.autor }} + {{ prop.hash_code }} {% endfor %} diff --git a/sapl/templates/materia/proposicao_detail.html b/sapl/templates/materia/proposicao_detail.html index ee42b7ace..6539a7a0a 100644 --- a/sapl/templates/materia/proposicao_detail.html +++ b/sapl/templates/materia/proposicao_detail.html @@ -135,5 +135,16 @@ {% endif %} + {% if object.hash_code %} + +
+
+

{%field_verbose_name object 'hash_code'%}

+
+
{{object.hash_code}}
+
+
+
+ {% endif %} {% endblock detail_content %}