From ea47cb7b44cfc2c7bc590953d5968e1024a51be3 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Thu, 3 Nov 2016 11:26:16 -0200 Subject: [PATCH] =?UTF-8?q?Add=20opc=20p/=20uso=20de=20Hist=C3=B3rico=20de?= =?UTF-8?q?=20P=C3=BAblica=C3=A7=C3=A3o=20de=20T.A.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/compilacao/forms.py | 28 ++++++++++++++----- ...063_tipotextoarticulado_publicacao_func.py | 20 +++++++++++++ sapl/compilacao/models.py | 6 ++++ sapl/compilacao/views.py | 22 +++++++++++---- sapl/materia/views.py | 9 +++++- sapl/norma/views.py | 4 +++ .../compilacao/textoarticulado_detail.html | 2 +- 7 files changed, 76 insertions(+), 15 deletions(-) create mode 100644 sapl/compilacao/migrations/0063_tipotextoarticulado_publicacao_func.py diff --git a/sapl/compilacao/forms.py b/sapl/compilacao/forms.py index b5b7cc09c..1559b97ef 100644 --- a/sapl/compilacao/forms.py +++ b/sapl/compilacao/forms.py @@ -42,10 +42,18 @@ class TipoTaForm(ModelForm): label=TipoTextoArticulado._meta.get_field( 'descricao').verbose_name) - participacao_social = forms.NullBooleanField( + participacao_social = forms.ChoiceField( label=TipoTextoArticulado._meta.get_field( 'participacao_social').verbose_name, - widget=forms.Select(choices=YES_NO_CHOICES), + choices=YES_NO_CHOICES, + widget=forms.RadioSelect(), + required=True) + + publicacao_func = forms.ChoiceField( + label=TipoTextoArticulado._meta.get_field( + 'publicacao_func').verbose_name, + choices=YES_NO_CHOICES, + widget=forms.RadioSelect(), required=True) class Meta: @@ -54,21 +62,27 @@ class TipoTaForm(ModelForm): 'descricao', 'content_type', 'participacao_social', + 'publicacao_func' ] def __init__(self, *args, **kwargs): row1 = to_row([ - ('sigla', 2), - ('descricao', 4), - ('content_type', 3), - ('participacao_social', 3), + ('sigla', 3), + ('descricao', 5), + ('content_type', 4), + ]) + row2 = to_row([ + (InlineRadios('participacao_social'), 3), + (InlineRadios('publicacao_func'), 3), ]) self.helper = FormHelper() self.helper.layout = SaplFormLayout( Fieldset(_('Identificação Básica'), - row1, css_class="col-md-12")) + row1, css_class="col-md-12"), + Fieldset(_('Funcionalidades'), + row2, css_class="col-md-12")) super(TipoTaForm, self).__init__(*args, **kwargs) diff --git a/sapl/compilacao/migrations/0063_tipotextoarticulado_publicacao_func.py b/sapl/compilacao/migrations/0063_tipotextoarticulado_publicacao_func.py new file mode 100644 index 000000000..53dac62fc --- /dev/null +++ b/sapl/compilacao/migrations/0063_tipotextoarticulado_publicacao_func.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.9.7 on 2016-11-03 11:06 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('compilacao', '0062_auto_20161101_1221'), + ] + + operations = [ + migrations.AddField( + model_name='tipotextoarticulado', + name='publicacao_func', + field=models.NullBooleanField(choices=[(True, 'Sim'), (False, 'Não')], default=True, verbose_name='Histórico de Publicação'), + ), + ] diff --git a/sapl/compilacao/models.py b/sapl/compilacao/models.py index 117a79289..189dea8f2 100644 --- a/sapl/compilacao/models.py +++ b/sapl/compilacao/models.py @@ -81,6 +81,12 @@ class TipoTextoArticulado(models.Model): choices=YES_NO_CHOICES, verbose_name=_('Participação Social')) + publicacao_func = models.NullBooleanField( + default=True, + blank=True, null=True, + choices=YES_NO_CHOICES, + verbose_name=_('Histórico de Publicação')) + class Meta: verbose_name = _('Tipo de Texto Articulado') verbose_name_plural = _('Tipos de Texto Articulados') diff --git a/sapl/compilacao/views.py b/sapl/compilacao/views.py index 086ba8e3c..1de1eaf66 100644 --- a/sapl/compilacao/views.py +++ b/sapl/compilacao/views.py @@ -119,6 +119,15 @@ class IntegracaoTaView(TemplateView): try: if settings.DEBUG or not TipoDispositivo.objects.exists(): self.import_pattern() + + if hasattr(self, 'map_funcs'): + tipo_ta = TipoTextoArticulado.objects.get( + content_type=ContentType.objects.get_for_model(self.model)) + + for key, value in self.map_funcs.items(): + setattr(tipo_ta, key, value) + tipo_ta.save() + except Exception as e: logger.error( string_concat( @@ -144,7 +153,7 @@ class IntegracaoTaView(TemplateView): implemente, ou passe `None` para as chaves que são fixas. """) - mf = self.map_fields + map_fields = self.map_fields item = get_object_or_404(self.model, pk=kwargs['pk']) related_object_type = ContentType.objects.get_for_model(item) @@ -166,15 +175,16 @@ class IntegracaoTaView(TemplateView): else: ta = ta[0] - ta.data = getattr(item, mf['data'], datetime.now()) + ta.data = getattr(item, map_fields['data'], datetime.now()) ta.ementa = getattr( - item, mf['ementa'], _('Integração com %s sem ementa.') % item) - ta.observacao = getattr(item, mf['observacao'], '') - ta.numero = getattr(item, mf['numero'], int('%s%s%s' % ( + item, map_fields['ementa'], _( + 'Integração com %s sem ementa.') % item) + ta.observacao = getattr(item, map_fields['observacao'], '') + ta.numero = getattr(item, map_fields['numero'], int('%s%s%s' % ( int(datetime.now().year), int(datetime.now().month), int(datetime.now().day)))) - ta.ano = getattr(item, mf['ano'], datetime.now().year) + ta.ano = getattr(item, map_fields['ano'], datetime.now().year) ta.save() diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 9b6df196e..718451c78 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -21,7 +21,6 @@ from django.views.generic.base import RedirectView from django.views.generic.edit import FormView from django_filters.views import FilterView -import sapl from sapl.base.models import Autor, CasaLegislativa from sapl.compilacao.views import IntegracaoTaView from sapl.crispy_layout_mixin import SaplFormLayout, form_actions @@ -37,6 +36,7 @@ from sapl.protocoloadm.models import Protocolo from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, autor_modal, gerar_hash_arquivo, get_base_url, montar_row_autor) +import sapl from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, DocumentoAcessorioForm, MateriaLegislativaFilterSet, @@ -52,6 +52,7 @@ from .models import (AcompanhamentoMateria, Anexada, Autoria, DespachoInicial, TipoMateriaLegislativa, TipoProposicao, Tramitacao, UnidadeTramitacao) + OrigemCrud = Crud.build(Origem, '') TipoMateriaCrud = CrudAux.build( @@ -107,6 +108,9 @@ class MateriaTaView(IntegracaoTaView): 'numero': 'numero', 'ano': 'ano', } + map_funcs = { + 'publicacao_func': False + } def get(self, request, *args, **kwargs): """ @@ -130,6 +134,9 @@ class ProposicaoTaView(IntegracaoTaView): 'numero': 'numero_proposicao', 'ano': 'ano', } + map_funcs = { + 'publicacao_func': False + } def get(self, request, *args, **kwargs): """ diff --git a/sapl/norma/views.py b/sapl/norma/views.py index 27b7d7b4c..d0b13d117 100644 --- a/sapl/norma/views.py +++ b/sapl/norma/views.py @@ -36,6 +36,10 @@ class NormaTaView(IntegracaoTaView): 'ano': 'ano', } + map_funcs = { + 'publicacao_func': True + } + def get(self, request, *args, **kwargs): """ Para manter a app compilacao isolada das outras aplicações, diff --git a/sapl/templates/compilacao/textoarticulado_detail.html b/sapl/templates/compilacao/textoarticulado_detail.html index f1d472f0a..29f9bcb92 100644 --- a/sapl/templates/compilacao/textoarticulado_detail.html +++ b/sapl/templates/compilacao/textoarticulado_detail.html @@ -13,7 +13,7 @@ {% trans 'Início' %} {%endif%} - {% if perms.compilacao.list_publicacao %} + {% if object.tipo_ta.publicacao_func %}
  • {% model_verbose_name_plural 'sapl.compilacao.models.Publicacao' %}
  • {% endif %} {% if perms.compilacao.view_dispositivo_notificacoes %}