Browse Source

Ajusta imports e alguns erros de testes

pull/675/head
LeandroRoberto 8 years ago
parent
commit
0d8bf836d0
  1. 6
      sapl/base/models.py
  2. 3
      sapl/base/templatetags/menus.py
  3. 2
      sapl/crispy_layout_mixin.py
  4. 10
      sapl/crud/base.py
  5. 1
      sapl/legacy/management/commands/migracao_25_31.py
  6. 6
      sapl/lexml/views.py
  7. 7
      sapl/materia/forms.py
  8. 1
      sapl/materia/models.py
  9. 282
      sapl/materia/views.py
  10. 9
      sapl/norma/views.py
  11. 22
      sapl/parlamentares/views.py
  12. 9
      sapl/protocoloadm/views.py
  13. 35
      sapl/sessao/views.py
  14. 40
      scripts/inicializa_grupos_autorizacoes.py
  15. 3
      scripts/test_inicializa_grupos_autorizacoes.py

6
sapl/base/models.py

@ -7,11 +7,12 @@ from django.contrib.contenttypes.models import ContentType
from django.core import exceptions
from django.db import models, router
from django.db.utils import DEFAULT_DB_ALIAS
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
from sapl.utils import UF, YES_NO_CHOICES
TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')),
('R', _('Restritivo')))
@ -201,7 +202,8 @@ def create_proxy_permissions(
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")
"""

3
sapl/base/templatetags/menus.py

@ -1,7 +1,6 @@
import yaml
from django import template
from django.core.urlresolvers import reverse
import yaml
register = template.Library()

2
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):

10
sapl/crud/base.py

@ -17,7 +17,7 @@ from django.utils.translation import string_concat
from django.utils.translation import ugettext_lazy as _
from django.views.generic import (CreateView, DeleteView, DetailView, ListView,
UpdateView)
from django.views.generic.base import ContextMixin, View
from django.views.generic.base import ContextMixin
from django.views.generic.list import MultipleObjectMixin
from sapl.crispy_layout_mixin import CrispyLayoutFormMixin, get_field_display
@ -204,6 +204,7 @@ class PermissionRequiredContainerCrudMixin(PermissionRequiredMixin):
class CrudBaseMixin(CrispyLayoutFormMixin):
def __init__(self, **kwargs):
super(CrudBaseMixin, self).__init__(**kwargs)
obj = self.crud if hasattr(self, 'crud') else self
self.app_label = obj.model._meta.app_label
self.model_name = obj.model._meta.model_name
@ -1024,8 +1025,8 @@ class MasterDetailCrud(Crud):
def get_form(self, form_class=None):
obj = self.crud if hasattr(self, 'crud') else self
form = super(CrudCreateView,
self).get_form(self.form_class)
form = super(MasterDetailCrud.CreateView, self).get_form(
self.form_class)
if not obj.is_m2m:
parent_field = obj.parent_field.split('__')[0]
field = self.model._meta.get_field(parent_field)
@ -1168,7 +1169,8 @@ class MasterDetailCrud(Crud):
@property
def detail_set_create_url(self):
obj = self.crud if hasattr(self, 'crud') else self
if hasattr(obj, 'model_set') and self.request.user.has_perm(
if hasattr(obj, 'model_set') and obj.model_set\
and self.request.user.has_perm(
self.permission_set(RP_ADD)):
root_pk = self.object .pk
pk = root_pk

1
sapl/legacy/management/commands/migracao_25_31.py

@ -1,4 +1,5 @@
from django.core.management.base import BaseCommand
from sapl.legacy import migration

6
sapl/lexml/views.py

@ -1,6 +1,6 @@
from sapl.crud.base import Crud
from sapl.crud.base import CrudAux
from .models import LexmlProvedor, LexmlPublicador
LexmlProvedorCrud = Crud.build(LexmlProvedor, 'lexml_provedor')
LexmlPublicadorCrud = Crud.build(LexmlPublicador, 'lexml_publicador')
LexmlProvedorCrud = CrudAux.build(LexmlProvedor, 'lexml_provedor')
LexmlPublicadorCrud = CrudAux.build(LexmlPublicador, 'lexml_publicador')

7
sapl/materia/forms.py

@ -1,6 +1,5 @@
from datetime import datetime
import django_filters
from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout
from django import forms
@ -12,6 +11,7 @@ from django.db import models, transaction
from django.db.models import Max
from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _
import django_filters
from sapl.comissoes.models import Comissao
from sapl.crispy_layout_mixin import form_actions, to_row
@ -27,6 +27,7 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa,
Tramitacao, UnidadeTramitacao)
ANO_CHOICES = [('', '---------')] + RANGE_ANOS
@ -427,6 +428,10 @@ class AnexadaForm(ModelForm):
ano = forms.CharField(label='Ano', required=True)
def __init__(self, *args, **kwargs):
return super(AnexadaForm, self).__init__(*args, **kwargs)
def clean(self):
if self.errors:
return self.errors

1
sapl/materia/models.py

@ -589,6 +589,7 @@ class Tramitacao(models.Model):
class Meta:
verbose_name = _('Tramitação')
verbose_name_plural = _('Tramitações')
ordering = 'data_tramitacao',
def __str__(self):
return _('%(materia)s | %(status)s | %(data)s') % {

282
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
@ -26,24 +26,20 @@ from django_filters.views import FilterView
from sapl.base.models import CasaLegislativa
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, MasterDetailCrud, make_pagination)
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, CrudDetailView,
MasterDetailCrud, make_pagination)
from sapl.materia.forms import AnexadaForm
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,
permissao_tb_aux, permissoes_autor, permissoes_materia,
permissoes_autor, permissoes_materia,
permissoes_protocoloadm)
from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm,
AnexadaForm, AutorForm, AutoriaForm,
ConfirmarProposicaoForm, DespachoInicialForm,
DocumentoAcessorioForm, LegislacaoCitadaForm,
MateriaLegislativaFilterSet, NumeracaoForm,
AutorForm, ConfirmarProposicaoForm, DocumentoAcessorioForm,
MateriaLegislativaFilterSet,
PrimeiraTramitacaoEmLoteFilterSet, ProposicaoForm,
ReceberProposicaoForm, RelatoriaForm,
TramitacaoEmLoteFilterSet, TramitacaoForm,
TramitacaoUpdateForm, UnidadeTramitacaoForm,
ReceberProposicaoForm, TramitacaoEmLoteFilterSet,
filtra_tramitacao_destino,
filtra_tramitacao_destino_and_status,
filtra_tramitacao_status)
@ -54,8 +50,26 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao,
Tramitacao, UnidadeTramitacao)
AnexadaCrud = Crud.build(Anexada, '')
OrigemCrud = Crud.build(Origem, '')
TipoMateriaCrud = CrudAux.build(
TipoMateriaLegislativa, 'tipo_materia_legislativa')
RegimeTramitacaoCrud = CrudAux.build(
RegimeTramitacao, 'regime_tramitacao')
TipoDocumentoCrud = CrudAux.build(
TipoDocumento, 'tipo_documento')
TipoFimRelatoriaCrud = CrudAux.build(
TipoFimRelatoria, 'fim_relatoria')
TipoAutorCrud = CrudAux.build(
TipoAutor, 'regime_tramitacao')
def recuperar_materia(request):
tipo = TipoMateriaLegislativa.objects.get(pk=request.GET['tipo'])
@ -69,61 +83,6 @@ def recuperar_materia(request):
return response
class OrigemCrud(Crud):
model = Origem
help_path = 'origem'
class TipoMateriaCrud(Crud):
model = TipoMateriaLegislativa
help_path = 'tipo_materia_legislativa'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class RegimeTramitacaoCrud(Crud):
model = RegimeTramitacao
help_path = 'regime_tramitacao'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class TipoDocumentoCrud(Crud):
model = TipoDocumento
help_path = 'tipo_documento'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class TipoFimRelatoriaCrud(Crud):
model = TipoFimRelatoria
help_path = 'fim_relatoria'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class TipoAutorCrud(Crud):
model = TipoAutor
help_path = 'tipo_autor'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
def montar_helper_autor(self):
autor_row = montar_row_autor('nome')
self.helper = FormHelper()
@ -146,18 +105,14 @@ def montar_helper_autor(self):
' class="btn btn-inverse">Cancelar</a>')]))
class AutorCrud(Crud):
class AutorCrud(CrudAux):
model = Autor
help_path = 'autor'
class BaseMixin(CrudBaseMixin):
class BaseMixin(CrudAux.BaseMixin):
list_field_names = ['tipo', 'nome']
def has_permission(self):
return permissao_tb_aux(self)
class UpdateView(CrudUpdateView):
form_class = AutorForm
class UpdateView(CrudAux.UpdateView):
layout_key = 'AutorCreate'
def __init__(self, *args, **kwargs):
@ -169,7 +124,7 @@ class AutorCrud(Crud):
context['helper'] = self.helper
return context
class CreateView(CrudCreateView):
class CreateView(CrudAux.CreateView):
form_class = AutorForm
layout_key = 'AutorCreate'
@ -223,34 +178,10 @@ class ConfirmarEmailView(TemplateView):
return self.render_to_response(context)
class OrgaoCrud(Crud):
model = Orgao
help_path = 'orgao'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class TipoProposicaoCrud(Crud):
model = TipoProposicao
help_path = 'tipo_proposicao'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
class StatusTramitacaoCrud(Crud):
model = StatusTramitacao
help_path = 'status_tramitacao'
class BaseMixin(CrudBaseMixin):
def has_permission(self):
return permissao_tb_aux(self)
OrgaoCrud = CrudAux.build(Orgao, 'orgao')
TipoProposicaoCrud = CrudAux.build(TipoProposicao, 'tipo_proposicao')
StatusTramitacaoCrud = CrudAux.build(StatusTramitacao, 'status_tramitacao')
UnidadeTramitacaoCrud = CrudAux.build(UnidadeTramitacao, 'unidade_tramitacao')
def criar_materia_proposicao(proposicao):
@ -290,22 +221,6 @@ def criar_doc_proposicao(proposicao):
)
class UnidadeTramitacaoCrud(Crud):
model = UnidadeTramitacao
help_path = 'unidade_tramitacao'
class CreateView(CrudCreateView):
permission_required = permissoes_materia()
form_class = UnidadeTramitacaoForm
class UpdateView(CrudUpdateView):
permission_required = permissoes_materia()
form_class = UnidadeTramitacaoForm
class DeleteView(CrudDeleteView):
permission_required = permissoes_materia()
class ProposicaoDevolvida(PermissionRequiredMixin, ListView):
template_name = 'materia/prop_devolvidas_list.html'
model = Proposicao
@ -451,13 +366,12 @@ class ProposicaoCrud(Crud):
model = Proposicao
help_path = ''
class BaseMixin(CrudBaseMixin):
class BaseMixin(Crud.BaseMixin):
list_field_names = ['data_envio', 'descricao',
'tipo', 'data_recebimento']
class CreateView(CrudCreateView):
class CreateView(Crud.CreateView):
form_class = ProposicaoForm
permission_required = {'materia.add_proposicao'}
@property
def layout_key(self):
@ -483,9 +397,8 @@ class ProposicaoCrud(Crud):
else:
return {'autor': autor_id}
class UpdateView(CrudUpdateView):
class UpdateView(Crud.UpdateView):
form_class = ProposicaoForm
permission_required = permissoes_autor()
def get_initial(self):
initial = self.initial.copy()
@ -519,8 +432,7 @@ class ProposicaoCrud(Crud):
messages.add_message(self.request, messages.ERROR, msg)
return False
class DetailView(CrudDetailView):
permission_required = permissoes_autor()
class DetailView(Crud.DetailView):
def has_permission(self):
perms = self.get_permission_required()
@ -536,9 +448,8 @@ class ProposicaoCrud(Crud):
context['subnav_template_name'] = ''
return context
class ListView(CrudListView):
class ListView(Crud.ListView):
ordering = ['-data_envio', 'descricao']
permission_required = permissoes_autor()
def get_rows(self, object_list):
@ -566,8 +477,7 @@ class ProposicaoCrud(Crud):
return lista
class DeleteView(CrudDeleteView):
permission_required = {'materia.delete_proposicao'}
class DeleteView(Crud.DeleteView):
def has_permission(self):
perms = self.get_permission_required()
@ -630,10 +540,9 @@ class RelatoriaCrud(MasterDetailCrud):
model = Relatoria
parent_field = 'materia'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_materia()
form_class = RelatoriaForm
def get_initial(self):
materia = MateriaLegislativa.objects.get(id=self.kwargs['pk'])
@ -652,27 +561,20 @@ class RelatoriaCrud(MasterDetailCrud):
return {'comissao': localizacao}
class UpdateView(MasterDetailCrud.UpdateView):
permission_required = permissoes_materia()
form_class = RelatoriaForm
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class TramitacaoCrud(MasterDetailCrud):
model = Tramitacao
parent_field = 'materia'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['data_tramitacao', 'unidade_tramitacao_local',
'unidade_tramitacao_destino', 'status']
ordered_list = False
ordering = '-data_tramitacao',
class CreateView(MasterDetailCrud.CreateView):
form_class = TramitacaoForm
permission_required = permissoes_materia()
def get_initial(self):
local = MateriaLegislativa.objects.get(
@ -688,8 +590,6 @@ class TramitacaoCrud(MasterDetailCrud):
return super(CreateView, self).post(request, *args, **kwargs)
class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoUpdateForm
permission_required = permissoes_materia()
def post(self, request, *args, **kwargs):
materia = MateriaLegislativa.objects.get(
@ -709,7 +609,6 @@ class TramitacaoCrud(MasterDetailCrud):
return qs.filter(**kwargs).order_by('-data_tramitacao', '-id')
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
def delete(self, request, *args, **kwargs):
tramitacao = Tramitacao.objects.get(id=self.kwargs['pk'])
@ -762,78 +661,56 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
model = DocumentoAcessorio
parent_field = 'materia'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['nome', 'tipo', 'data', 'autor', 'arquivo']
class CreateView(MasterDetailCrud.CreateView):
form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
def __init__(self, *args, **kwargs):
def __init__(self, **kwargs):
montar_helper_documento_acessorio(self)
super(CreateView, self).__init__(*args, **kwargs)
super(MasterDetailCrud.CreateView, self).__init__(**kwargs)
def get_context_data(self, **kwargs):
context = super(CreateView, self).get_context_data(**kwargs)
context = super(
MasterDetailCrud.CreateView, self).get_context_data(**kwargs)
context['helper'] = self.helper
return context
class UpdateView(MasterDetailCrud.UpdateView):
form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
def __init__(self, *args, **kwargs):
def __init__(self, **kwargs):
montar_helper_documento_acessorio(self)
super(UpdateView, self).__init__(*args, **kwargs)
super(MasterDetailCrud.UpdateView, self).__init__(**kwargs)
def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs)
context['helper'] = self.helper
return context
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class AutoriaCrud(MasterDetailCrud):
model = Autoria
parent_field = 'materia'
help_path = ''
class CreateView(MasterDetailCrud.CreateView):
form_class = AutoriaForm
permission_required = permissoes_materia()
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AutoriaForm
permission_required = permissoes_materia()
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
public = [RP_LIST, RP_DETAIL]
class DespachoInicialCrud(MasterDetailCrud):
model = DespachoInicial
parent_field = 'materia'
help_path = ''
class CreateView(MasterDetailCrud.CreateView):
form_class = DespachoInicialForm
permission_required = permissoes_materia()
class UpdateView(MasterDetailCrud.UpdateView):
form_class = DespachoInicialForm
permission_required = permissoes_materia()
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
public = [RP_LIST, RP_DETAIL]
class LegislacaoCitadaCrud(MasterDetailCrud):
model = LegislacaoCitada
parent_field = 'materia'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['norma', 'disposicoes']
@ -843,13 +720,7 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
return reverse('%s:%s' % (namespace, self.url_name(suffix)),
args=args)
class CreateView(MasterDetailCrud.CreateView):
form_class = LegislacaoCitadaForm
permission_required = permissoes_materia()
class UpdateView(MasterDetailCrud.UpdateView):
form_class = LegislacaoCitadaForm
permission_required = permissoes_materia()
def get_initial(self):
self.initial['tipo'] = self.object.norma.tipo.id
@ -857,9 +728,6 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
self.initial['ano'] = self.object.norma.ano
return self.initial
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class DetailView(MasterDetailCrud.DetailView):
@property
@ -871,69 +739,35 @@ class NumeracaoCrud(MasterDetailCrud):
model = Numeracao
parent_field = 'materia'
help_path = ''
class CreateView(MasterDetailCrud.CreateView):
form_class = NumeracaoForm
permission_required = permissoes_materia()
class UpdateView(MasterDetailCrud.UpdateView):
form_class = NumeracaoForm
permission_required = permissoes_materia()
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
public = [RP_LIST, RP_DETAIL]
class AnexadaCrud(MasterDetailCrud):
model = Anexada
parent_field = 'materia_principal'
help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['materia_anexada', 'data_anexacao']
class CreateView(MasterDetailCrud.CreateView):
form_class = AnexadaForm
permission_required = permissoes_materia()
class UpdateView(MasterDetailCrud.UpdateView):
form_class = AnexadaForm
permission_required = permissoes_materia()
def get_initial(self):
self.initial['tipo'] = self.object.materia_anexada.tipo.id
self.initial['numero'] = self.object.materia_anexada.numero
self.initial['ano'] = self.object.materia_anexada.ano
return self.initial
class DetailView(MasterDetailCrud.DetailView):
@property
def layout_key(self):
return 'AnexadaDetail'
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class MateriaLegislativaCrud(Crud):
model = MateriaLegislativa
help_path = 'materia_legislativa'
public = [RP_LIST, RP_DETAIL]
class BaseMixin(CrudBaseMixin):
class BaseMixin(Crud.BaseMixin):
list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao']
class CreateView(CrudCreateView):
permission_required = permissoes_materia()
class UpdateView(CrudUpdateView):
permission_required = permissoes_materia()
class DeleteView(CrudDeleteView):
permission_required = permissoes_materia()
# FIXME - qual a finalidade dessa classe??
class DocumentoAcessorioView(PermissionRequiredMixin, CreateView):
template_name = "materia/documento_acessorio.html"
form_class = DocumentoAcessorioForm

9
sapl/norma/views.py

@ -4,12 +4,9 @@ from django.shortcuts import redirect
from django.views.generic import FormView, ListView
from sapl.compilacao.views import IntegracaoTaView
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudUpdateView, make_pagination,
CrudAux, RP_LIST, RP_DETAIL)
from sapl.utils import permissoes_norma
from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, make_pagination
from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm
from .forms import NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica,
TipoNormaJuridica)
@ -31,7 +28,6 @@ class NormaCrud(Crud):
public = [RP_LIST, RP_DETAIL]
class UpdateView(Crud.UpdateView):
form_class = NormaJuridicaForm
@property
def layout_key(self):
@ -46,7 +42,6 @@ class NormaCrud(Crud):
return self.initial.copy()
class CreateView(Crud.CreateView):
form_class = NormaJuridicaForm
@property
def layout_key(self):

22
sapl/parlamentares/views.py

@ -1,34 +1,22 @@
from datetime import date
from django.contrib import messages
from django.contrib.auth.decorators import permission_required
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, reverse_lazy
from django.shortcuts import redirect
from django.utils.datastructures import MultiValueDictKeyError
from django.utils.translation import ugettext_lazy as _
from django.views.generic import FormView, ListView
from django.views.generic import FormView
from sapl.comissoes.models import Participacao
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, MasterDetailCrud, CrudAux,
RP_CHANGE, RP_DETAIL, RP_LIST,
CrudBaseForListAndDetailExternalAppView)
from sapl.crud.base import (RP_CHANGE, RP_DETAIL, RP_LIST, Crud, CrudAux,
CrudBaseForListAndDetailExternalAppView,
MasterDetailCrud)
from sapl.materia.models import Proposicao, Relatoria
from sapl.parlamentares.apps import AppConfig
from sapl.utils import permissao_tb_aux, permissoes_parlamentares
from .forms import (ComposicaoColigacaoForm, FiliacaoForm,
LegislaturaForm, ParlamentarCreateForm, ParlamentarForm)
from .forms import LegislaturaForm, ParlamentarCreateForm, ParlamentarForm
from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa,
Dependente, Filiacao, Frente, Legislatura, Mandato,
NivelInstrucao, Parlamentar, Partido, SessaoLegislativa,
SituacaoMilitar, TipoAfastamento, TipoDependente)
CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa')
PartidoCrud = CrudAux.build(Partido, 'partidos')
SessaoLegislativaCrud = CrudAux.build(SessaoLegislativa, 'sessao_legislativa')

9
sapl/protocoloadm/views.py

@ -1,5 +1,5 @@
from datetime import date, datetime
import json
from datetime import date, datetime
from braces.views import FormValidMessageMixin
from django.contrib import messages
@ -16,14 +16,10 @@ from django_filters.views import FilterView
from sapl.base.apps import AppConfig as AppsAppConfig
from sapl.base.models import AppConfig
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView,
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, MasterDetailCrud, make_pagination,
CrudAux)
from sapl.crud.base import Crud, CrudAux, MasterDetailCrud, make_pagination
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,
@ -36,7 +32,6 @@ from .models import (Autor, DocumentoAcessorioAdministrativo,
TipoDocumentoAdministrativo, TipoInstituicao,
TramitacaoAdministrativo)
TipoDocumentoAdministrativoCrud = CrudAux.build(
TipoDocumentoAdministrativo, '')
TipoInstituicaoCrud = CrudAux.build(TipoInstituicao, '')

35
sapl/sessao/views.py

@ -19,25 +19,23 @@ from django.views.generic.edit import FormMixin
from django_filters.views import FilterView
from rest_framework import generics
from sapl.crud.base import (Crud, MasterDetailCrud, make_pagination,
CrudAux, RP_CHANGE, RP_DETAIL, RP_LIST,)
from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
MasterDetailCrud, make_pagination)
from sapl.materia.forms import pega_ultima_tramitacao
from sapl.materia.models import (Autoria, DocumentoAcessorio,
TipoMateriaLegislativa, Tramitacao)
from sapl.materia.views import MateriaLegislativaPesquisaView
from sapl.norma.models import NormaJuridica
from sapl.parlamentares.models import (Parlamentar, SessaoLegislativa,
Legislatura)
from sapl.parlamentares.models import (Legislatura, Parlamentar,
SessaoLegislativa)
from sapl.sessao.apps import AppConfig
from sapl.sessao.serializers import SessaoPlenariaSerializer
from sapl.utils import permissao_tb_aux, permissoes_painel, permissoes_sessao
from .forms import (AdicionarVariasMateriasFilterSet, BancadaForm,
ExpedienteForm, ExpedienteMateriaForm, ListMateriaForm,
MesaForm, OradorExpedienteForm, OradorForm, OrdemDiaForm,
PautaSessaoFilterSet, PresencaForm,
SessaoPlenariaFilterSet, VotacaoEditForm, VotacaoForm,
VotacaoNominalForm)
from sapl.utils import permissoes_painel, permissoes_sessao
from .forms import (AdicionarVariasMateriasFilterSet, ExpedienteForm,
ListMateriaForm, MesaForm, PautaSessaoFilterSet,
PresencaForm, SessaoPlenariaFilterSet, VotacaoEditForm,
VotacaoForm, VotacaoNominalForm)
from .models import (Bancada, Bloco, CargoBancada, CargoMesa,
ExpedienteMateria, ExpedienteSessao, IntegranteMesa,
MateriaLegislativa, Orador, OradorExpediente, OrdemDia,
@ -45,7 +43,6 @@ from .models import (Bancada, Bloco, CargoBancada, CargoMesa,
SessaoPlenariaPresenca, TipoExpediente,
TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar)
OrdemDiaCrud = Crud.build(OrdemDia, '')
RegistroVotacaoCrud = Crud.build(RegistroVotacao, '')
@ -131,14 +128,12 @@ class MateriaOrdemDiaCrud(MasterDetailCrud):
'resultado']
class CreateView(MasterDetailCrud.CreateView):
form_class = OrdemDiaForm
def get_success_url(self):
return reverse('sapl.sessao:ordemdia_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = OrdemDiaForm
def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id
@ -322,14 +317,12 @@ class ExpedienteMateriaCrud(MasterDetailCrud):
return [self._as_row(obj) for obj in object_list]
class CreateView(MasterDetailCrud.CreateView):
form_class = ExpedienteMateriaForm
def get_success_url(self):
return reverse('sapl.sessao:expedientemateria_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = ExpedienteMateriaForm
def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id
@ -358,29 +351,21 @@ class OradorExpedienteCrud(OradorCrud):
model = OradorExpediente
class CreateView(MasterDetailCrud.CreateView):
form_class = OradorExpedienteForm
def get_success_url(self):
return reverse('sapl.sessao:oradorexpediente_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = OradorExpedienteForm
class OradorCrud(OradorCrud):
model = Orador
class CreateView(MasterDetailCrud.CreateView):
form_class = OradorForm
def get_success_url(self):
return reverse('sapl.sessao:orador_list',
kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = OradorForm
def recuperar_numero_sessao(request):
try:

40
scripts/inicializa_grupos_autorizacoes.py

@ -1,26 +1,26 @@
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sapl.settings")
django.setup()
if __name__ == '__main__':
if True:
from django.apps import apps
from django.contrib.auth import get_user_model
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
def cria_ou_reseta_grupo(nome):
class InicializaGruposAutorizacoes():
def cria_ou_reseta_grupo(self, nome):
grupo = Group.objects.get_or_create(name=nome)[0]
for p in list(grupo.permissions.all()):
grupo.permissions.remove(p)
return grupo
def cria_usuario(nome, grupo):
def cria_usuario(self, nome, grupo):
nome_usuario = nome
usuario = get_user_model().objects.get_or_create(
username=nome_usuario)[0]
@ -28,7 +28,7 @@ if __name__ == '__main__':
usuario.save()
grupo.user_set.add(usuario)
def cria_grupos_permissoes():
def cria_grupos_permissoes(self):
nomes_apps = ['base', 'parlamentares', 'comissoes',
'materia', 'norma', 'sessao', 'painel']
@ -44,12 +44,12 @@ if __name__ == '__main__':
permissoes['documento_administrativo'] = list(
Permission.objects.filter(content_type__in=cts))
nome_grupo = 'Operador Administrativo'
grupo = cria_ou_reseta_grupo(nome_grupo)
grupo = self.cria_ou_reseta_grupo(nome_grupo)
for p in permissoes['documento_administrativo']:
grupo.permissions.add(p)
nome_usuario = 'operador_administrativo'
cria_usuario(nome_usuario, grupo)
self.cria_usuario(nome_usuario, grupo)
# prolocolo administrativo
cts = cts.exclude(model__icontains='tramitacao').exclude(
@ -57,12 +57,12 @@ if __name__ == '__main__':
permissoes['protocoloadm'] = list(
Permission.objects.filter(content_type__in=cts))
nome_grupo = 'Operador de Protocolo Administrativo'
grupo = cria_ou_reseta_grupo(nome_grupo)
grupo = self.cria_ou_reseta_grupo(nome_grupo)
for p in permissoes['protocoloadm']:
grupo.permissions.add(p)
nome_usuario = 'operador_protocoloadm'
cria_usuario(nome_usuario, grupo)
self.cria_usuario(nome_usuario, grupo)
# permissoes do base
cts = ContentType.objects.filter(app_label='base')
@ -77,7 +77,7 @@ if __name__ == '__main__':
# Cria Grupo
nome_grupo = 'Operador de %s' % apps.get_app_config(
nome_app).verbose_name
grupo = cria_ou_reseta_grupo(nome_grupo)
grupo = self.cria_ou_reseta_grupo(nome_grupo)
# Elimina o acesso a proposicoes pelo Operador de Matérias
if nome_app == 'materia':
@ -99,13 +99,13 @@ if __name__ == '__main__':
grupo.user_set.add(usuario)
# Operador Geral
grupo_geral = cria_ou_reseta_grupo('Operador Geral')
grupo_geral = self.cria_ou_reseta_grupo('Operador Geral')
for lista in permissoes.values():
for p in lista:
grupo_geral.permissions.add(p)
nome_usuario = 'operador_geral'
cria_usuario(nome_usuario, grupo_geral)
self.cria_usuario(nome_usuario, grupo_geral)
# Autor
perms_autor = []
@ -116,11 +116,17 @@ if __name__ == '__main__':
Permission.objects.get(name='Can delete Proposição'))
# Configura Permissoes Autor
grupo = cria_ou_reseta_grupo('Autor')
grupo = self.cria_ou_reseta_grupo('Autor')
for p in perms_autor:
grupo.permissions.add(p)
nome_usuario = 'operador_autor'
cria_usuario(nome_usuario, grupo)
self.cria_usuario(nome_usuario, grupo)
def __call__(self):
self.cria_grupos_permissoes()
cria_grupos_permissoes()
cria_grupos_permissoes = InicializaGruposAutorizacoes()
if __name__ == '__main__':
cria_grupos_permissoes.cria_grupos_permissoes()

3
scripts/test_inicializa_grupos_autorizacoes.py

@ -1,10 +1,11 @@
import pytest
from django.apps import apps
from django.contrib.auth.models import Group, Permission
from django.contrib.contenttypes.models import ContentType
import pytest
from inicializa_grupos_autorizacoes import cria_grupos_permissoes
pytestmark = pytest.mark.django_db
apps_com_permissao_padrao = [

Loading…
Cancel
Save