diff --git a/sapl/comissoes/views.py b/sapl/comissoes/views.py index f8ca4a813..155b10e89 100644 --- a/sapl/comissoes/views.py +++ b/sapl/comissoes/views.py @@ -1,4 +1,7 @@ from django.core.urlresolvers import reverse +from django.contrib.auth.mixins import PermissionRequiredMixin +from django.contrib.auth.models import Permission +from django.contrib.contenttypes.models import ContentType from django.views.generic import ListView from sapl.crud.base import Crud, CrudBaseMixin @@ -8,9 +11,14 @@ from sapl.materia.models import Tramitacao from .models import (CargoComissao, Comissao, Composicao, Participacao, Periodo, TipoComissao) -CargoCrud = Crud.build(CargoComissao, 'cargo_comissao') -PeriodoComposicaoCrud = Crud.build(Periodo, 'periodo_composicao_comissao') -TipoComissaoCrud = Crud.build(TipoComissao, 'tipo_comissao') + +def permissoes_comissoes(): + lista_permissoes = [] + cts = ContentType.objects.filter(app_label='comissoes') + perms_comissoes = list(Permission.objects.filter(content_type__in=cts)) + for p in perms_comissoes: + lista_permissoes.append('comissoes.' + p.codename) + return set(lista_permissoes) def pegar_url_composicao(pk): @@ -20,13 +28,40 @@ def pegar_url_composicao(pk): return url +class CargoCrud(Crud): + model = CargoComissao + help_path = 'cargo_comissao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_comissoes() + list_field_names = ['nome', 'unico'] + + +class PeriodoComposicaoCrud(Crud): + model = Periodo + help_path = 'periodo_composicao_comissao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_comissoes() + list_field_names = ['data_inicio', 'data_fim'] + + +class TipoComissaoCrud(Crud): + model = TipoComissao + help_path = 'tipo_comissao' + + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_comissoes() + list_field_names = ['sigla', 'nome', 'natureza', + 'dispositivo_regimental'] + + class ParticipacaoCrud(MasterDetailCrud): model = Participacao parent_field = 'composicao' help_path = '' class DetailView(MasterDetailCrud.DetailView): - def get(self, request, *args, **kwargs): self.object = self.get_object() context = self.get_context_data(object=self.object) @@ -63,6 +98,10 @@ class ParticipacaoCrud(MasterDetailCrud): def cancel_url(self): return pegar_url_composicao(self.kwargs['pk']) + class BaseMixin(PermissionRequiredMixin, CrudBaseMixin): + permission_required = permissoes_comissoes() + list_field_names = ['composicao', 'parlamentar', 'cargo'] + class ComposicaoCrud(MasterDetailCrud): model = Composicao @@ -78,11 +117,61 @@ class ComposicaoCrud(MasterDetailCrud): context['participacoes'] = composicao.participacao_set.all() return self.render_to_response(context) + class CreateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:composicao_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class UpdateView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:composicao_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DetailView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:composicao_list') + class ComissaoCrud(Crud): model = Comissao help_path = 'modulo_comissoes' + class CreateView(PermissionRequiredMixin, Crud.CreateView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:comissoes_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class UpdateView(PermissionRequiredMixin, Crud.UpdateView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:comissoes_detail', + kwargs={'pk': self.kwargs['pk']} + ) + + class DeleteView(PermissionRequiredMixin, Crud.DeleteView): + permission_required = permissoes_comissoes() + + def get_success_url(self): + return reverse( + 'sapl.comissoes:comissoes_list') + class BaseMixin(CrudBaseMixin): list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao']