diff --git a/sapl/parlamentares/urls.py b/sapl/parlamentares/urls.py index 2235e5a12..496386551 100644 --- a/sapl/parlamentares/urls.py +++ b/sapl/parlamentares/urls.py @@ -5,7 +5,8 @@ from sapl.parlamentares.views import (CargoMesaCrud, ColigacaoCrud, FiliacaoCrud, LegislaturaCrud, MandatoCrud, MesaDiretoraView, NivelInstrucaoCrud, ParlamentarCrud, - PartidoCrud, SessaoLegislativaCrud, + ParticipacaoParlamentarCrud, PartidoCrud, + SessaoLegislativaCrud, TipoAfastamentoCrud, TipoDependenteCrud, TipoMilitarCrud) @@ -16,7 +17,8 @@ app_name = AppConfig.name urlpatterns = [ url(r'^parlamentar/', include( ParlamentarCrud.get_urls() + DependenteCrud.get_urls() + - FiliacaoCrud.get_urls() + MandatoCrud.get_urls() + FiliacaoCrud.get_urls() + MandatoCrud.get_urls() + + ParticipacaoParlamentarCrud.get_urls() )), url(r'^coligacao/', include(ColigacaoCrud.get_urls() + diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index e104cb91f..77136ff45 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -8,6 +8,7 @@ from django.utils.datastructures import MultiValueDictKeyError from django.utils.translation import ugettext_lazy as _ from django.views.generic import FormView +from sapl.comissoes.models import Participacao from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudDeleteView, CrudDetailView, CrudListView, CrudUpdateView) @@ -22,6 +23,39 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, SituacaoMilitar, TipoAfastamento, TipoDependente) +class ParticipacaoParlamentarCrud(MasterDetailCrud): + model = Participacao + parent_field = 'parlamentar' + help_path = '' + + class ListView(MasterDetailCrud.ListView): + ordering = ('-composicao__periodo') + + def get_rows(self, object_list): + comissoes = [] + for p in object_list: + if p.cargo.nome != 'Relator': + comissao = [ + (p.composicao.comissao.nome, p.composicao.comissao.pk), + (p.cargo.nome, None), + (p.composicao.periodo, None) + ] + comissoes.append(comissao) + return comissoes + + def get_headers(self): + return ['Comissão', 'Cargo', 'Período'] + + class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView): + permission_required = permissoes_parlamentares() + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView): + permission_required = permissoes_parlamentares() + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): + permission_required = permissoes_parlamentares() + + class CargoMesaCrud(Crud): model = CargoMesa help_path = 'cargo_mesa' diff --git a/sapl/templates/parlamentares/subnav.yaml b/sapl/templates/parlamentares/subnav.yaml index 9b457cd18..87068dcfa 100644 --- a/sapl/templates/parlamentares/subnav.yaml +++ b/sapl/templates/parlamentares/subnav.yaml @@ -7,3 +7,5 @@ url: filiacao_list - title: {% trans 'Dependentes' %} url: dependente_list +- title: {% trans 'Comissões' %} + url: participacao_list