From 9a90c214ddffacc60d84b8fd27c031a062b0037f Mon Sep 17 00:00:00 2001 From: Cesar Carvalho Date: Thu, 13 Dec 2018 17:33:43 -0200 Subject: [PATCH] normas por mes concluida e inicio normas vigencia --- sapl/base/forms.py | 52 +++++++++++++++++++ sapl/base/urls.py | 7 ++- sapl/base/views.py | 47 +++++++++++++---- .../base/RelatorioNormaMes_filter.html | 50 +++++++++++------- .../base/RelatorioNormasVigencia_filter.html | 48 +++++++++++++++++ sapl/templates/base/relatorios_list.html | 8 ++- 6 files changed, 178 insertions(+), 34 deletions(-) create mode 100644 sapl/templates/base/RelatorioNormasVigencia_filter.html diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 044b99f61..a42ca9b59 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -729,6 +729,58 @@ class RelatorioNormasMesFilterSet(django_filters.FilterSet): return parent.distinct().order_by('data') +class RelatorioNormasVigenciaFilterSet(django_filters.FilterSet): + + ano = django_filters.ChoiceFilter(required=True, + label='Ano da Norma', + choices=RANGE_ANOS) + + vigencia = forms.ChoiceField( + label=_('Vigente'), + choices=[(True, "Vigente"), (False, "Não vigente")], + widget=forms.RadioSelect(), + required=True, + help_text=_('Se vc está trocando ou removendo o usuário deste Autor, ' + 'como o Sistema deve proceder com o usuário que está sendo' + ' desvinculado?')) + + # filter_overrides = {models.DateField: { + # 'filter_class': django_filters.DateFromToRangeFilter, + # 'extra': lambda f: { + # 'label': '%s (%s)' % (f.verbose_name, _('Ano')), + # 'widget': RangeWidgetOverride} + # }} + @property + def qs(self): + parent = super(RelatorioNormasVigenciaFilterSet, self).qs + return parent.distinct().order_by('data') + + class Meta: + model = NormaJuridica + # fields = ['ano', 'vigencia'] + + def __init__(self, *args, **kwargs): + super(RelatorioNormasVigenciaFilterSet, self).__init__( + *args, **kwargs) + + self.filters['ano'].label = 'Ano' + # self.filters['vigencia'].label = 'Vigência' + self.form.fields['ano'].required = True + # self.form.fields['vigencia'].required = True + + row1 = to_row([('ano', 12)]) + # row2 = to_row([('vigencia', 12)]) + + self.form.helper = FormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Normas por vigência.'), + row1, + form_actions(label='Pesquisar')) + ) + + + class RelatorioPresencaSessaoFilterSet(django_filters.FilterSet): filter_overrides = {models.DateField: { diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 911006c6e..39e017bd1 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -24,7 +24,8 @@ from .views import (AlterarSenha, AppConfigCrud, CasaLegislativaCrud, RelatorioMateriasTramitacaoView, RelatorioPresencaSessaoView, RelatorioReuniaoView, SaplSearchView, - RelatorioAtosPublicadosMesView) + RelatorioNormasPublicadasMesView, + RelatorioNormasVigenciaView) app_name = AppConfig.name @@ -90,7 +91,9 @@ urlpatterns = [ url(r'^sistema/relatorios/materia-por-autor$', RelatorioMateriasPorAutorView.as_view(), name='materia_por_autor'), url(r'^sistema/relatorios/relatorio-por-mes$', - RelatorioAtosPublicadosMesView.as_view(), name='atos_por_mes'), + RelatorioNormasPublicadasMesView.as_view(), name='normas_por_mes'), + url(r'^sistema/relatorios/relatorio-por-vigencia$', + RelatorioNormasVigenciaView.as_view(), name='normas_por_vigencia'), url(r'^sistema/relatorios/materia-por-ano-autor-tipo$', RelatorioMateriasPorAnoAutorTipoView.as_view(), name='materia_por_ano_autor_tipo'), diff --git a/sapl/base/views.py b/sapl/base/views.py index 1002c2fed..0b4329e2e 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1,5 +1,6 @@ import logging import os +import collections from django.contrib.auth import get_user_model from django.contrib.auth.mixins import PermissionRequiredMixin @@ -46,7 +47,8 @@ from .forms import (AlterarSenhaForm, CasaLegislativaForm, RelatorioMateriasTramitacaoilterSet, RelatorioPresencaSessaoFilterSet, RelatorioReuniaoFilterSet, UsuarioCreateForm, - UsuarioEditForm, RelatorioNormasMesFilterSet) + UsuarioEditForm, RelatorioNormasMesFilterSet, + RelatorioNormasVigenciaFilterSet) from .models import AppConfig, CasaLegislativa @@ -745,13 +747,13 @@ class RelatorioMateriasPorAutorView(FilterView): return context -class RelatorioAtosPublicadosMesView(FilterView): +class RelatorioNormasPublicadasMesView(FilterView): model = NormaJuridica filterset_class = RelatorioNormasMesFilterSet template_name = 'base/RelatorioNormaMes_filter.html' def get_context_data(self, **kwargs): - context = super(RelatorioAtosPublicadosMesView, + context = super(RelatorioNormasPublicadasMesView, self).get_context_data(**kwargs) context['title'] = _('Normas') @@ -765,19 +767,44 @@ class RelatorioAtosPublicadosMesView(FilterView): context['show_results'] = show_results_filter_set(qr) context['ano'] = self.request.GET['ano'] - normas_mes = {} + normas_mes = collections.OrderedDict() + meses = {1: 'Janeiro', 2: 'Fevereiro', 3:'Março', 4: 'Abril', 5: 'Maio', 6:'Junho', + 7: 'Julho', 8: 'Agosto', 9:'Setembro', 10:'Outubro', 11:'Novembro', 12:'Dezembro'} + for norma in context['object_list']: + if not meses[norma.data.month] in normas_mes: + normas_mes[meses[norma.data.month]] = [] + normas_mes[meses[norma.data.month]].append(norma) + + context['normas_mes'] = normas_mes + + return context - # for norma in context['object_list']: - # import ipdb; ipdb.set_trace() - # pass - # context['periodo'] = ( - # self.request.GET['data_inicio_0'] + - # ' - ' + self.request.GET['data_inicio_1']) +class RelatorioNormasVigenciaView(FilterView): + model = NormaJuridica + filterset_class = RelatorioNormasVigenciaFilterSet + template_name = 'base/RelatorioNormasVigencia_filter.html' + def get_context_data(self, **kwargs): + context = super(RelatorioNormasVigenciaView, + self).get_context_data(**kwargs) + context['title'] = _('Normas por vigência') + + # Verifica se os campos foram preenchidos + if not self.filterset.form.is_valid(): + return context + + qr = self.request.GET.copy() + context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + context['show_results'] = show_results_filter_set(qr) + context['ano'] = self.request.GET['ano'] + + # import ipdb; ipdb.set_trace() return context + class ListarUsuarioView(PermissionRequiredMixin, ListView): model = get_user_model() template_name = 'auth/user_list.html' diff --git a/sapl/templates/base/RelatorioNormaMes_filter.html b/sapl/templates/base/RelatorioNormaMes_filter.html index 9f5c82acc..1b7fce6fa 100644 --- a/sapl/templates/base/RelatorioNormaMes_filter.html +++ b/sapl/templates/base/RelatorioNormaMes_filter.html @@ -9,30 +9,40 @@ {% if show_results %}
- {% trans 'Fazer nova pesquisa' %} + {% trans 'Fazer nova pesquisa' %}




PARÂMETROS DE PESQUISA:
 Ano: {{ ano }}
-


- - {% for norma in object_list %} - - - - - - - - - - - - - +
+ {% for mes, normas in normas_mes.items %} +
+

Mês: {{ norma.data }}

MatériaNorma
- {{norma.tipo.descricao}} - {{norma.tipo.sigla}} {{norma.numero}}/{{norma.ano}} - {{norma.ementa}}
{{norma.observacao}}
+ + + + + +

Mês: {{ mes }}

+ + + + + + + + + {% for n in normas %} + + + + + {% endfor %} + +
MatériaNorma
+ {{n.tipo.descricao}} - {{n.tipo.sigla}} {{n.numero}}/{{n.ano}} + {{n.ementa}}
{{n.observacao}}
+ {% endfor %} - {% endif %} {% endblock base_content %} diff --git a/sapl/templates/base/RelatorioNormasVigencia_filter.html b/sapl/templates/base/RelatorioNormasVigencia_filter.html new file mode 100644 index 000000000..1b7fce6fa --- /dev/null +++ b/sapl/templates/base/RelatorioNormasVigencia_filter.html @@ -0,0 +1,48 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block base_content %} + {% if not show_results %} + {% crispy filter.form %} + {% endif %} + + {% if show_results %} +
+ {% trans 'Fazer nova pesquisa' %} +
+



+ PARÂMETROS DE PESQUISA:
+  Ano: {{ ano }}
+
+ {% for mes, normas in normas_mes.items %} +
+ + + + + + +

Mês: {{ mes }}

+ + + + + + + + + {% for n in normas %} + + + + + {% endfor %} + +
MatériaNorma
+ {{n.tipo.descricao}} - {{n.tipo.sigla}} {{n.numero}}/{{n.ano}} + {{n.ementa}}
{{n.observacao}}
+
+ {% endfor %} + {% endif %} +{% endblock base_content %} diff --git a/sapl/templates/base/relatorios_list.html b/sapl/templates/base/relatorios_list.html index c6a53d458..461c59f45 100644 --- a/sapl/templates/base/relatorios_list.html +++ b/sapl/templates/base/relatorios_list.html @@ -49,8 +49,12 @@ Audiência Pública com o tipo. - Atos - Atos publicados por mês. + Normas por mês + Normas publicadas por mês. + + + Normas por vigência + Normas vigentes ou não vigentes.