From 365638587405b022aa99c6d6d79a6f087d34fe35 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Tue, 5 Jan 2016 10:57:14 -0200 Subject: [PATCH] Refactor SessaoPlenaria List Fix #81 --- sessao/urls.py | 8 +++++--- sessao/views.py | 22 +++++++++++++++++++++- templates/base.html | 2 +- templates/sessao/sessao_list.html | 26 ++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 5 deletions(-) create mode 100644 templates/sessao/sessao_list.html diff --git a/sessao/urls.py b/sessao/urls.py index 7ddef0d95..25f4c05a8 100644 --- a/sessao/urls.py +++ b/sessao/urls.py @@ -1,5 +1,4 @@ from django.conf.urls import include, url - from sessao.views import (EditExpedienteOrdemDiaView, EditMateriaOrdemDiaView, ExpedienteOrdemDiaView, ExpedienteView, ExplicacaoDelete, ExplicacaoEdit, ExplicacaoView, @@ -8,8 +7,9 @@ from sessao.views import (EditExpedienteOrdemDiaView, EditMateriaOrdemDiaView, OradorExpedienteDelete, OradorExpedienteEdit, OradorExpedienteView, PainelView, PresencaOrdemDiaView, PresencaView, ResumoView, - VotacaoEditView, VotacaoExpedienteEditView, - VotacaoExpedienteView, VotacaoNominalEditView, + SessaoListView, VotacaoEditView, + VotacaoExpedienteEditView, VotacaoExpedienteView, + VotacaoNominalEditView, VotacaoNominalExpedienteEditView, VotacaoNominalExpedienteView, VotacaoNominalView, VotacaoView, sessao_crud, tipo_expediente_crud, @@ -79,6 +79,8 @@ urlpatterns_sessao = sessao_crud.urlpatterns + [ VotacaoExpedienteView.as_view(), name='votacaosecretaexp'), url(r'^(?P\d+)/matexp/votsec/view/(?P\d+)/(?P\d+)$', VotacaoExpedienteEditView.as_view(), name='votacaosecretaexpedit'), + url(r'^sessao-list$', + SessaoListView.as_view(), name='list_sessao'), ] sessao_urls = urlpatterns_sessao, sessao_crud.namespace, sessao_crud.namespace diff --git a/sessao/views.py b/sessao/views.py index 6a127800d..86ade6392 100644 --- a/sessao/views.py +++ b/sessao/views.py @@ -1,14 +1,15 @@ from datetime import datetime from re import sub +import sapl from django import forms from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse from django.forms.util import ErrorList from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ +from django.views.generic import ListView from django.views.generic.edit import FormMixin - from materia.models import Autoria, TipoMateriaLegislativa from parlamentares.models import Parlamentar from sapl.crud import build_crud @@ -2209,3 +2210,22 @@ class VotacaoExpedienteEditView(FormMixin, sessao_crud.CrudDetailView): pk = self.kwargs['pk'] return reverse('sessaoplenaria:expedienteordemdia_list', kwargs={'pk': pk}) + + +class SessaoListView(ListView): + template_name = "sessao/sessao_list.html" + paginate_by = 10 + model = SessaoPlenaria + + def get_queryset(self): + return SessaoPlenaria.objects.all().order_by('-data_inicio') + + def get_context_data(self, **kwargs): + context = super(SessaoListView, self).get_context_data(**kwargs) + + paginator = context['paginator'] + page_obj = context['page_obj'] + + context['page_range'] = sapl.crud.make_pagination( + page_obj.number, paginator.num_pages) + return context diff --git a/templates/base.html b/templates/base.html index 2068aa673..5c47d4d32 100644 --- a/templates/base.html +++ b/templates/base.html @@ -78,7 +78,7 @@