From 4fbe0a95dff5d53c608be7c9c61ba27acccb41d8 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 2 Sep 2016 15:09:26 -0300 Subject: [PATCH] =?UTF-8?q?Implementa=20view=20e=20form=20para=20pesquisa?= =?UTF-8?q?=20de=20presen=C3=A7a=20em=20sess=C3=A3o?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/base/forms.py | 30 ++++++++++++++ sapl/base/urls.py | 6 ++- sapl/base/views.py | 18 ++++++++- .../base/RelatorioPresencaSessao_filter.html | 40 +++++++++++++++++++ sapl/templates/base/relatorios_list.html | 2 +- 5 files changed, 93 insertions(+), 3 deletions(-) create mode 100644 sapl/templates/base/RelatorioPresencaSessao_filter.html diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 5af6ee179..0c11a7a63 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -10,6 +10,7 @@ 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.sessao.models import SessaoPlenaria from sapl.settings import MAX_IMAGE_UPLOAD_SIZE from sapl.utils import (RANGE_ANOS, ImageThumbnailFileInput, autor_label, autor_modal) @@ -37,6 +38,35 @@ class RangeWidgetOverride(forms.MultiWidget): return ''.join(rendered_widgets) +class RelatorioPresencaSessaoFilterSet(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} + }} + + class Meta: + model = SessaoPlenaria + fields = ['data_inicio'] + + def __init__(self, *args, **kwargs): + super(RelatorioPresencaSessaoFilterSet, self).__init__( + *args, **kwargs) + + self.filters['data_inicio'].label = 'Período' + + row1 = to_row([('data_inicio', 12)]) + + self.form.helper = FormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Presença dos parlamentares nas sessões plenárias'), + row1, form_actions(save_label='Pesquisar')) + ) + + class RelatorioHistoricoTramitacaoFilterSet(django_filters.FilterSet): filter_overrides = {models.DateField: { diff --git a/sapl/base/urls.py b/sapl/base/urls.py index b3dcac6ea..88ab866b1 100644 --- a/sapl/base/urls.py +++ b/sapl/base/urls.py @@ -8,7 +8,8 @@ from .views import (CasaLegislativaCrud, HelpView, RelatorioHistoricoTramitacaoView, RelatorioMateriasPorAnoAutorTipoView, RelatorioMateriasPorAutorView, - RelatorioMateriasTramitacaoView) + RelatorioMateriasTramitacaoView, + RelatorioPresencaSessaoView) app_name = AppConfig.name @@ -39,5 +40,8 @@ urlpatterns = [ url(r'^relatorio/historico-tramitacoes$', RelatorioHistoricoTramitacaoView.as_view(), name='historico_tramitacoes'), + url(r'^relatorio/presenca$', + RelatorioPresencaSessaoView.as_view(), + name='presenca_sessao'), ] diff --git a/sapl/base/views.py b/sapl/base/views.py index ca5d735a3..cdaf77e19 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -9,11 +9,13 @@ from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudDetailView, CrudUpdateView) from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa from sapl.utils import permissao_tb_aux +from sapl.sessao.models import SessaoPlenaria from .forms import (CasaLegislativaForm, RelatorioHistoricoTramitacaoFilterSet, RelatorioMateriasPorAnoAutorTipoFilterSet, RelatorioMateriasPorAutorFilterSet, - RelatorioMateriasTramitacaoilterSet) + RelatorioMateriasTramitacaoilterSet, + RelatorioPresencaSessaoFilterSet) from .models import CasaLegislativa @@ -21,6 +23,20 @@ def get_casalegislativa(): return CasaLegislativa.objects.first() +class RelatorioPresencaSessaoView(FilterView): + model = SessaoPlenaria + filterset_class = RelatorioPresencaSessaoFilterSet + template_name = 'base/RelatorioPresencaSessao_filter.html' + + def get_context_data(self, **kwargs): + context = super(RelatorioPresencaSessaoView, + self).get_context_data(**kwargs) + context['title'] = _('Presença dos parlamentares nas sessões') + qr = self.request.GET.copy() + context['filter_url'] = ('&' + qr.urlencode()) if len(qr) > 0 else '' + return context + + class RelatorioHistoricoTramitacaoView(FilterView): model = MateriaLegislativa filterset_class = RelatorioHistoricoTramitacaoFilterSet diff --git a/sapl/templates/base/RelatorioPresencaSessao_filter.html b/sapl/templates/base/RelatorioPresencaSessao_filter.html new file mode 100644 index 000000000..1a8792174 --- /dev/null +++ b/sapl/templates/base/RelatorioPresencaSessao_filter.html @@ -0,0 +1,40 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block base_content %} + {% if not filter_url %} + {% crispy filter.form %} + {% endif %} + + {% if filter_url %} +
+ {% trans 'Fazer nova pesquisa' %} +
+



+ + + + + + + + + + + + + + + + + + + + + + + +
Nome Parlamentar / PartidoSessãoOrdem do Dia
(Qtd)( % )(Qtd)( % )
Nome Teste / Partido Teste1511%116%
+ {% endif %} +{% endblock base_content %} diff --git a/sapl/templates/base/relatorios_list.html b/sapl/templates/base/relatorios_list.html index 49edf946c..ade7fa1f0 100644 --- a/sapl/templates/base/relatorios_list.html +++ b/sapl/templates/base/relatorios_list.html @@ -25,7 +25,7 @@ Totalização anual de matérias agrupadas por autor e tipo. - Presença nas sessões + Presença nas sessões Presença dos parlamentares nas sessões plenárias.