From 8574382e3b430a3e212eb5555d9f1c7a3eccb54d Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Mon, 29 Aug 2016 12:43:12 -0300 Subject: [PATCH] Cria telas de pesquisa e listagem da pesquisa --- sapl/base/forms.py | 76 ++++++++++++++++++- sapl/base/urls.py | 6 +- sapl/base/views.py | 42 +++++++++- sapl/materia/views.py | 5 -- .../RelatorioMateriasPorAutor_filter.html | 64 ++++++++++++++++ sapl/templates/base/relatorios_list.html | 14 ++-- 6 files changed, 190 insertions(+), 17 deletions(-) create mode 100644 sapl/templates/base/RelatorioMateriasPorAutor_filter.html diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 5f69f086c..6fcdcf5de 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -1,14 +1,88 @@ +import django_filters +from crispy_forms.helper import FormHelper +from crispy_forms.layout import HTML, Button, Fieldset, Layout from django import forms from django.contrib.auth.forms import AuthenticationForm from django.core.exceptions import ValidationError +from django.db import models from django.forms import ModelForm +from django.utils.translation import ugettext_lazy as _ +from sapl.crispy_layout_mixin import form_actions, to_row +from sapl.materia.models import MateriaLegislativa from sapl.settings import MAX_IMAGE_UPLOAD_SIZE -from sapl.utils import ImageThumbnailFileInput +from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, autor_label, + autor_modal) from .models import CasaLegislativa +class RangeWidgetOverride(forms.MultiWidget): + + def __init__(self, attrs=None): + widgets = (forms.DateInput(format='%d/%m/%Y', + attrs={'class': 'dateinput', + 'placeholder': 'Inicial'}), + forms.DateInput(format='%d/%m/%Y', + attrs={'class': 'dateinput', + 'placeholder': 'Final'})) + super(RangeWidgetOverride, self).__init__(widgets, attrs) + + def decompress(self, value): + if value: + return [value.start, value.stop] + return [None, None] + + def format_output(self, rendered_widgets): + return ''.join(rendered_widgets) + + +class RelatorioMateriasPorAutorFilterSet(django_filters.FilterSet): + + filter_overrides = {models.DateField: { + 'filter_class': django_filters.DateFromToRangeFilter, + 'extra': lambda f: { + 'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')), + 'widget': RangeWidgetOverride} + }} + + autoria__autor = django_filters.CharFilter(widget=forms.HiddenInput()) + + class Meta: + model = MateriaLegislativa + fields = ['tipo', 'data_apresentacao'] + + def __init__(self, *args, **kwargs): + super(RelatorioMateriasPorAutorFilterSet, self).__init__( + *args, **kwargs) + + self.filters['tipo'].label = 'Tipo de Matéria' + + row1 = to_row( + [('tipo', 12)]) + row2 = to_row( + [('data_apresentacao', 12)]) + row3 = to_row( + [('autoria__autor', 0), + (Button('pesquisar', + 'Pesquisar Autor', + css_class='btn btn-primary btn-sm'), 2), + (Button('limpar', + 'limpar Autor', + css_class='btn btn-primary btn-sm'), 10)]) + + self.form.helper = FormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Pesquisar'), + row1, row2, + HTML(autor_label), + HTML(autor_modal), + row3, + form_actions(save_label='Pesquisar')) + ) + + class CasaLegislativaForm(ModelForm): class Meta: diff --git a/sapl/base/urls.py b/sapl/base/urls.py index 03b5b4eb3..e7500d683 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -4,7 +4,7 @@ from django.views.generic.base import TemplateView from .apps import AppConfig from .forms import LoginForm -from .views import CasaLegislativaCrud, HelpView +from .views import CasaLegislativaCrud, HelpView, RelatorioMateriasPorAutorView app_name = AppConfig.name @@ -17,11 +17,13 @@ urlpatterns = [ url(r'^ajuda/(?P\w+)$', HelpView.as_view(), name='help_topic'), url(r'^ajuda/', TemplateView.as_view(template_name='ajuda/index.html'), name='help_base'), - url(r'^casa_legislativa/', include(CasaLegislativaCrud.get_urls())), url(r'^login/$', views.login, { 'template_name': 'base/login.html', 'authentication_form': LoginForm}, name='login'), url(r'^logout/$', views.logout, {'next_page': '/login'}, name='logout'), + + url(r'^relatorio/materia-por-autor$', + RelatorioMateriasPorAutorView.as_view(), name='materia_por_autor'), ] diff --git a/sapl/base/views.py b/sapl/base/views.py index c52b5b6fa..1e4ae15f1 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -1,13 +1,16 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.urlresolvers import reverse from django.http import HttpResponseRedirect +from django.utils.translation import ugettext_lazy as _ from django.views.generic.base import TemplateView +from django_filters.views import FilterView from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, - CrudDetailView, CrudUpdateView) + CrudDetailView, CrudUpdateView, make_pagination) +from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.utils import permissao_tb_aux -from .forms import CasaLegislativaForm +from .forms import CasaLegislativaForm, RelatorioMateriasPorAutorFilterSet from .models import CasaLegislativa @@ -15,6 +18,41 @@ def get_casalegislativa(): return CasaLegislativa.objects.first() +class RelatorioMateriasPorAutorView(FilterView): + model = MateriaLegislativa + filterset_class = RelatorioMateriasPorAutorFilterSet + paginate_by = 10 + template_name = 'base/RelatorioMateriasPorAutor_filter.html' + + def get_filterset_kwargs(self, filterset_class): + super(RelatorioMateriasPorAutorView, + self).get_filterset_kwargs(filterset_class) + + kwargs = {'data': self.request.GET or None} + qs = self.get_queryset() + + return kwargs + + def get_context_data(self, **kwargs): + context = super(RelatorioMateriasPorAutorView, + self).get_context_data(**kwargs) + + context['title'] = _('Matérias por Autor') + + qtdes = {} + for tipo in TipoMateriaLegislativa.objects.all(): + qs = kwargs['object_list'] + qtde = len(qs.filter(tipo_id=tipo.id)) + if qtde > 0: + qtdes[tipo] = qtde + context['qtdes'] = qtdes + + qr = self.request.GET.copy() + context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + + return context + + class CasaLegislativaCrud(Crud): model = CasaLegislativa help_path = '' diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 35f4eef50..57a804be9 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -929,11 +929,6 @@ class MateriaLegislativaPesquisaView(FilterView): context['title'] = _('Pesquisar Matéria Legislativa') - paginator = context['paginator'] - page_obj = context['page_obj'] - context['page_range'] = make_pagination( - page_obj.number, paginator.num_pages) - self.filterset.form.fields['o'].label = _('Ordenação') qr = self.request.GET.copy() diff --git a/sapl/templates/base/RelatorioMateriasPorAutor_filter.html b/sapl/templates/base/RelatorioMateriasPorAutor_filter.html new file mode 100644 index 000000000..2df425be5 --- /dev/null +++ b/sapl/templates/base/RelatorioMateriasPorAutor_filter.html @@ -0,0 +1,64 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block base_content %} + {% if not filter_url %} + {% crispy filter.form %} + {% endif %} + + {% if filter_url %} + +



+ + + + + + + + + + + {% for key, value in qtdes.items %} + + + + + {% endfor %} + +
QUADRO GERAL
Tipo MatériaQuantidade
{{key.sigla}} - {{key}}{{value}}
+ + + + + + + + + + + {% for materia in object_list %} + + + + + + {% endfor %} + +
MatériaEmentaAutor(es)
+ {{materia.tipo.sigla}} {{materia.numero}}/{{materia.ano}} + {{materia.ementa}} + {% for autor in materia.autoria_set.all %} + {{autor.autor}}
+ {% endfor %} +
+ + {% include "paginacao.html" %} + + + {% endif %} + +{% endblock base_content %} diff --git a/sapl/templates/base/relatorios_list.html b/sapl/templates/base/relatorios_list.html index b4ffc0da3..d27a7914e 100644 --- a/sapl/templates/base/relatorios_list.html +++ b/sapl/templates/base/relatorios_list.html @@ -14,15 +14,15 @@ Matérias em tramitação - Matérias Legislativas por Ano, Tipo, Local atual e Status da Tramitação informados. + Matérias Legislativas por Ano, Tipo, Local atual e Status da Tramitação informados. - Proposituras por Tipo, Autor e Ano - Número de matérias legislativas, agrupadas por Tipo e Autor e Ano selecionado. + Matérias por Autor + Listagem e totalização de matérias por autor, com filtros para tipo e período. - Proposituras por Autor - Resumo de Proposituras de um determinado ano, agrupadas por Autor. + Matérias por Ano, Autor e Tipo + Totalização anual de matérias agrupadas por autor e tipo. Presença nas sessões @@ -30,11 +30,11 @@ Atas - Matérias Legislativas por Ano, Tipo, Local atual e Status da Tramitação informados. + Atas de Sessão Plenária. Histórico de tramitações - Histórico de tramitações por período e local informados. + Histórico de tramitações por período e local informados.