Browse Source

Faz a autorizacao no app protocoloadm

pull/505/head
Eduardo Calil 9 years ago
committed by LeandroRoberto
parent
commit
0fe8dfa715
  1. 81
      sapl/protocoloadm/views.py

81
sapl/protocoloadm/views.py

@ -2,6 +2,9 @@ import json
from datetime import date, datetime
from braces.views import FormValidMessageMixin
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.models import Permission
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Max, Q
@ -12,7 +15,8 @@ from django.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView
from django_filters.views import FilterView
from sapl.crud.base import Crud, CrudBaseMixin, CrudListView, make_pagination
from sapl.crud.base import (Crud, CrudBaseMixin, CrudListView, make_pagination,
CrudCreateView, CrudUpdateView, CrudDeleteView)
from sapl.materia.models import Proposicao, TipoMateriaLegislativa
from sapl.utils import create_barcode, get_client_ip
@ -38,6 +42,24 @@ ProtocoloMateriaCrud = Crud.build(Protocolo, '')
TipoInstituicaoCrud = Crud.build(TipoInstituicao, '')
def permissoes_protocoloadm():
lista_permissoes = []
cts = ContentType.objects.filter(app_label='protocoloadm')
perms_protocolo = list(Permission.objects.filter(content_type__in=cts))
for p in perms_protocolo:
lista_permissoes.append('protocoloadm.' + p.codename)
return set(lista_permissoes)
def permissoes_adm():
lista_permissoes = []
perms_adm = Permission.objects.filter(
group__name='Operador de Administração')
for p in perms_adm:
lista_permissoes.append('protocoloadm.' + p.codename)
return set(lista_permissoes)
class StatusTramitacaoAdministrativoCrud(Crud):
model = StatusTramitacaoAdministrativo
help_path = ''
@ -48,11 +70,21 @@ class StatusTramitacaoAdministrativoCrud(Crud):
class ListView(CrudListView):
ordering = 'sigla'
class CreateView(PermissionRequiredMixin, CrudCreateView):
permission_required = permissoes_adm()
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
permission_required = permissoes_adm()
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
permission_required = permissoes_adm()
class ProtocoloPesquisaView(FilterView):
class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView):
model = Protocolo
filterset_class = ProtocoloFilterSet
paginate_by = 10
permission_required = permissoes_protocoloadm()
def get_filterset_kwargs(self, filterset_class):
super(ProtocoloPesquisaView,
@ -108,11 +140,12 @@ class ProtocoloPesquisaView(FilterView):
return self.render_to_response(context)
class ProtocoloListView(ListView):
class ProtocoloListView(PermissionRequiredMixin, ListView):
template_name = 'protocoloadm/protocolo_list.html'
context_object_name = 'protocolos'
model = Protocolo
paginate_by = 10
permission_required = permissoes_protocoloadm()
def get_queryset(self):
kwargs = self.request.session['kwargs']
@ -131,10 +164,11 @@ class ProtocoloListView(ListView):
return context
class AnularProtocoloAdmView(CreateView):
class AnularProtocoloAdmView(PermissionRequiredMixin, CreateView):
template_name = 'protocoloadm/anular_protocoloadm.html'
form_class = AnularProcoloAdmForm
form_valid_message = _('Protocolo anulado com sucesso!')
permission_required = permissoes_protocoloadm()
def get_success_url(self):
return reverse('sapl.protocoloadm:protocolo')
@ -157,10 +191,11 @@ class AnularProtocoloAdmView(CreateView):
return redirect(self.get_success_url())
class ProtocoloDocumentoView(FormValidMessageMixin, CreateView):
class ProtocoloDocumentoView(PermissionRequiredMixin, FormValidMessageMixin, CreateView):
template_name = "protocoloadm/protocolar_documento.html"
form_class = ProtocoloDocumentForm
form_valid_message = _('Protocolo cadastrado com sucesso!')
permission_required = permissoes_protocoloadm()
def get_success_url(self):
return reverse('sapl.protocoloadm:protocolo')
@ -189,9 +224,10 @@ class ProtocoloDocumentoView(FormValidMessageMixin, CreateView):
return redirect(self.get_success_url())
class CriarDocumentoProtocolo(CreateView):
class CriarDocumentoProtocolo(PermissionRequiredMixin, CreateView):
template_name = "protocoloadm/criar_documento.html"
form_class = DocumentoAdministrativoForm
permission_required = permissoes_protocoloadm()
def get_initial(self):
numero = self.kwargs['pk']
@ -226,9 +262,10 @@ class CriarDocumentoProtocolo(CreateView):
return doc
class ProtocoloMostrarView(TemplateView):
class ProtocoloMostrarView(PermissionRequiredMixin, TemplateView):
template_name = "protocoloadm/protocolo_mostrar.html"
permission_required = permissoes_protocoloadm()
def get_context_data(self, **kwargs):
context = super(ProtocoloMostrarView, self).get_context_data(**kwargs)
@ -239,9 +276,10 @@ class ProtocoloMostrarView(TemplateView):
return context
class ComprovanteProtocoloView(TemplateView):
class ComprovanteProtocoloView(PermissionRequiredMixin, TemplateView):
template_name = "protocoloadm/comprovante.html"
permission_required = permissoes_protocoloadm()
def get_context_data(self, **kwargs):
context = super(ComprovanteProtocoloView, self).get_context_data(
@ -267,11 +305,12 @@ class ComprovanteProtocoloView(TemplateView):
return context
class ProtocoloMateriaView(CreateView):
class ProtocoloMateriaView(PermissionRequiredMixin, CreateView):
template_name = "protocoloadm/protocolar_materia.html"
form_class = ProtocoloMateriaForm
form_valid_message = _('Matéria cadastrada com sucesso!')
permission_required = permissoes_protocoloadm()
def get_success_url(self):
return reverse('sapl.protocoloadm:protocolo')
@ -368,10 +407,11 @@ class ProposicaoDetailView(DetailView):
return context
class PesquisarDocumentoAdministrativoView(FilterView):
class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin, FilterView):
model = DocumentoAdministrativo
filterset_class = DocumentoAdministrativoFilterSet
paginate_by = 10
permission_required = permissoes_adm()
def get_filterset_kwargs(self, filterset_class):
super(PesquisarDocumentoAdministrativoView,
@ -427,8 +467,9 @@ class PesquisarDocumentoAdministrativoView(FilterView):
return self.render_to_response(context)
class DetailDocumentoAdministrativo(DetailView):
class DetailDocumentoAdministrativo(PermissionRequiredMixin, DetailView):
template_name = "protocoloadm/detail_doc_adm.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
documento = DocumentoAdministrativo.objects.get(
@ -467,8 +508,9 @@ class DetailDocumentoAdministrativo(DetailView):
'pk': self.kwargs['pk']})
class DocumentoAcessorioAdministrativoEditView(FormView):
class DocumentoAcessorioAdministrativoEditView(PermissionRequiredMixin, FormView):
template_name = "protocoloadm/documento_acessorio_administrativo_edit.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
doc = DocumentoAdministrativo.objects.get(
@ -514,8 +556,9 @@ class DocumentoAcessorioAdministrativoEditView(FormView):
return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk})
class DocumentoAcessorioAdministrativoView(FormView):
class DocumentoAcessorioAdministrativoView(PermissionRequiredMixin, FormView):
template_name = "protocoloadm/documento_acessorio_administrativo.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
form = DocumentoAcessorioAdministrativoForm()
@ -553,8 +596,9 @@ class DocumentoAcessorioAdministrativoView(FormView):
return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk})
class TramitacaoAdmView(FormView):
class TramitacaoAdmView(PermissionRequiredMixin, FormView):
template_name = "protocoloadm/tramitacao.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
@ -567,8 +611,9 @@ class TramitacaoAdmView(FormView):
'tramitacoes': tramitacoes})
class TramitacaoAdmIncluirView(FormView):
class TramitacaoAdmIncluirView(PermissionRequiredMixin, FormView):
template_name = "protocoloadm/tramitacao_incluir.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
pk = kwargs['pk']
@ -592,9 +637,10 @@ class TramitacaoAdmIncluirView(FormView):
return self.form_invalid(form)
class TramitacaoAdmEditView(FormView):
class TramitacaoAdmEditView(PermissionRequiredMixin, FormView):
template_name = "protocoloadm/tramitacao_edit.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
pk = kwargs['pk']
@ -620,9 +666,10 @@ class TramitacaoAdmEditView(FormView):
return self.form_invalid(form)
class TramitacaoAdmDeleteView(DetailView):
class TramitacaoAdmDeleteView(PermissionRequiredMixin, DetailView):
template_name = "protocoloadm/tramitacao.html"
permission_required = permissoes_adm()
def get(self, request, *args, **kwargs):
pk = kwargs['pk']

Loading…
Cancel
Save