Browse Source

Implementa a autorizacao no app norma

pull/505/head
Eduardo Calil 9 years ago
committed by LeandroRoberto
parent
commit
609ecab2d0
  1. 43
      sapl/norma/views.py

43
sapl/norma/views.py

@ -1,27 +1,56 @@
from datetime import datetime from datetime import datetime
from django.contrib.auth.models import Permission
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.contenttypes.models import ContentType
from django.shortcuts import redirect from django.shortcuts import redirect
from django.views.generic import FormView, ListView from django.views.generic import FormView, ListView
from sapl.compilacao.views import IntegracaoTaView from sapl.compilacao.views import IntegracaoTaView
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudUpdateView, make_pagination) CrudDeleteView, CrudUpdateView, make_pagination)
from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica,
TipoNormaJuridica) TipoNormaJuridica)
AssuntoNormaCrud = Crud.build(AssuntoNorma, 'assunto_norma_juridica')
TipoNormaCrud = Crud.build(TipoNormaJuridica, 'tipo_norma_juridica')
LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '') LegislacaoCitadaCrud = Crud.build(LegislacaoCitada, '')
def permissoes_norma():
lista_permissoes = []
cts = ContentType.objects.filter(app_label='norma')
perms_norma = list(Permission.objects.filter(content_type__in=cts))
for p in perms_norma:
lista_permissoes.append('norma.' + p.codename)
return set(lista_permissoes)
class AssuntoNormaCrud(Crud):
model = AssuntoNorma
help_path = 'assunto_norma_juridica'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
permission_required = permissoes_norma()
list_field_names = ['assunto', 'descricao']
class TipoNormaCrud(Crud):
model = TipoNormaJuridica
help_path = 'tipo_norma_juridica'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
permission_required = permissoes_norma()
list_field_names = ['equivalente_lexml', 'sigla', 'descricao']
class NormaCrud(Crud): class NormaCrud(Crud):
model = NormaJuridica model = NormaJuridica
help_path = 'norma_juridica' help_path = 'norma_juridica'
class UpdateView(CrudUpdateView): class UpdateView(PermissionRequiredMixin, CrudUpdateView):
form_class = NormaJuridicaForm form_class = NormaJuridicaForm
permission_required = permissoes_norma()
@property @property
def layout_key(self): def layout_key(self):
@ -35,13 +64,17 @@ class NormaCrud(Crud):
self.initial['numero_materia'] = norma.materia.numero self.initial['numero_materia'] = norma.materia.numero
return self.initial.copy() return self.initial.copy()
class CreateView(CrudCreateView): class CreateView(PermissionRequiredMixin, CrudCreateView):
form_class = NormaJuridicaForm form_class = NormaJuridicaForm
permission_required = permissoes_norma()
@property @property
def layout_key(self): def layout_key(self):
return 'NormaJuridicaCreate' return 'NormaJuridicaCreate'
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
permission_required = permissoes_norma()
class BaseMixin(CrudBaseMixin): class BaseMixin(CrudBaseMixin):
list_field_names = ['tipo', 'numero', 'ano', 'ementa'] list_field_names = ['tipo', 'numero', 'ano', 'ementa']

Loading…
Cancel
Save