diff --git a/sapl/parlamentares/urls.py b/sapl/parlamentares/urls.py index 2235e5a12..97f2a0347 100644 --- a/sapl/parlamentares/urls.py +++ b/sapl/parlamentares/urls.py @@ -5,7 +5,10 @@ from sapl.parlamentares.views import (CargoMesaCrud, ColigacaoCrud, FiliacaoCrud, LegislaturaCrud, MandatoCrud, MesaDiretoraView, NivelInstrucaoCrud, ParlamentarCrud, - PartidoCrud, SessaoLegislativaCrud, + ParticipacaoParlamentarCrud, PartidoCrud, + ProposicaoParlamentarCrud, + RelatoriaParlamentarCrud, + SessaoLegislativaCrud, TipoAfastamentoCrud, TipoDependenteCrud, TipoMilitarCrud) @@ -16,7 +19,10 @@ 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() + + ProposicaoParlamentarCrud.get_urls() + + RelatoriaParlamentarCrud.get_urls() )), url(r'^coligacao/', include(ColigacaoCrud.get_urls() + diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index e104cb91f..0f2a8edfb 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -2,16 +2,19 @@ from django.contrib import messages from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.models import Permission from django.contrib.contenttypes.models import ContentType -from django.core.urlresolvers import reverse_lazy +from django.core.exceptions import ObjectDoesNotExist +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 sapl.comissoes.models import Participacao from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, CrudDeleteView, CrudDetailView, CrudListView, CrudUpdateView) from sapl.crud.masterdetail import MasterDetailCrud +from sapl.materia.models import Proposicao, Relatoria from sapl.utils import permissao_tb_aux, permissoes_parlamentares from .forms import (ComposicaoColigacaoForm, FiliacaoForm, LegislaturaForm, @@ -22,6 +25,93 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, SituacaoMilitar, TipoAfastamento, TipoDependente) +class RelatoriaParlamentarCrud(MasterDetailCrud): + model = Relatoria + parent_field = 'parlamentar' + help_path = '' + + class ListView(MasterDetailCrud.ListView): + permission_required = permissoes_parlamentares() + + 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 ProposicaoParlamentarCrud(MasterDetailCrud): + model = Proposicao + parent_field = 'autor__parlamentar' + help_path = '' + + class BaseMixin(CrudBaseMixin): + list_field_names = ['tipo', 'descricao'] + + class ListView(MasterDetailCrud.ListView): + permission_required = permissoes_parlamentares() + + def get_queryset(self): + try: + proposicoes = Proposicao.objects.filter( + autor__parlamentar_id=self.kwargs['pk'], + data_envio__isnull=False) + except ObjectDoesNotExist: + return [] + else: + return proposicoes + + 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 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, reverse( + 'sapl.comissoes:comissao_detail', kwargs={ + 'pk': p.composicao.comissao.pk})), + (p.cargo.nome, None), + (p.composicao.periodo.data_inicio.strftime( + "%d/%m/%Y") + ' a ' + + p.composicao.periodo.data_fim.strftime("%d/%m/%Y"), + 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..286e0fc9d 100644 --- a/sapl/templates/parlamentares/subnav.yaml +++ b/sapl/templates/parlamentares/subnav.yaml @@ -7,3 +7,9 @@ url: filiacao_list - title: {% trans 'Dependentes' %} url: dependente_list +- title: {% trans 'Comissões' %} + url: participacao_list +- title: {% trans 'Proposições' %} + url: proposicao_list +- title: {% trans 'Relatorias' %} + url: relatoria_list