Browse Source

Refatora app protocoloadm p/ usar ref do Crud

pull/675/head
LeandroRoberto 8 years ago
parent
commit
a2f9bb1f78
  1. 135
      sapl/protocoloadm/views.py

135
sapl/protocoloadm/views.py

@ -1,8 +1,9 @@
import json
from datetime import date, datetime from datetime import date, datetime
import json
from braces.views import FormValidMessageMixin, PermissionRequiredMixin from braces.views import FormValidMessageMixin
from django.contrib import messages from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.db.models import Max, Q from django.db.models import Max, Q
@ -13,14 +14,16 @@ from django.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django_filters.views import FilterView from django_filters.views import FilterView
import sapl.crud.base from sapl.base.apps import AppConfig as AppsAppConfig
from sapl.base.models import AppConfig from sapl.base.models import AppConfig
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView, CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, MasterDetailCrud, make_pagination) CrudUpdateView, MasterDetailCrud, make_pagination,
CrudAux)
from sapl.materia.models import TipoMateriaLegislativa from sapl.materia.models import TipoMateriaLegislativa
from sapl.utils import (create_barcode, get_client_ip, permissoes_adm, from sapl.utils import (create_barcode, get_client_ip, permissoes_adm,
permissoes_protocoloadm) permissoes_protocoloadm)
import sapl.crud.base
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoFilterSet, DocumentoAdministrativoFilterSet,
@ -33,79 +36,57 @@ from .models import (Autor, DocumentoAcessorioAdministrativo,
TipoDocumentoAdministrativo, TipoInstituicao, TipoDocumentoAdministrativo, TipoInstituicao,
TramitacaoAdministrativo) TramitacaoAdministrativo)
TipoDocumentoAdministrativoCrud = Crud.build(TipoDocumentoAdministrativo, '')
DocumentoAcessorioAdministrativoCrud = Crud.build(
DocumentoAcessorioAdministrativo, '')
ProtocoloDocumentoCrud = Crud.build(Protocolo, '')
# FIXME precisa de uma chave diferente para o layout
ProtocoloMateriaCrud = Crud.build(Protocolo, '')
TipoInstituicaoCrud = Crud.build(TipoInstituicao, '')
TipoDocumentoAdministrativoCrud = CrudAux.build(
TipoDocumentoAdministrativo, '')
TipoInstituicaoCrud = CrudAux.build(TipoInstituicao, '')
class DocumentoAdministrativoCrud(Crud):
model = DocumentoAdministrativo
help_path = ''
class BaseMixin(sapl.crud.base.CrudBaseMixin): ProtocoloDocumentoCrud = Crud.build(Protocolo, '')
list_field_names = ['tipo', 'numero', 'ano', 'data', # FIXME precisa de uma chave diferente para o layout
'numero_protocolo', 'assunto', ProtocoloMateriaCrud = Crud.build(Protocolo, '')
'interessado', 'tramitacao', 'texto_integral']
class CreateView(CrudCreateView):
permission_required = permissoes_adm()
class UpdateView(CrudUpdateView): DocumentoAcessorioAdministrativoCrud = Crud.build(
permission_required = permissoes_adm() DocumentoAcessorioAdministrativo, '')
class DeleteView(CrudDeleteView):
permission_required = permissoes_adm()
class ListView(CrudListView): class DocumentoAdministrativoMixin:
permission_required = permissoes_adm()
def has_permission(self): def has_permission(self):
app_config = AppConfig.objects.last() app_config = AppConfig.objects.last()
if app_config and app_config.documentos_administrativos == 'O':
return True
if app_config: return self.request.user.has_module_perms(AppsAppConfig.label)
if app_config.documentos_administrativos == 'O':
return True
perms = self.get_permission_required()
return self.request.user.has_perms(perms)
class DetailView(CrudDetailView): class DocumentoAdministrativoCrud(Crud):
permission_required = permissoes_adm() model = DocumentoAdministrativo
help_path = ''
def has_permission(self): class BaseMixin(Crud.BaseMixin):
app_config = AppConfig.objects.last() list_field_names = ['tipo', 'numero', 'ano', 'data',
'numero_protocolo', 'assunto',
'interessado', 'tramitacao', 'texto_integral']
if app_config: class ListView(Crud.ListView, DocumentoAdministrativoMixin):
if app_config.documentos_administrativos == 'O': pass
return True
perms = self.get_permission_required() class DetailView(Crud.DetailView, DocumentoAdministrativoMixin):
return self.request.user.has_perms(perms) pass
class StatusTramitacaoAdministrativoCrud(Crud): class StatusTramitacaoAdministrativoCrud(CrudAux):
model = StatusTramitacaoAdministrativo model = StatusTramitacaoAdministrativo
help_path = '' help_path = ''
class BaseMixin(CrudBaseMixin): class BaseMixin(CrudAux.BaseMixin):
list_field_names = ['sigla', 'indicador', 'descricao'] list_field_names = ['sigla', 'indicador', 'descricao']
class ListView(CrudListView): class ListView(CrudAux.ListView):
ordering = 'sigla' ordering = 'sigla'
class CreateView(CrudCreateView):
permission_required = permissoes_adm()
class UpdateView(CrudUpdateView):
permission_required = permissoes_adm()
class DeleteView(CrudDeleteView):
permission_required = permissoes_adm()
class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView): class ProtocoloPesquisaView(PermissionRequiredMixin, FilterView):
model = Protocolo model = Protocolo
@ -392,22 +373,13 @@ class ProtocoloMateriaView(PermissionRequiredMixin, CreateView):
class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin, class PesquisarDocumentoAdministrativoView(PermissionRequiredMixin,
FilterView): FilterView,
DocumentoAdministrativoMixin):
model = DocumentoAdministrativo model = DocumentoAdministrativo
filterset_class = DocumentoAdministrativoFilterSet filterset_class = DocumentoAdministrativoFilterSet
paginate_by = 10 paginate_by = 10
permission_required = permissoes_adm() permission_required = permissoes_adm()
def has_permission(self):
app_config = AppConfig.objects.last()
if app_config:
if app_config.documentos_administrativos == 'O':
return True
perms = self.get_permission_required()
return self.request.user.has_perms(perms)
def get_filterset_kwargs(self, filterset_class): def get_filterset_kwargs(self, filterset_class):
super(PesquisarDocumentoAdministrativoView, super(PesquisarDocumentoAdministrativoView,
self).get_filterset_kwargs(filterset_class) self).get_filterset_kwargs(filterset_class)
@ -603,45 +575,20 @@ class TramitacaoAdmCrud(MasterDetailCrud):
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = TramitacaoAdmForm form_class = TramitacaoAdmForm
permission_required = permissoes_adm()
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoAdmEditForm form_class = TramitacaoAdmEditForm
permission_required = permissoes_adm()
class DeleteView(MasterDetailCrud.DeleteView): class ListView(MasterDetailCrud.ListView, DocumentoAdministrativoMixin):
permission_required = permissoes_adm()
class ListView(MasterDetailCrud.ListView):
permission_required = permissoes_adm()
def get_queryset(self): def get_queryset(self):
qs = super(MasterDetailCrud.ListView, self).get_queryset() qs = super(MasterDetailCrud.ListView, self).get_queryset()
kwargs = {self.crud.parent_field: self.kwargs['pk']} kwargs = {self.crud.parent_field: self.kwargs['pk']}
return qs.filter(**kwargs).order_by('-data_tramitacao', '-id') return qs.filter(**kwargs).order_by('-data_tramitacao', '-id')
def has_permission(self): class DetailView(MasterDetailCrud.DetailView,
app_config = AppConfig.objects.last() DocumentoAdministrativoMixin):
pass
if app_config:
if app_config.documentos_administrativos == 'O':
return True
perms = self.get_permission_required()
return self.request.user.has_perms(perms)
class DetailView(MasterDetailCrud.DetailView):
permission_required = permissoes_adm()
def has_permission(self):
app_config = AppConfig.objects.last()
if app_config:
if app_config.documentos_administrativos == 'O':
return True
perms = self.get_permission_required()
return self.request.user.has_perms(perms)
def get_nome_autor(request): def get_nome_autor(request):

Loading…
Cancel
Save