Browse Source

Ref crud e dependencias e adequa app comissoes

pull/675/head
LeandroRoberto 8 years ago
parent
commit
7cd36e2d82
  1. 19
      sapl/base/migrations/0019_auto_20160928_1951.py
  2. 111
      sapl/base/models.py
  3. 11
      sapl/base/templatetags/common_tags.py
  4. 6
      sapl/base/urls.py
  5. 15
      sapl/base/views.py
  6. 21
      sapl/comissoes/migrations/0008_auto_20160929_1611.py
  7. 2
      sapl/comissoes/models.py
  8. 127
      sapl/comissoes/views.py
  9. 27
      sapl/crispy_layout_mixin.py
  10. 972
      sapl/crud/base.py
  11. 19
      sapl/crud/masterdetail.py
  12. 9
      sapl/crud/urls.py
  13. 99
      sapl/materia/views.py
  14. 10
      sapl/norma/views.py
  15. 74
      sapl/parlamentares/views.py
  16. 40
      sapl/protocoloadm/views.py
  17. 61
      sapl/sessao/views.py
  18. 7
      sapl/static/styles/app.scss
  19. 6
      sapl/templates/base.html
  20. 2
      sapl/templates/crud/ajax_form.html
  21. 9
      sapl/templates/crud/confirm_delete.html
  22. 96
      sapl/templates/crud/detail.html
  23. 92
      sapl/templates/crud/detail_detail.html
  24. 2
      sapl/templates/crud/form.html
  25. 80
      sapl/templates/crud/list.html
  26. 10
      sapl/utils.py

19
sapl/base/migrations/0019_auto_20160928_1951.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-09-28 22:51
from __future__ import unicode_literals
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('base', '0018_auto_20160919_1333'),
]
operations = [
migrations.AlterModelOptions(
name='appconfig',
options={'permissions': (('menu_sistemas', 'Renderizar Menu Sistemas'), ('view_tabelas_auxiliares', 'Visualizar Tabelas Auxiliares')), 'verbose_name': 'Configurações da Aplicação', 'verbose_name_plural': 'Configurações da Aplicação'},
),
]

111
sapl/base/models.py

@ -1,10 +1,21 @@
from builtins import LookupError
from django.apps import apps
from django.conf.urls import include, url
from django.contrib.auth.management import _get_all_permissions
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType
from django.core import exceptions
from django.db import models
from django.db import models, router
from django.db.utils import DEFAULT_DB_ALIAS
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
from rest_framework import permissions
from sapl.utils import UF, YES_NO_CHOICES
TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')),
('R', _('Restritivo')))
@ -94,7 +105,107 @@ class AppConfig(models.Model):
class Meta:
verbose_name = _('Configurações da Aplicação')
verbose_name_plural = _('Configurações da Aplicação')
permissions = (
('menu_sistemas', _('Renderizar Menu Sistemas')),
('view_tabelas_auxiliares', _('Visualizar Tabelas Auxiliares')),
)
def __str__(self):
return _('Configurações da Aplicação - %(id)s') % {
'id': self.id}
def create_proxy_permissions(
app_config, verbosity=2, interactive=True,
using=DEFAULT_DB_ALIAS, **kwargs):
if not app_config.models_module:
return
# print(app_config)
try:
Permission = apps.get_model('auth', 'Permission')
except LookupError:
return
if not router.allow_migrate_model(using, Permission):
return
from django.contrib.contenttypes.models import ContentType
permission_name_max_length = Permission._meta.get_field('name').max_length
# This will hold the permissions we're looking for as
# (content_type, (codename, name))
searched_perms = list()
# The codenames and ctypes that should exist.
ctypes = set()
for klass in list(app_config.get_models()):
opts = klass._meta
permissions = (
("list_" + opts.model_name,
string_concat(
_('Visualizaçao da lista de'), ' ',
opts.verbose_name_plural)),
("detail_" + opts.model_name,
string_concat(
_('Visualização dos detalhes de'), ' ',
opts.verbose_name_plural)),
)
opts.permissions = tuple(
set(list(permissions) + list(opts.permissions)))
if opts.proxy:
# Force looking up the content types in the current database
# before creating foreign keys to them.
app_label, model = opts.app_label, opts.model_name
try:
ctype = ContentType.objects.db_manager(
using).get_by_natural_key(app_label, model)
except:
ctype = ContentType.objects.db_manager(
using).create(app_label=app_label, model=model)
else:
ctype = ContentType.objects.db_manager(using).get_for_model(klass)
ctypes.add(ctype)
for perm in _get_all_permissions(klass._meta, ctype):
searched_perms.append((ctype, perm))
# Find all the Permissions that have a content_type for a model we're
# looking for. We don't need to check for codenames since we already have
# a list of the ones we're going to create.
all_perms = set(Permission.objects.using(using).filter(
content_type__in=ctypes,
).values_list(
"content_type", "codename"
))
perms = [
Permission(codename=codename, name=name, content_type=ct)
for ct, (codename, name) in searched_perms
if (ct.pk, codename) not in all_perms
]
# Validate the permissions before bulk_creation to avoid cryptic database
# error when the name is longer than 255 characters
for perm in perms:
if len(perm.name) > permission_name_max_length:
raise exceptions.ValidationError(
'The permission name %s of %s.%s '
'is longer than %s characters' % (
perm.name,
perm.content_type.app_label,
perm.content_type.model,
permission_name_max_length,
)
)
Permission.objects.using(using).bulk_create(perms)
if verbosity >= 2:
for perm in perms:
print("Adding permission '%s'" % perm)
models.signals.post_migrate.connect(
receiver=create_proxy_permissions,
dispatch_uid="django.contrib.auth.management.create_permissions")

11
sapl/base/templatetags/common_tags.py

@ -126,3 +126,14 @@ def get_config_not_exists(user):
return True
else:
return False
@register.filter
def str2intabs(value):
if not isinstance(value, str):
return ''
try:
v = int(value)
v = abs(v)
return v
except:
return ''

6
sapl/base/urls.py

@ -1,5 +1,6 @@
from django.conf.urls import include, url
from django.contrib.auth import views
from django.contrib.auth.decorators import permission_required
from django.views.generic.base import TemplateView
from .apps import AppConfig
@ -11,11 +12,14 @@ from .views import (AppConfigCrud, CasaLegislativaCrud, HelpView,
RelatorioMateriasTramitacaoView,
RelatorioPresencaSessaoView)
app_name = AppConfig.name
urlpatterns = [
url(r'^sistema/', TemplateView.as_view(template_name='sistema.html')),
url(r'^sistema/', permission_required('base.view_tabelas_auxiliares')
(TemplateView.as_view(template_name='sistema.html'))),
url(r'^ajuda/', TemplateView.as_view(template_name='ajuda.html')),
url(r'^relatorios/', TemplateView.as_view(
template_name='base/relatorios_list.html')),

15
sapl/base/views.py

@ -1,4 +1,5 @@
from django.contrib.auth.mixins import PermissionRequiredMixin
from braces.views import PermissionRequiredMixin
from django.core.urlresolvers import reverse
from django.db.models import Count, Q
from django.http import HttpResponseRedirect
@ -229,16 +230,16 @@ class CasaLegislativaCrud(Crud):
model = CasaLegislativa
help_path = ''
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
list_field_names = ['codigo', 'nome', 'sigla']
def has_permission(self):
return permissao_tb_aux(self)
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
form_class = CasaLegislativaForm
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
form_class = CasaLegislativaForm
class DetailView(CrudDetailView):
@ -269,7 +270,7 @@ class AppConfigCrud(Crud):
model = AppConfig
help_path = ''
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
list_field_names = ['documentos_administrativos',
'sequencia_numeracao',
'painel_aberto']
@ -277,7 +278,7 @@ class AppConfigCrud(Crud):
def has_permission(self):
return permissao_tb_aux(self)
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
form_class = ConfiguracoesAppForm
def get(self, request, *args, **kwargs):
@ -291,5 +292,5 @@ class AppConfigCrud(Crud):
return super(BaseCreateView, self).get(
request, *args, **kwargs)
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
form_class = ConfiguracoesAppForm

21
sapl/comissoes/migrations/0008_auto_20160929_1611.py

@ -0,0 +1,21 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.9.7 on 2016-09-29 19:11
from __future__ import unicode_literals
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('comissoes', '0007_merge'),
]
operations = [
migrations.AlterField(
model_name='participacao',
name='composicao',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='participacao_set', to='comissoes.Composicao'),
),
]

2
sapl/comissoes/models.py

@ -131,7 +131,7 @@ class Composicao(models.Model): # IGNORE
class Participacao(models.Model): # ComposicaoComissao
composicao = models.ForeignKey(Composicao)
composicao = models.ForeignKey(Composicao, related_name='participacao_set')
parlamentar = models.ForeignKey(Parlamentar)
cargo = models.ForeignKey(CargoComissao)
titular = models.BooleanField(verbose_name=_('Titular'))

127
sapl/comissoes/views.py

@ -1,10 +1,11 @@
from django.contrib.auth.decorators import permission_required
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.urlresolvers import reverse
from django.views.generic import ListView
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudListView, CrudUpdateView)
from sapl.crud.masterdetail import MasterDetailCrud
CrudDeleteView, CrudListView, CrudUpdateView,
MasterDetailCrud, CrudAux)
from sapl.materia.models import MateriaLegislativa, Tramitacao
from sapl.utils import permissao_tb_aux, permissoes_comissoes
@ -18,130 +19,52 @@ def pegar_url_composicao(pk):
url = reverse('sapl.comissoes:composicao_detail', kwargs={'pk': comp_pk})
return url
CargoCrud = CrudAux.build(CargoComissao, 'cargo_comissao')
PeriodoComposicaoCrud = CrudAux.build(Periodo, 'periodo_composicao_comissao')
class CargoCrud(Crud):
model = CargoComissao
help_path = 'cargo_comissao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
list_field_names = ['nome', 'unico']
def has_permission(self):
return permissao_tb_aux(self)
class PeriodoComposicaoCrud(Crud):
model = Periodo
help_path = 'periodo_composicao_comissao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
list_field_names = ['data_inicio', 'data_fim']
def has_permission(self):
return permissao_tb_aux(self)
class TipoComissaoCrud(Crud):
model = TipoComissao
help_path = 'tipo_comissao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
list_field_names = ['sigla', 'nome', 'natureza',
'dispositivo_regimental']
def has_permission(self):
return permissao_tb_aux(self)
TipoComissaoCrud = CrudAux.build(
TipoComissao, 'tipo_comissao', list_field_names=[
'sigla', 'nome', 'natureza', 'dispositivo_regimental'])
class ParticipacaoCrud(MasterDetailCrud):
model = Participacao
parent_field = 'composicao'
parent_field = 'composicao__comissao'
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)
context['root_pk'] = self.object.composicao.comissao.pk
return self.render_to_response(context)
class CreateView(MasterDetailCrud.CreateView):
def get_success_url(self):
return reverse(
'sapl.comissoes:composicao_detail',
kwargs={'pk': self.kwargs['pk']}
)
def cancel_url(self):
return reverse(
'sapl.comissoes:composicao_detail',
kwargs={'pk': self.kwargs['pk']}
)
class UpdateView(MasterDetailCrud.UpdateView):
def get_success_url(self):
return pegar_url_composicao(self.kwargs['pk'])
def cancel_url(self):
return pegar_url_composicao(self.kwargs['pk'])
class DeleteView(MasterDetailCrud.DeleteView):
def get_success_url(self):
return pegar_url_composicao(self.kwargs['pk'])
def cancel_url(self):
return pegar_url_composicao(self.kwargs['pk'])
class BaseMixin(PermissionRequiredMixin, MasterDetailCrud.BaseMixin):
permission_required = permissoes_comissoes()
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['composicao', 'parlamentar', 'cargo']
class DetailView(MasterDetailCrud.DetailView):
permission_required = []
class ComposicaoCrud(MasterDetailCrud):
model = Composicao
parent_field = 'comissao'
help_path = ''
model_set = 'participacao_set'
class DetailView(MasterDetailCrud.DetailView):
def get(self, request, *args, **kwargs):
self.object = self.get_object()
context = self.get_context_data(object=self.object)
composicao = Composicao.objects.get(id=self.kwargs['pk'])
context['participacoes'] = composicao.participacao_set.all()
return self.render_to_response(context)
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
permission_required = permissoes_comissoes()
class ListView(MasterDetailCrud.ListView):
permission_required = []
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
permission_required = permissoes_comissoes()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
permission_required = permissoes_comissoes()
class DetailView(MasterDetailCrud.DetailView):
permission_required = []
class ComissaoCrud(Crud):
model = Comissao
help_path = 'modulo_comissoes'
class CreateView(PermissionRequiredMixin, CrudCreateView):
permission_required = permissoes_comissoes()
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
permission_required = permissoes_comissoes()
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
permission_required = permissoes_comissoes()
class BaseMixin(Crud.BaseMixin):
list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao', 'ativa']
initial_order = '-ativa', 'sigla'
class ListView(CrudListView):
ordering = ['-ativa', 'sigla']
class ListView(Crud.ListView):
permission_required = []
class BaseMixin(CrudBaseMixin):
list_field_names = ['nome', 'sigla', 'tipo', 'data_criacao', 'ativa']
class DetailView(Crud.DetailView):
permission_required = []
class MateriasTramitacaoListView(ListView):

27
sapl/crispy_layout_mixin.py

@ -1,12 +1,12 @@
from math import ceil
import rtyaml
from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django import template
from django.utils import formats
from django.utils.translation import ugettext as _
import rtyaml
def heads_and_tails(list_of_lists):
@ -97,10 +97,25 @@ class CrispyLayoutFormMixin:
else:
return self.model.__name__
@property
def layout_key_set(self):
if hasattr(super(CrispyLayoutFormMixin, self), 'layout_key_set'):
return super(CrispyLayoutFormMixin, self).layout_key_set
else:
obj = self.crud if hasattr(self, 'crud') else self
return getattr(obj.model,
obj.model_set).field.model.__name__
def get_layout(self):
yaml_layout = '%s/layouts.yaml' % self.model._meta.app_config.label
return read_layout_from_yaml(yaml_layout, self.layout_key)
def get_layout_set(self):
obj = self.crud if hasattr(self, 'crud') else self
yaml_layout = '%s/layouts.yaml' % getattr(
obj.model, obj.model_set).field.model._meta.app_config.label
return read_layout_from_yaml(yaml_layout, self.layout_key_set)
@property
def fields(self):
if hasattr(self, 'form_class') and self.form_class:
@ -132,6 +147,16 @@ class CrispyLayoutFormMixin:
rows = self.get_layout()[0][1:]
return [fieldname for row in rows for fieldname, __ in row]
@property
def list_field_names_set(self):
'''The list of field names to display on table
This base implementation returns the field names
in the first fieldset of the layout.
'''
rows = self.get_layout_set()[0][1:]
return [fieldname for row in rows for fieldname, __ in row]
def get_column(self, fieldname, span):
obj = self.get_object()
verbose_name, text = get_field_display(obj, fieldname)

972
sapl/crud/base.py

File diff suppressed because it is too large

19
sapl/crud/masterdetail.py

@ -1,21 +1,21 @@
from django.utils.decorators import classonlymethod
from .base import (CREATE, LIST, Crud, CrudBaseMixin, CrudCreateView,
from .base import (ACTION_CREATE, ACTION_LIST, Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView)
class MasterDetailCrud(Crud):
class MasterDetailCrud__OBSOLETO(Crud):
class BaseMixin(CrudBaseMixin):
@property
def list_url(self):
return self.resolve_url(LIST, args=(self.kwargs['pk'],))
return self.resolve_url(ACTION_LIST, args=(self.kwargs['pk'],))
@property
def create_url(self):
return self.resolve_url(CREATE, args=(self.kwargs['pk'],))
return self.resolve_url(ACTION_CREATE, args=(self.kwargs['pk'],))
def get_context_data(self, **kwargs):
obj = getattr(self, 'object', None)
@ -24,7 +24,7 @@ class MasterDetailCrud(Crud):
else:
root_pk = self.kwargs['pk'] # in list and create
kwargs.setdefault('root_pk', root_pk)
return super(MasterDetailCrud.BaseMixin,
return super(MasterDetailCrud__OBSOLETO.BaseMixin,
self).get_context_data(**kwargs)
class ListView(CrudListView):
@ -34,7 +34,8 @@ class MasterDetailCrud(Crud):
return r'^(?P<pk>\d+)/%s$' % cls.model._meta.model_name
def get_queryset(self):
qs = super(MasterDetailCrud.ListView, self).get_queryset()
qs = super(
MasterDetailCrud__OBSOLETO.ListView, self).get_queryset()
kwargs = {self.crud.parent_field: self.kwargs['pk']}
return qs.filter(**kwargs)
@ -45,7 +46,7 @@ class MasterDetailCrud(Crud):
return r'^(?P<pk>\d+)/%s/create$' % cls.model._meta.model_name
def get_form(self, form_class=None):
form = super(MasterDetailCrud.CreateView,
form = super(MasterDetailCrud__OBSOLETO.CreateView,
self).get_form(self.form_class)
field = self.model._meta.get_field(self.crud.parent_field)
parent = field.related_model.objects.get(pk=self.kwargs['pk'])
@ -72,10 +73,10 @@ class MasterDetailCrud(Crud):
def get_success_url(self):
pk = getattr(self.get_object(), self.crud.parent_field).pk
return self.resolve_url(LIST, args=(pk,))
return self.resolve_url(ACTION_LIST, args=(pk,))
@classonlymethod
def build(cls, model, parent_field, help_path):
crud = super(MasterDetailCrud, cls).build(model, help_path)
crud = super(MasterDetailCrud__OBSOLETO, cls).build(model, help_path)
crud.parent_field = parent_field
return crud

9
sapl/crud/urls.py

@ -1,4 +1,13 @@
from builtins import LookupError
from django import apps
from django.conf.urls import include, url
from django.contrib.auth.management import _get_all_permissions
from django.core import exceptions
from django.db import models, router
from django.db.utils import DEFAULT_DB_ALIAS
from django.utils.translation import string_concat
urlpatterns = [
url(r'', include('stub_app.urls')),

99
sapl/materia/views.py

@ -2,12 +2,12 @@ from datetime import datetime
from random import choice
from string import ascii_letters, digits
from braces.views import PermissionRequiredMixin
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button
from django.conf import settings
from django.contrib import messages
from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.contrib.auth.tokens import default_token_generator
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.mail import send_mail
@ -28,8 +28,7 @@ from sapl.compilacao.views import IntegracaoTaView
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, make_pagination)
from sapl.crud.masterdetail import MasterDetailCrud
CrudUpdateView, make_pagination, MasterDetailCrud)
from sapl.norma.models import LegislacaoCitada
from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label,
autor_modal, gerar_hash_arquivo, get_base_url,
@ -74,17 +73,12 @@ class OrigemCrud(Crud):
model = Origem
help_path = 'origem'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class TipoMateriaCrud(Crud):
model = TipoMateriaLegislativa
help_path = 'tipo_materia_legislativa'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -94,7 +88,7 @@ class RegimeTramitacaoCrud(Crud):
model = RegimeTramitacao
help_path = 'regime_tramitacao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -104,7 +98,7 @@ class TipoDocumentoCrud(Crud):
model = TipoDocumento
help_path = 'tipo_documento'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -114,7 +108,7 @@ class TipoFimRelatoriaCrud(Crud):
model = TipoFimRelatoria
help_path = 'fim_relatoria'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -124,7 +118,7 @@ class TipoAutorCrud(Crud):
model = TipoAutor
help_path = 'tipo_autor'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -156,7 +150,7 @@ class AutorCrud(Crud):
model = Autor
help_path = 'autor'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
list_field_names = ['tipo', 'nome']
def has_permission(self):
@ -233,7 +227,7 @@ class OrgaoCrud(Crud):
model = Orgao
help_path = 'orgao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -243,7 +237,7 @@ class TipoProposicaoCrud(Crud):
model = TipoProposicao
help_path = 'tipo_proposicao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -253,7 +247,7 @@ class StatusTramitacaoCrud(Crud):
model = StatusTramitacao
help_path = 'status_tramitacao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -300,15 +294,15 @@ class UnidadeTramitacaoCrud(Crud):
model = UnidadeTramitacao
help_path = 'unidade_tramitacao'
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
permission_required = permissoes_materia()
form_class = UnidadeTramitacaoForm
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
permission_required = permissoes_materia()
form_class = UnidadeTramitacaoForm
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = permissoes_materia()
@ -461,7 +455,7 @@ class ProposicaoCrud(Crud):
list_field_names = ['data_envio', 'descricao',
'tipo', 'data_recebimento']
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
form_class = ProposicaoForm
permission_required = {'materia.add_proposicao'}
@ -489,7 +483,7 @@ class ProposicaoCrud(Crud):
else:
return {'autor': autor_id}
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
form_class = ProposicaoForm
permission_required = permissoes_autor()
@ -525,7 +519,7 @@ class ProposicaoCrud(Crud):
messages.add_message(self.request, messages.ERROR, msg)
return False
class DetailView(PermissionRequiredMixin, CrudDetailView):
class DetailView(CrudDetailView):
permission_required = permissoes_autor()
def has_permission(self):
@ -542,7 +536,7 @@ class ProposicaoCrud(Crud):
context['subnav_template_name'] = ''
return context
class ListView(PermissionRequiredMixin, CrudListView):
class ListView(CrudListView):
ordering = ['-data_envio', 'descricao']
permission_required = permissoes_autor()
@ -572,7 +566,7 @@ class ProposicaoCrud(Crud):
return lista
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = {'materia.delete_proposicao'}
def has_permission(self):
@ -637,7 +631,7 @@ class RelatoriaCrud(MasterDetailCrud):
parent_field = 'materia'
help_path = ''
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_materia()
form_class = RelatoriaForm
@ -658,11 +652,11 @@ class RelatoriaCrud(MasterDetailCrud):
return {'comissao': localizacao}
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_materia()
form_class = RelatoriaForm
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
@ -674,8 +668,9 @@ class TramitacaoCrud(MasterDetailCrud):
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['data_tramitacao', 'unidade_tramitacao_local',
'unidade_tramitacao_destino', 'status']
initial_order = '-data_tramitacao'
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = TramitacaoForm
permission_required = permissoes_materia()
@ -692,7 +687,7 @@ class TramitacaoCrud(MasterDetailCrud):
do_envia_email_tramitacao(request, materia)
return super(CreateView, self).post(request, *args, **kwargs)
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoUpdateForm
permission_required = permissoes_materia()
@ -713,7 +708,7 @@ class TramitacaoCrud(MasterDetailCrud):
kwargs = {self.crud.parent_field: self.kwargs['pk']}
return qs.filter(**kwargs).order_by('-data_tramitacao', '-id')
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
def delete(self, request, *args, **kwargs):
@ -771,7 +766,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['nome', 'tipo', 'data', 'autor', 'arquivo']
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
@ -784,7 +779,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
context['helper'] = self.helper
return context
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
@ -797,7 +792,7 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
context['helper'] = self.helper
return context
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
@ -806,15 +801,15 @@ class AutoriaCrud(MasterDetailCrud):
parent_field = 'materia'
help_path = ''
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = AutoriaForm
permission_required = permissoes_materia()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AutoriaForm
permission_required = permissoes_materia()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
@ -823,15 +818,15 @@ class DespachoInicialCrud(MasterDetailCrud):
parent_field = 'materia'
help_path = ''
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = DespachoInicialForm
permission_required = permissoes_materia()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = DespachoInicialForm
permission_required = permissoes_materia()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
@ -848,11 +843,11 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
return reverse('%s:%s' % (namespace, self.url_name(suffix)),
args=args)
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = LegislacaoCitadaForm
permission_required = permissoes_materia()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = LegislacaoCitadaForm
permission_required = permissoes_materia()
@ -862,7 +857,7 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
self.initial['ano'] = self.object.norma.ano
return self.initial
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class DetailView(MasterDetailCrud.DetailView):
@ -877,15 +872,15 @@ class NumeracaoCrud(MasterDetailCrud):
parent_field = 'materia'
help_path = ''
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = NumeracaoForm
permission_required = permissoes_materia()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = NumeracaoForm
permission_required = permissoes_materia()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
@ -897,11 +892,11 @@ class AnexadaCrud(MasterDetailCrud):
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['materia_anexada', 'data_anexacao']
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = AnexadaForm
permission_required = permissoes_materia()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AnexadaForm
permission_required = permissoes_materia()
@ -918,7 +913,7 @@ class AnexadaCrud(MasterDetailCrud):
def layout_key(self):
return 'AnexadaDetail'
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
@ -929,13 +924,13 @@ class MateriaLegislativaCrud(Crud):
class BaseMixin(CrudBaseMixin):
list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao']
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
permission_required = permissoes_materia()
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
permission_required = permissoes_materia()
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = permissoes_materia()

10
sapl/norma/views.py

@ -20,7 +20,7 @@ class AssuntoNormaCrud(Crud):
model = AssuntoNorma
help_path = 'assunto_norma_juridica'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
permission_required = permissoes_norma()
list_field_names = ['assunto', 'descricao']
@ -29,7 +29,7 @@ class TipoNormaCrud(Crud):
model = TipoNormaJuridica
help_path = 'tipo_norma_juridica'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
permission_required = permissoes_norma()
list_field_names = ['equivalente_lexml', 'sigla', 'descricao']
@ -38,7 +38,7 @@ class NormaCrud(Crud):
model = NormaJuridica
help_path = 'norma_juridica'
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
form_class = NormaJuridicaForm
permission_required = permissoes_norma()
@ -54,7 +54,7 @@ class NormaCrud(Crud):
self.initial['numero_materia'] = norma.materia.numero
return self.initial.copy()
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
form_class = NormaJuridicaForm
permission_required = permissoes_norma()
@ -62,7 +62,7 @@ class NormaCrud(Crud):
def layout_key(self):
return 'NormaJuridicaCreate'
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = permissoes_norma()
class BaseMixin(CrudBaseMixin):

74
sapl/parlamentares/views.py

@ -1,5 +1,4 @@
from django.contrib import messages
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
@ -12,8 +11,7 @@ from django.views.generic import FormView, ListView
from sapl.comissoes.models import Participacao
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView)
from sapl.crud.masterdetail import MasterDetailCrud
CrudUpdateView, MasterDetailCrud)
from sapl.materia.models import Proposicao, Relatoria
from sapl.utils import permissao_tb_aux, permissoes_parlamentares
@ -50,10 +48,10 @@ class FrenteCrud(Crud):
def has_permission(self):
return permissao_tb_aux(self)
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
form_class = FrenteForm
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
form_class = FrenteForm
@ -65,13 +63,13 @@ class RelatoriaParlamentarCrud(MasterDetailCrud):
class ListView(MasterDetailCrud.ListView):
permission_required = permissoes_parlamentares()
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_parlamentares()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_parlamentares()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_parlamentares()
@ -102,13 +100,13 @@ class ProposicaoParlamentarCrud(MasterDetailCrud):
else:
return proposicoes
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_parlamentares()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_parlamentares()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_parlamentares()
@ -140,13 +138,13 @@ class ParticipacaoParlamentarCrud(MasterDetailCrud):
def get_headers(self):
return ['Comissão', 'Cargo', 'Período']
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_parlamentares()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_parlamentares()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_parlamentares()
@ -154,7 +152,7 @@ class CargoMesaCrud(Crud):
model = CargoMesa
help_path = 'cargo_mesa'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -164,7 +162,7 @@ class PartidoCrud(Crud):
model = Partido
help_path = 'partidos'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -174,7 +172,7 @@ class SessaoLegislativaCrud(Crud):
model = SessaoLegislativa
help_path = 'sessao_legislativa'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -184,7 +182,7 @@ class TipoDependenteCrud(Crud):
model = TipoDependente
help_path = 'nivel_instrucao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -194,7 +192,7 @@ class NivelInstrucaoCrud(Crud):
model = NivelInstrucao
help_path = 'tipo_dependente'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -204,7 +202,7 @@ class TipoAfastamentoCrud(Crud):
model = TipoAfastamento
help_path = 'tipo_afastamento'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -214,7 +212,7 @@ class TipoMilitarCrud(Crud):
model = SituacaoMilitar
help_path = 'tipo_situa_militar'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -225,19 +223,19 @@ class DependenteCrud(MasterDetailCrud):
parent_field = 'parlamentar'
help_path = ''
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_parlamentares()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_parlamentares()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_parlamentares()
class ListView(PermissionRequiredMixin, MasterDetailCrud.ListView):
class ListView(MasterDetailCrud.ListView):
permission_required = permissoes_parlamentares()
class DetailView(PermissionRequiredMixin, MasterDetailCrud.DetailView):
class DetailView(MasterDetailCrud.DetailView):
permission_required = permissoes_parlamentares()
@ -249,13 +247,13 @@ class MandatoCrud(MasterDetailCrud):
class ListView(MasterDetailCrud.ListView):
ordering = ('-legislatura__numero')
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_parlamentares()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_parlamentares()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_parlamentares()
@ -266,7 +264,7 @@ class ColigacaoCrud(Crud):
class ListView(CrudListView):
ordering = ('-numero_votos', 'nome')
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -294,7 +292,7 @@ class ComposicaoColigacaoCrud(MasterDetailCrud):
class ListView(MasterDetailCrud.ListView):
ordering = '-partido__sigla'
class BaseMixin(PermissionRequiredMixin, MasterDetailCrud.BaseMixin):
class BaseMixin(MasterDetailCrud.BaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -310,7 +308,7 @@ class LegislaturaCrud(Crud):
class UpdateView(CrudUpdateView):
form_class = LegislaturaForm
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -321,15 +319,15 @@ class FiliacaoCrud(MasterDetailCrud):
parent_field = 'parlamentar'
help_path = ''
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = FiliacaoForm
permission_required = permissoes_parlamentares()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = FiliacaoForm
permission_required = permissoes_parlamentares()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_parlamentares()
class ListView(MasterDetailCrud.ListView):
@ -362,11 +360,11 @@ class ParlamentarCrud(Crud):
else:
return ['parlamentares/parlamentar_perfil_publico.html']
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
form_class = ParlamentarForm
permission_required = permissoes_parlamentares()
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
form_class = ParlamentarCreateForm
permission_required = permissoes_parlamentares()
@ -374,7 +372,7 @@ class ParlamentarCrud(Crud):
def layout_key(self):
return 'ParlamentarCreate'
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
form_class = ParlamentarCreateForm
permission_required = permissoes_parlamentares()

40
sapl/protocoloadm/views.py

@ -1,9 +1,8 @@
import json
from datetime import date, datetime
import json
from braces.views import FormValidMessageMixin
from braces.views import FormValidMessageMixin, PermissionRequiredMixin
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Max, Q
@ -14,15 +13,15 @@ from django.views.generic import CreateView, DetailView, FormView, ListView
from django.views.generic.base import TemplateView
from django_filters.views import FilterView
import sapl.crud.base
from sapl.base.models import AppConfig
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, make_pagination)
from sapl.crud.masterdetail import MasterDetailCrud
CrudDetailView, CrudDeleteView,
CrudListView, CrudUpdateView,
make_pagination, MasterDetailCrud)
from sapl.materia.models import TipoMateriaLegislativa
from sapl.utils import (create_barcode, get_client_ip, permissoes_adm,
permissoes_protocoloadm)
import sapl.crud.base
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoFilterSet,
@ -35,6 +34,7 @@ from .models import (Autor, DocumentoAcessorioAdministrativo,
TipoDocumentoAdministrativo, TipoInstituicao,
TramitacaoAdministrativo)
TipoDocumentoAdministrativoCrud = Crud.build(TipoDocumentoAdministrativo, '')
DocumentoAcessorioAdministrativoCrud = Crud.build(
DocumentoAcessorioAdministrativo, '')
@ -53,16 +53,16 @@ class DocumentoAdministrativoCrud(Crud):
'numero_protocolo', 'assunto',
'interessado', 'tramitacao', 'texto_integral']
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
permission_required = permissoes_adm()
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
permission_required = permissoes_adm()
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = permissoes_adm()
class ListView(PermissionRequiredMixin, CrudListView):
class ListView(CrudListView):
permission_required = permissoes_adm()
def has_permission(self):
@ -75,7 +75,7 @@ class DocumentoAdministrativoCrud(Crud):
perms = self.get_permission_required()
return self.request.user.has_perms(perms)
class DetailView(PermissionRequiredMixin, CrudDetailView):
class DetailView(CrudDetailView):
permission_required = permissoes_adm()
def has_permission(self):
@ -99,13 +99,13 @@ class StatusTramitacaoAdministrativoCrud(Crud):
class ListView(CrudListView):
ordering = 'sigla'
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
permission_required = permissoes_adm()
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
permission_required = permissoes_adm()
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = permissoes_adm()
@ -603,18 +603,18 @@ class TramitacaoAdmCrud(MasterDetailCrud):
list_field_names = ['data_tramitacao', 'unidade_tramitacao_local',
'unidade_tramitacao_destino', 'status']
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = TramitacaoAdmForm
permission_required = permissoes_adm()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoAdmEditForm
permission_required = permissoes_adm()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_adm()
class ListView(PermissionRequiredMixin, MasterDetailCrud.ListView):
class ListView(MasterDetailCrud.ListView):
permission_required = permissoes_adm()
def get_queryset(self):
@ -632,7 +632,7 @@ class TramitacaoAdmCrud(MasterDetailCrud):
perms = self.get_permission_required()
return self.request.user.has_perms(perms)
class DetailView(PermissionRequiredMixin, MasterDetailCrud.DetailView):
class DetailView(MasterDetailCrud.DetailView):
permission_required = permissoes_adm()
def has_permission(self):

61
sapl/sessao/views.py

@ -1,8 +1,8 @@
from datetime import datetime
from re import sub
from braces.views import PermissionRequiredMixin
from django.contrib import messages
from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist, ValidationError
from django.core.urlresolvers import reverse
from django.forms.utils import ErrorList
@ -18,8 +18,7 @@ from rest_framework import generics
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, make_pagination)
from sapl.crud.masterdetail import MasterDetailCrud
CrudUpdateView, make_pagination, MasterDetailCrud)
from sapl.materia.forms import pega_ultima_tramitacao
from sapl.materia.models import (Autoria, DocumentoAcessorio,
TipoMateriaLegislativa, Tramitacao)
@ -43,6 +42,7 @@ from .models import (Bancada, Bloco, CargoBancada, CargoMesa,
SessaoPlenariaPresenca, TipoExpediente,
TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar)
OrdemDiaCrud = Crud.build(OrdemDia, '')
RegistroVotacaoCrud = Crud.build(RegistroVotacao, '')
@ -77,7 +77,7 @@ class BlocoCrud(Crud):
model = Bloco
help_path = ''
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
list_field_names = ['nome', 'data_criacao', 'partidos']
def has_permission(self):
@ -88,7 +88,7 @@ class BancadaCrud(Crud):
model = Bancada
help_path = ''
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
list_field_names = ['nome', 'legislatura']
def has_permission(self):
@ -108,7 +108,8 @@ class TipoSessaoCrud(Crud):
model = TipoSessaoPlenaria
help_path = 'tipo_sessao_plenaria'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -117,7 +118,8 @@ class TipoResultadoVotacaoCrud(Crud):
model = TipoResultadoVotacao
help_path = 'tipo_resultado_votacao'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -126,7 +128,8 @@ class TipoExpedienteCrud(Crud):
model = TipoExpediente
help_path = 'tipo_expediente'
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -135,7 +138,8 @@ class CargoBancadaCrud(Crud):
model = CargoBancada
help_path = ''
class BaseMixin(PermissionRequiredMixin, CrudBaseMixin):
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
@ -198,6 +202,7 @@ class MateriaOrdemDiaCrud(MasterDetailCrud):
return self.initial
class DetailView(MasterDetailCrud.DetailView):
@property
def layout_key(self):
return 'OrdemDiaDetail'
@ -370,7 +375,7 @@ class ExpedienteMateriaCrud(MasterDetailCrud):
obj.resultado)
return [self._as_row(obj) for obj in object_list]
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
form_class = ExpedienteMateriaForm
permission_required = permissoes_sessao()
@ -378,7 +383,7 @@ class ExpedienteMateriaCrud(MasterDetailCrud):
return reverse('sapl.sessao:expedientemateria_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
form_class = ExpedienteMateriaForm
permission_required = permissoes_sessao()
@ -406,20 +411,20 @@ class OradorCrud(MasterDetailCrud):
class ListView(MasterDetailCrud.ListView):
ordering = ['numero_ordem', 'parlamentar']
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_sessao()
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_sessao()
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_sessao()
class OradorExpedienteCrud(OradorCrud):
model = OradorExpediente
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_sessao()
form_class = OradorExpedienteForm
@ -427,18 +432,18 @@ class OradorExpedienteCrud(OradorCrud):
return reverse('sapl.sessao:oradorexpediente_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_sessao()
form_class = OradorExpedienteForm
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_sessao()
class OradorCrud(OradorCrud):
model = Orador
class CreateView(PermissionRequiredMixin, MasterDetailCrud.CreateView):
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_sessao()
form_class = OradorForm
@ -446,11 +451,11 @@ class OradorCrud(OradorCrud):
return reverse('sapl.sessao:orador_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(PermissionRequiredMixin, MasterDetailCrud.UpdateView):
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_sessao()
form_class = OradorForm
class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView):
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_sessao()
@ -483,7 +488,7 @@ class SessaoCrud(Crud):
class ListView(CrudListView):
ordering = ['-data_inicio']
class CreateView(PermissionRequiredMixin, CrudCreateView):
class CreateView(CrudCreateView):
permission_required = permissoes_sessao()
def get_initial(self):
@ -493,10 +498,10 @@ class SessaoCrud(Crud):
return {'legislatura': legislatura,
'sessao_legislativa': sessao_legislativa}
class UpdateView(PermissionRequiredMixin, CrudUpdateView):
class UpdateView(CrudUpdateView):
permission_required = permissoes_sessao()
class DeleteView(PermissionRequiredMixin, CrudDeleteView):
class DeleteView(CrudDeleteView):
permission_required = permissoes_sessao()
@ -2118,11 +2123,11 @@ class PesquisarPautaSessaoView(PesquisarSessaoPlenariaView):
def filtra_tramitacao_ordem_dia():
lista = pega_ultima_tramitacao()
return Tramitacao.objects.filter(
id__in=lista,
status__descricao='Ordem do Dia').distinct().values_list(
'materia_id', flat=True)
lista = pega_ultima_tramitacao()
return Tramitacao.objects.filter(
id__in=lista,
status__descricao='Ordem do Dia').distinct().values_list(
'materia_id', flat=True)
def retira_materias_ja_adicionadas(id_sessao, model):

7
sapl/static/styles/app.scss

@ -70,6 +70,13 @@ h6, .h6 {
color: inherit;
}
.caret {
/* Por padrão caret aponta para baixo*/
&.top {
transform: rotate(180deg);
}
}
// #### CRUD DETAIL ########################################
p.control-label {
font-weight: bold;

6
sapl/templates/base.html

@ -103,11 +103,11 @@
<!-- <li class="nav__sub-item"><a class="nav__sub-link" href="#">Índice de Assuntos</a></li> -->
</ul>
</li>
{% if user|ver_menu_sistema_perm %}
<li class="dropdown">
{% if perms.base.menu_sistemas %}
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">Sistema <span class="caret"></span></a>
<ul class="dropdown-menu">
<li class="nav__sub-item"><a class="nav__sub-link" href="/sistema">Tabelas Auxiliares</a></li>
{% if perms.base.view_tabelas_auxiliares %}<li class="nav__sub-item"><a class="nav__sub-link" href="/sistema">Tabelas Auxiliares</a></li>{%endif%}
<!-- <li class="nav__sub-item"><a class="nav__sub-link" href="#">Provedor LexML</a></li>
<li class="nav__sub-item"><a class="nav__sub-link" href="#">Publicador LexML</a></li>
<li class="nav__sub-item"><a class="nav__sub-link" href="#">Gerenciar Usuários</a></li>

2
sapl/templates/crud/ajax_form.html

@ -0,0 +1,2 @@
{% load i18n crispy_forms_tags %}
{% crispy form %}

9
sapl/templates/crud/confirm_delete.html

@ -3,13 +3,12 @@
{% block base_content %}
<form action="" method="post">{% csrf_token %}
<br>
<div class="panel panel-danger">
<div class="panel-heading text-center">
{% block msg %}
{% blocktrans %}
Confirma exclusão de "{{ object }}"?
{% endblocktrans %}
{% endblock msg %}
{% blocktrans %}
Confirma exclusão de "{{ object }}"?
{% endblocktrans %}
</div>
<div class="panel-body text-center">
<a href="{{ view.cancel_url }}" class="btn btn-inverse">{% trans 'Cancelar' %}</a>

96
sapl/templates/crud/detail.html

@ -1,45 +1,83 @@
{% extends "base.html" %}
{% load i18n %}
{% load common_tags %}
{% load i18n common_tags%}
{% block base_content %}
<div class="clearfix">
<div class="context-actions clearfix">
{% block actions %}
<div class="actions btn-group pull-right" role="group">
{% if perms|get_change_perm:view %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar' %}</a>
{% endif %}
{% if perms|get_delete_perm:view %}
<a href="{{ view.delete_url }}" class="btn btn-default">{% trans 'Excluir' %}</a>
<div class="actions btn-group btn-group-sm" role="group">
{% if view.list_url %}
<a href="{{ view.list_url }}?list" class="btn btn-default">{% trans 'Listar' %} {{view.verbose_name_plural}}</a>
{% endif %}
{% if view.create_url %}
<a href="{{ view.create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% endif %}
</div>
{% if view.update_url or view.delete_url %}
<div class="actions btn-group pull-right" role="group">
{% if view.update_url %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar' %}</a>
{% endif %}
{% if view.delete_url %}
<a href="{{ view.delete_url }}" class="btn btn-danger">{% trans 'Excluir' %}</a>
{% endif %}
</div>
{% endif %}
</div>
{% endblock actions %}
</div>
{% block extra_msg %}{% endblock extra_msg %}
{% block detail_content %}
{% for fieldset in view.layout_display %}
<h2 class="legend">{{ fieldset.legend }}</h2>
{% for row in fieldset.rows %}
<div class="row-fluid">
{% for column in row %}
<div class="col-sm-{{ column.span }}">
<div id="div_id_{{ column.id }}" class="form-group">
<p class="control-label">{{ column.verbose_name }}</p>
<div class="controls">
{% if column.text %}
<p class="form-control-static">{{ column.text|safe }}</p>
{% else %}
<p class="form-control-static">Não informado</p>
{% endif %}
</div>
<h2 class="legend">{{ fieldset.legend }}</h2>
{% for row in fieldset.rows %}
<div class="row-fluid">
{% for column in row %}
<div class="col-sm-{{ column.span }}">
<div id="div_id_{{ column.id }}" class="form-group">
<p class="control-label">{{ column.verbose_name }}</p>
<div class="controls">
<div class="form-control-static">{{ column.text|safe }}</div>
</div>
</div>
</div>
{% endfor %}
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% endfor %}
{% endblock detail_content %}
<div class="container-table">
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<div class="result-count">{% blocktrans with verbose_name_plural=view.model_set_verbose_name_plural %}Total de {{ verbose_name_plural }}: <strong>{{count}}</strong>{% endblocktrans %}</div>
<table class="table table-striped table-hover">
<thead>
<tr>
{% for name in headers %}
<th>{{ name }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in rows %}
<tr>
{% for value, href in value_list %}
<td>
{% if href %}
<a href="{{ href }}">{{ value }}</a>
{% elif value != 'core.Cep.None' %}
{{ value|safe }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% include "paginacao.html" %}
{% endblock base_content %}

92
sapl/templates/crud/detail_detail.html

@ -0,0 +1,92 @@
{% extends "base.html" %}
{% load i18n common_tags%}
{% block base_content %}
<div class="context-actions clearfix">
{% block actions %}
<div class="actions btn-group btn-group-sm" role="group">
{% if view.detail_list_url %}
<a href="{{ view.detail_list_url }}?list" class="btn btn-default">{% trans 'Listar' %} {{view.verbose_name_plural}}</a>
{% endif %}
{% if view.detail_create_url %}
<a href="{{ view.detail_create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% endif %}
</div>
{% if view.update_url or view.delete_url %}
<div class="actions btn-group pull-right " role="group">
{% if view.update_url %}
<a href="{{ view.update_url }}" class="btn btn-default">{% trans 'Editar' %}</a>
{% endif %}
{% if view.delete_url %}
<a href="{{ view.delete_url }}" class="btn btn-default btn-excluir">{% trans 'Excluir' %}</a>
{% endif %}
</div>
{% endif %}
{% endblock actions %}
</div>
{% block detail_content %}
{% for fieldset in view.layout_display %}
<h2 class="legend">{{ fieldset.legend }}</h2>
{% for row in fieldset.rows %}
<div class="row-fluid">
{% for column in row %}
<div class="col-sm-{{ column.span }}">
<div id="div_id_{{ column.id }}" class="form-group">
<p class="control-label">{{ column.verbose_name }}</p>
<div class="controls">
<div class="form-control-static">{{ column.text|safe }}</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
{% endfor %}
{% endblock detail_content %}
<div class="actions btn-group pull-right btn-group-lg" role="group">
{% if view.detail_set_create_url %}
<a href="{{ view.detail_set_create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name_set %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% endif %}
{% block more_buttons %}{% endblock more_buttons %}
</div>
<div class="container-table">
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<div class="result-count">{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de Registros: <strong>{{count}}</strong>{% endblocktrans %}</div>
<table class="table table-striped table-hover">
<thead>
<tr>
{% for name in headers %}
<th>{{ name }}</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in rows %}
<tr>
{% for value, href in value_list %}
<td>
{% if href %}
<a href="{{ href }}">{{ value }}</a>
{% elif valu != 'core.Cep.None' %}
{{ value|safe }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
{% include "paginacao.html" %}
{% endblock base_content %}

2
sapl/templates/crud/form.html

@ -1,6 +1,6 @@
{% extends "base.html" %}
{% load i18n crispy_forms_tags %}
{% block base_content %}
{% block extra_msg %}{% endblock %}
{% crispy form %}
{% endblock %}

80
sapl/templates/crud/list.html

@ -1,48 +1,68 @@
{% extends "base.html" %}
{% load i18n %}
{% load common_tags %}
{% load i18n common_tags crispy_forms_tags%}
{% block base_content %}
<div class="actions btn-group pull-right" role="group">
{% if perms|get_add_perm:view %}
<a href="{{ view.create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% endif %}
{% block more_buttons %}{% endblock more_buttons %}
<div class="context-actions clearfix">
<div class="actions search pull-left">
{% if form %}
{% crispy form %}
{% endif %}
</div>
{% block actions %}
<div class="actions btn-group pull-right btn-group-lg" role="group">
{% if view.create_url %}
<a href="{{ view.create_url }}" class="btn btn-default">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a>
{% endif %}
{% block more_buttons %}{% endblock more_buttons %}
</div>
{% endblock actions %}
</div>
<br/><br/>
{% block extra_content %} {% endblock %}
{% if not rows %}
<p>{{ NO_ENTRIES_MSG }}</p>
{% else %}
<table class="table table-striped table-hover">
<thead>
<div class="container-table">
<div class="result-count">{% blocktrans with verbose_name_plural=view.verbose_name_plural %}Total de {{ verbose_name_plural }}: <strong>{{count}}</strong>{% endblocktrans %}</div>
<table class="table table-striped table-hover table-link-ordering">
<thead>
<tr>
{% for name in headers %}
<th>
<a title="{% trans 'Clique para alterar a ordem a listagem'%}" href="?o={% if 'o' not in request.GET and view.initial_order.0 != '-' or 'o' not in request.GET and not view.initial_order and forloop.counter == 1 or 'o' in request.GET and forloop.counter|safe == request.GET.o %}-{%endif%}{{forloop.counter}}{{ordering_url}}">{{ name }}
{% if 'o' not in request.GET and view.initial_order and view.initial_order.0 != '-' or 'o' not in request.GET and not view.initial_order and forloop.counter == 1 or 'o' in request.GET and forloop.counter|safe == request.GET.o %}
<span class="caret top" title="{% trans 'Listado na Ordem Ascendente'%}"></span>
{% elif 'o' not in request.GET and view.initial_order and view.initial_order.0 == '-' or 'o' in request.GET and forloop.counter == request.GET.o|str2intabs %}
<span class="caret" title="{% trans 'Listado na Ordem Descendente'%}"></span>
{%endif%}
</a>
</th>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in rows %}
<tr>
{% for name in headers %}
<th>{{ name }}</th>
{% for value, href in value_list %}
<td>
{% if href %}
<a href="{{ href }}">{{ value }}</a>
{% elif valu != 'core.Cep.None' %}
{{ value|safe }}
{% endif %}
</td>
{% endfor %}
</tr>
</thead>
<tbody>
{% for value_list in rows %}
<tr>
{% for value, href in value_list %}
<td>
{% if href %}
<a href="{{ href }}">{{ value }}</a>
{% else %}
{{ value|safe }}
{% endif %}
</td>
{% endfor %}
</tr>
{% endfor %}
</tbody>
</table>
</tbody>
</table>
</div>
{% endif %}
{% include "paginacao.html" %}

10
sapl/utils.py

@ -1,8 +1,8 @@
import hashlib
from datetime import date
from functools import wraps
from unicodedata import normalize as unicodedata_normalize
import hashlib
import magic
from django import forms
from django.apps import apps
from django.conf import settings
@ -12,6 +12,12 @@ from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import ValidationError
from django.utils.translation import ugettext_lazy as _
from floppyforms import ClearableFileInput
import magic
def normalize(txt):
return unicodedata_normalize(
'NFKD', txt).encode('ASCII', 'ignore').decode('ASCII')
def get_settings_auth_user_model():

Loading…
Cancel
Save