diff --git a/sapl/utils.py b/sapl/utils.py index a94d7dfaf..1b3085da4 100644 --- a/sapl/utils.py +++ b/sapl/utils.py @@ -131,6 +131,23 @@ UF = [ RANGE_ANOS = [(year, year) for year in range(date.today().year, 1889, -1)] +RANGE_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'), +] + +RANGE_DIAS_MES = [(n, n) for n in range(1, 32)] + TIPOS_TEXTO_PERMITIDOS = ( 'application/vnd.oasis.opendocument.text', 'application/x-vnd.oasis.opendocument.text', diff --git a/sessao/forms.py b/sessao/forms.py index b58bed721..d66fa9872 100644 --- a/sessao/forms.py +++ b/sessao/forms.py @@ -64,9 +64,21 @@ from crispy_forms.layout import Fieldset, Layout import crispy_layout_mixin from crispy_layout_mixin import form_actions +from sapl.utils import RANGE_MESES, RANGE_DIAS_MES + from .models import SessaoPlenaria +def pega_anos(): + anos_list = SessaoPlenaria.objects.all().dates('data_inicio', 'year') + anos = [(k.year, k.year) for k in anos_list] + return anos + +ANO_CHOICES = [('', '---------')] + pega_anos() +MES_CHOICES = [('', '---------')] + RANGE_MESES +DIA_CHOICES = [('', '---------')] + RANGE_DIAS_MES + + class PresencaForm(forms.Form): presenca = forms.CharField(required=False, initial=False) parlamentar = forms.CharField(required=False, max_length=20) @@ -113,20 +125,23 @@ class VotacaoEditForm(forms.Form): pass -class PesquisaSessaoPlenaria(django_filters.FilterSet): +class SessaoPlenariaFilterSet(django_filters.FilterSet): + data_inicio__year = django_filters.ChoiceFilter(required=False, + label=u'Ano', + choices=ANO_CHOICES) + data_inicio__month = django_filters.ChoiceFilter(required=False, + label=u'Mês', + choices=MES_CHOICES) + data_inicio__day = django_filters.ChoiceFilter(required=False, + label=u'Dia', + choices=DIA_CHOICES) class Meta: model = SessaoPlenaria - fields = ['data_inicio__year', - 'data_inicio__month', - 'data_inicio__day', - 'tipo', - ] + fields = ['tipo'] def __init__(self, *args, **kwargs): - super(PesquisaSessaoPlenaria, self).__init__(*args, **kwargs) - - # self.filters['tipo'].label = 'Tipo de Matéria' + super(SessaoPlenariaFilterSet, self).__init__(*args, **kwargs) row1 = crispy_layout_mixin.to_row( [('data_inicio__year', 3), diff --git a/sessao/urls.py b/sessao/urls.py index 1e5ce368f..607cf940c 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -9,6 +9,7 @@ from sessao.views import (EditMateriaOrdemDiaView, OradorExpedienteCrud, PainelView, PautaExpedienteDetail, PautaOrdemDetail, PautaSessaoDetailView, PautaSessaoListView, + PesquisarSessaoPlenariaView, PresencaOrdemDiaView, PresencaView, ResumoView, SessaoCrud, SessaoPlenariaView, TipoExpedienteCrud, TipoResultadoVotacaoCrud, TipoSessaoCrud, @@ -74,6 +75,8 @@ urlpatterns = [ MateriaOrdemDiaView.as_view(), name='materiaordemdia_create'), url(r'^(?P\d+)/resumo$', ResumoView.as_view(), name='resumo'), + url(r'^sessao/pesquisar-sessao$', + PesquisarSessaoPlenariaView.as_view(), name='pesquisar_sessao'), url(r'^(?P\d+)/matordemdia/votnom/(?P\d+)/(?P\d+)$', VotacaoNominalView.as_view(), name='votacaonominal'), url(r'^(?P\d+)/matordemdia/votnom/edit/(?P\d+)/(?P\d+)$', diff --git a/sessao/views.py b/sessao/views.py index 99e8d1e63..83bb11b0d 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -9,6 +9,7 @@ from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ from django.views.generic import ListView, TemplateView from django.views.generic.edit import FormMixin +from django_filters.views import FilterView from rest_framework import generics import crud.base @@ -23,7 +24,8 @@ from sessao.serializers import SessaoPlenariaSerializer from django.http.response import HttpResponseRedirect from .forms import (ExpedienteForm, ListMateriaForm, MateriaOrdemDiaForm, - MesaForm, PresencaForm, VotacaoEditForm, VotacaoForm, + MesaForm, PresencaForm, SessaoPlenariaFilterSet, + VotacaoEditForm, VotacaoForm, VotacaoNominalForm, ExpedienteMateriaForm) from .models import (CargoMesa, ExpedienteMateria, ExpedienteSessao, IntegranteMesa, MateriaLegislativa, Orador, @@ -1865,3 +1867,60 @@ class PautaOrdemDetail(SessaoCrud.CrudDetailView): 'norma': norma, 'doc_ace': doc_ace, 'tramitacao': tramitacao}) + + +class PesquisarSessaoPlenariaView(FilterView): + model = SessaoPlenaria + filterset_class = SessaoPlenariaFilterSet + paginate_by = 10 + + def get_filterset_kwargs(self, filterset_class): + super(PesquisarSessaoPlenariaView, + self).get_filterset_kwargs(filterset_class) + + kwargs = {'data': self.request.GET or None} + + qs = self.get_queryset() + + qs = qs.distinct() + + kwargs.update({ + 'queryset': qs, + }) + return kwargs + + def get_context_data(self, **kwargs): + context = super(PesquisarSessaoPlenariaView, + self).get_context_data(**kwargs) + + paginator = context['paginator'] + page_obj = context['page_obj'] + + context['page_range'] = make_pagination( + page_obj.number, paginator.num_pages) + + return context + + def get(self, request, *args, **kwargs): + super(PesquisarSessaoPlenariaView, self).get(request) + + # Se a pesquisa estiver quebrando com a paginação + # Olhe esta função abaixo + # Provavelmente você criou um novo campo no Form/FilterSet + # Então a ordem da URL está diferente + data = self.filterset.data + if (data and data.get('data_inicio__year') is not None): + url = "&" + str(self.request.environ['QUERY_STRING']) + if url.startswith("&page"): + ponto_comeco = url.find('data_inicio__year=') - 1 + url = url[ponto_comeco:] + else: + url = '' + + context = self.get_context_data(filter=self.filterset, + object_list=self.object_list, + filter_url=url, + numero_res=len(self.object_list) + ) + + return self.render_to_response(context) diff --git a/templates/sessao/sessaoplenaria_filter.html b/templates/sessao/sessaoplenaria_filter.html new file mode 100644 index 000000000..2a3231507 --- /dev/null +++ b/templates/sessao/sessaoplenaria_filter.html @@ -0,0 +1,47 @@ +{% extends "crud/detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} +{% block actions %}{% endblock %} + +{% block sections_nav %} {% endblock %} + +{% block detail_content %} +

Pesquisar Sessão Plenária

+

+ + + {% crispy filter.form %} + {% if filter_url %} +

+ + + + + {% if page_obj|length %} + {% if numero_res > 1 %} +

Pesquisa concluída com sucesso! Foram encontradas {{numero_res}} sessões.

+ {% elif numero_res == 1 %} +

Pesquisa concluída com sucesso! Foi encontrada {{numero_res}} sessão.

+ {% endif %} + + {% for s in page_obj %} + + + + {% endfor %} + {% else %} + + + {% endif %} + +

Resultados

+ {{s.numero}}ª Sessão {{s.tipo.nome}} da {{s.sessao_legislativa.numero}}ª Sessão Legislativa da {{s.legislatura.id}}ª Legislatura
+

+
+

Nenhuma Sessão Plenária encontrada com essas especificações

+
+ +{% include "paginacao.html" %} +{% endif %} + +{% endblock detail_content %} \ No newline at end of file diff --git a/templates/sessao/sessaoplenaria_list.html b/templates/sessao/sessaoplenaria_list.html new file mode 100644 index 000000000..ef3d9a61c --- /dev/null +++ b/templates/sessao/sessaoplenaria_list.html @@ -0,0 +1,7 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% block more_buttons %} + + {% blocktrans with verbose_name=view.verbose_name %} Pesquisar {{ verbose_name }} {% endblocktrans %} + +{% endblock %}