Browse Source

Faz as permissoes do app Comissoes

pull/506/head
Eduardo Calil 9 years ago
parent
commit
bb23bb8761
  1. 97
      sapl/comissoes/views.py

97
sapl/comissoes/views.py

@ -1,4 +1,7 @@
from django.core.urlresolvers import reverse 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 django.views.generic import ListView
from sapl.crud.base import Crud, CrudBaseMixin from sapl.crud.base import Crud, CrudBaseMixin
@ -8,9 +11,14 @@ from sapl.materia.models import Tramitacao
from .models import (CargoComissao, Comissao, Composicao, Participacao, from .models import (CargoComissao, Comissao, Composicao, Participacao,
Periodo, TipoComissao) Periodo, TipoComissao)
CargoCrud = Crud.build(CargoComissao, 'cargo_comissao')
PeriodoComposicaoCrud = Crud.build(Periodo, 'periodo_composicao_comissao') def permissoes_comissoes():
TipoComissaoCrud = Crud.build(TipoComissao, 'tipo_comissao') 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): def pegar_url_composicao(pk):
@ -20,13 +28,40 @@ def pegar_url_composicao(pk):
return url 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): class ParticipacaoCrud(MasterDetailCrud):
model = Participacao model = Participacao
parent_field = 'composicao' parent_field = 'composicao'
help_path = '' help_path = ''
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
self.object = self.get_object() self.object = self.get_object()
context = self.get_context_data(object=self.object) context = self.get_context_data(object=self.object)
@ -63,6 +98,10 @@ class ParticipacaoCrud(MasterDetailCrud):
def cancel_url(self): def cancel_url(self):
return pegar_url_composicao(self.kwargs['pk']) return pegar_url_composicao(self.kwargs['pk'])
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
permission_required = permissoes_comissoes()
list_field_names = ['composicao', 'parlamentar', 'cargo']
class ComposicaoCrud(MasterDetailCrud): class ComposicaoCrud(MasterDetailCrud):
model = Composicao model = Composicao
@ -78,11 +117,61 @@ class ComposicaoCrud(MasterDetailCrud):
context['participacoes'] = composicao.participacao_set.all() context['participacoes'] = composicao.participacao_set.all()
return self.render_to_response(context) 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): class ComissaoCrud(Crud):
model = Comissao model = Comissao
help_path = 'modulo_comissoes' 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): class BaseMixin(CrudBaseMixin):
list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao'] list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao']

Loading…
Cancel
Save