From 5c114c33d1c972b99dc9158cd8a06c8914fe292f Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 16 Sep 2016 12:41:56 -0300 Subject: [PATCH] =?UTF-8?q?Cria=20m=C3=A9todo=20separado=20para=20listagem?= =?UTF-8?q?=20de=20frentes=20no=20parlamentar?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/parlamentares/urls.py | 13 ++++++++----- sapl/parlamentares/views.py | 21 ++++++++++++++------- sapl/templates/parlamentares/frentes.html | 21 +++++++++++++++++++++ sapl/templates/parlamentares/subnav.yaml | 2 +- 4 files changed, 44 insertions(+), 13 deletions(-) create mode 100644 sapl/templates/parlamentares/frentes.html diff --git a/sapl/parlamentares/urls.py b/sapl/parlamentares/urls.py index 34fb8b0fe..70af2200a 100644 --- a/sapl/parlamentares/urls.py +++ b/sapl/parlamentares/urls.py @@ -2,10 +2,10 @@ from django.conf.urls import include, url from sapl.parlamentares.views import (CargoMesaCrud, ColigacaoCrud, ComposicaoColigacaoCrud, DependenteCrud, - FiliacaoCrud, FrenteCrud, - FrenteParlamentarCrud, LegislaturaCrud, - MandatoCrud, MesaDiretoraView, - NivelInstrucaoCrud, ParlamentarCrud, + FiliacaoCrud, FrenteCrud, FrenteList, + LegislaturaCrud, MandatoCrud, + MesaDiretoraView, NivelInstrucaoCrud, + ParlamentarCrud, ParticipacaoParlamentarCrud, PartidoCrud, ProposicaoParlamentarCrud, RelatoriaParlamentarCrud, @@ -23,9 +23,12 @@ urlpatterns = [ FiliacaoCrud.get_urls() + MandatoCrud.get_urls() + ParticipacaoParlamentarCrud.get_urls() + ProposicaoParlamentarCrud.get_urls() + - RelatoriaParlamentarCrud.get_urls() + FrenteParlamentarCrud.get_urls() + RelatoriaParlamentarCrud.get_urls() )), + url(r'^parlamentar/(?P\d+)/frente$', + FrenteList.as_view(), name="frent_list"), + url(r'^sistema/coligacao/', include(ColigacaoCrud.get_urls() + ComposicaoColigacaoCrud.get_urls())), diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index c856e6a03..440fa98da 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -7,7 +7,7 @@ from django.core.urlresolvers import reverse, reverse_lazy from django.shortcuts import redirect from django.utils.datastructures import MultiValueDictKeyError from django.utils.translation import ugettext_lazy as _ -from django.views.generic import FormView +from django.views.generic import FormView, ListView from sapl.comissoes.models import Participacao from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, @@ -25,10 +25,17 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, SituacaoMilitar, TipoAfastamento, TipoDependente) -class FrenteParlamentarCrud(MasterDetailCrud): +class FrenteList(ListView): model = Frente - parent_field = 'parlamentares' - help_path = '' + paginate_by = 10 + template_name = 'parlamentares/frentes.html' + + def get_queryset(self): + return Frente.objects.filter(parlamentares__in=[self.kwargs['pk']]) + + def get_context_data(self, **kwargs): + return {'root_pk': self.kwargs['pk'], + 'object_list': self.get_queryset()} class FrenteCrud(Crud): @@ -36,15 +43,15 @@ class FrenteCrud(Crud): help_path = '' class BaseMixin(CrudBaseMixin): - permission_required = permissoes_parlamentares() list_field_names = ['nome', 'data_criacao', 'parlamentares'] + def has_permission(self): + return permissao_tb_aux(self) + class CreateView(PermissionRequiredMixin, CrudCreateView): - permission_required = permissoes_parlamentares() form_class = FrenteForm class UpdateView(PermissionRequiredMixin, CrudUpdateView): - permission_required = permissoes_parlamentares() form_class = FrenteForm diff --git a/sapl/templates/parlamentares/frentes.html b/sapl/templates/parlamentares/frentes.html new file mode 100644 index 000000000..5a7ae3f9e --- /dev/null +++ b/sapl/templates/parlamentares/frentes.html @@ -0,0 +1,21 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block base_content %} + {% if object_list|length == 0 %} +

Nenhuma frente encontrada.

+ {% else %} + + + + + + {% for frente in object_list %} + + {% endfor %} + +
Frentes
{{ frente.nome }}
+ {% endif %} + {% include "paginacao.html" %} +{% endblock %} diff --git a/sapl/templates/parlamentares/subnav.yaml b/sapl/templates/parlamentares/subnav.yaml index eeccf4533..986ab377d 100644 --- a/sapl/templates/parlamentares/subnav.yaml +++ b/sapl/templates/parlamentares/subnav.yaml @@ -14,4 +14,4 @@ - title: {% trans 'Relatorias' %} url: relatoria_list - title: {% trans 'Frentes' %} - url: frente_list + url: