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. 12
      sapl/crud/base.py
  5. 1
      sapl/legacy/management/commands/migracao_25_31.py
  6. 6
      sapl/lexml/views.py
  7. 13
      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.core import exceptions
from django.db import models, router from django.db import models, router
from django.db.utils import DEFAULT_DB_ALIAS 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 string_concat
from django.utils.translation import ugettext_lazy as _
from sapl.utils import UF, YES_NO_CHOICES from sapl.utils import UF, YES_NO_CHOICES
TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')), TIPO_DOCUMENTO_ADMINISTRATIVO = (('O', _('Ostensivo')),
('R', _('Restritivo'))) ('R', _('Restritivo')))
@ -201,7 +202,8 @@ def create_proxy_permissions(
for perm in perms: for perm in perms:
print("Adding permission '%s'" % perm) print("Adding permission '%s'" % perm)
"""
models.signals.post_migrate.connect( models.signals.post_migrate.connect(
receiver=create_proxy_permissions, receiver=create_proxy_permissions,
dispatch_uid="django.contrib.auth.management.create_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 import template
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
import yaml
register = template.Library() register = template.Library()

2
sapl/crispy_layout_mixin.py

@ -1,12 +1,12 @@
from math import ceil from math import ceil
import rtyaml
from crispy_forms.bootstrap import FormActions from crispy_forms.bootstrap import FormActions
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit from crispy_forms.layout import HTML, Div, Fieldset, Layout, Submit
from django import template from django import template
from django.utils import formats from django.utils import formats
from django.utils.translation import ugettext as _ from django.utils.translation import ugettext as _
import rtyaml
def heads_and_tails(list_of_lists): def heads_and_tails(list_of_lists):

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

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

@ -1,4 +1,5 @@
from django.core.management.base import BaseCommand from django.core.management.base import BaseCommand
from sapl.legacy import migration 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 from .models import LexmlProvedor, LexmlPublicador
LexmlProvedorCrud = Crud.build(LexmlProvedor, 'lexml_provedor') LexmlProvedorCrud = CrudAux.build(LexmlProvedor, 'lexml_provedor')
LexmlPublicadorCrud = Crud.build(LexmlPublicador, 'lexml_publicador') LexmlPublicadorCrud = CrudAux.build(LexmlPublicador, 'lexml_publicador')

13
sapl/materia/forms.py

@ -1,6 +1,5 @@
from datetime import datetime from datetime import datetime
import django_filters
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout from crispy_forms.layout import HTML, Button, Column, Fieldset, Layout
from django import forms from django import forms
@ -12,6 +11,7 @@ from django.db import models, transaction
from django.db.models import Max from django.db.models import Max
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
import django_filters
from sapl.comissoes.models import Comissao from sapl.comissoes.models import Comissao
from sapl.crispy_layout_mixin import form_actions, to_row 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, Numeracao, Proposicao, Relatoria, TipoMateriaLegislativa,
Tramitacao, UnidadeTramitacao) Tramitacao, UnidadeTramitacao)
ANO_CHOICES = [('', '---------')] + RANGE_ANOS ANO_CHOICES = [('', '---------')] + RANGE_ANOS
@ -192,9 +193,9 @@ class RelatoriaForm(ModelForm):
widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})} widgets = {'comissao': forms.Select(attrs={'disabled': 'disabled'})}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
super(RelatoriaForm, self).__init__(*args, **kwargs) super(RelatoriaForm, self).__init__(*args, **kwargs)
self.fields['parlamentar'].queryset = Parlamentar.objects.filter( self.fields['parlamentar'].queryset = Parlamentar.objects.filter(
ativo=True).order_by('nome_completo') ativo=True).order_by('nome_completo')
def clean(self): def clean(self):
cleaned_data = self.cleaned_data cleaned_data = self.cleaned_data
@ -427,6 +428,10 @@ class AnexadaForm(ModelForm):
ano = forms.CharField(label='Ano', required=True) ano = forms.CharField(label='Ano', required=True)
def __init__(self, *args, **kwargs):
return super(AnexadaForm, self).__init__(*args, **kwargs)
def clean(self): def clean(self):
if self.errors: if self.errors:
return self.errors return self.errors

1
sapl/materia/models.py

@ -589,6 +589,7 @@ class Tramitacao(models.Model):
class Meta: class Meta:
verbose_name = _('Tramitação') verbose_name = _('Tramitação')
verbose_name_plural = _('Tramitações') verbose_name_plural = _('Tramitações')
ordering = 'data_tramitacao',
def __str__(self): def __str__(self):
return _('%(materia)s | %(status)s | %(data)s') % { 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 random import choice
from string import ascii_letters, digits from string import ascii_letters, digits
from braces.views import PermissionRequiredMixin
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button from crispy_forms.layout import HTML, Button
from django.conf import settings from django.conf import settings
from django.contrib import messages from django.contrib import messages
from django.contrib.auth import get_user_model 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.contrib.auth.tokens import default_token_generator
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.mail import send_mail 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.base.models import CasaLegislativa
from sapl.compilacao.views import IntegracaoTaView from sapl.compilacao.views import IntegracaoTaView
from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row from sapl.crispy_layout_mixin import SaplFormLayout, form_actions, to_row
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux, CrudDetailView,
CrudDeleteView, CrudDetailView, CrudListView, MasterDetailCrud, make_pagination)
CrudUpdateView, MasterDetailCrud, make_pagination) from sapl.materia.forms import AnexadaForm
from sapl.norma.models import LegislacaoCitada from sapl.norma.models import LegislacaoCitada
from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label, from sapl.utils import (TURNO_TRAMITACAO_CHOICES, YES_NO_CHOICES, autor_label,
autor_modal, gerar_hash_arquivo, get_base_url, autor_modal, gerar_hash_arquivo, get_base_url,
permissao_tb_aux, permissoes_autor, permissoes_materia, permissoes_autor, permissoes_materia,
permissoes_protocoloadm) permissoes_protocoloadm)
from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm, from .forms import (AcessorioEmLoteFilterSet, AcompanhamentoMateriaForm,
AnexadaForm, AutorForm, AutoriaForm, AutorForm, ConfirmarProposicaoForm, DocumentoAcessorioForm,
ConfirmarProposicaoForm, DespachoInicialForm, MateriaLegislativaFilterSet,
DocumentoAcessorioForm, LegislacaoCitadaForm,
MateriaLegislativaFilterSet, NumeracaoForm,
PrimeiraTramitacaoEmLoteFilterSet, ProposicaoForm, PrimeiraTramitacaoEmLoteFilterSet, ProposicaoForm,
ReceberProposicaoForm, RelatoriaForm, ReceberProposicaoForm, TramitacaoEmLoteFilterSet,
TramitacaoEmLoteFilterSet, TramitacaoForm,
TramitacaoUpdateForm, UnidadeTramitacaoForm,
filtra_tramitacao_destino, filtra_tramitacao_destino,
filtra_tramitacao_destino_and_status, filtra_tramitacao_destino_and_status,
filtra_tramitacao_status) filtra_tramitacao_status)
@ -54,8 +50,26 @@ from .models import (AcompanhamentoMateria, Anexada, Autor, Autoria,
TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao, TipoFimRelatoria, TipoMateriaLegislativa, TipoProposicao,
Tramitacao, UnidadeTramitacao) Tramitacao, UnidadeTramitacao)
AnexadaCrud = Crud.build(Anexada, '') 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): def recuperar_materia(request):
tipo = TipoMateriaLegislativa.objects.get(pk=request.GET['tipo']) tipo = TipoMateriaLegislativa.objects.get(pk=request.GET['tipo'])
@ -69,61 +83,6 @@ def recuperar_materia(request):
return response 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): def montar_helper_autor(self):
autor_row = montar_row_autor('nome') autor_row = montar_row_autor('nome')
self.helper = FormHelper() self.helper = FormHelper()
@ -146,18 +105,14 @@ def montar_helper_autor(self):
' class="btn btn-inverse">Cancelar</a>')])) ' class="btn btn-inverse">Cancelar</a>')]))
class AutorCrud(Crud): class AutorCrud(CrudAux):
model = Autor model = Autor
help_path = 'autor' help_path = 'autor'
class BaseMixin(CrudBaseMixin): class BaseMixin(CrudAux.BaseMixin):
list_field_names = ['tipo', 'nome'] list_field_names = ['tipo', 'nome']
def has_permission(self): class UpdateView(CrudAux.UpdateView):
return permissao_tb_aux(self)
class UpdateView(CrudUpdateView):
form_class = AutorForm
layout_key = 'AutorCreate' layout_key = 'AutorCreate'
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
@ -169,7 +124,7 @@ class AutorCrud(Crud):
context['helper'] = self.helper context['helper'] = self.helper
return context return context
class CreateView(CrudCreateView): class CreateView(CrudAux.CreateView):
form_class = AutorForm form_class = AutorForm
layout_key = 'AutorCreate' layout_key = 'AutorCreate'
@ -223,34 +178,10 @@ class ConfirmarEmailView(TemplateView):
return self.render_to_response(context) return self.render_to_response(context)
class OrgaoCrud(Crud): OrgaoCrud = CrudAux.build(Orgao, 'orgao')
model = Orgao TipoProposicaoCrud = CrudAux.build(TipoProposicao, 'tipo_proposicao')
help_path = 'orgao' StatusTramitacaoCrud = CrudAux.build(StatusTramitacao, 'status_tramitacao')
UnidadeTramitacaoCrud = CrudAux.build(UnidadeTramitacao, 'unidade_tramitacao')
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)
def criar_materia_proposicao(proposicao): 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): class ProposicaoDevolvida(PermissionRequiredMixin, ListView):
template_name = 'materia/prop_devolvidas_list.html' template_name = 'materia/prop_devolvidas_list.html'
model = Proposicao model = Proposicao
@ -451,13 +366,12 @@ class ProposicaoCrud(Crud):
model = Proposicao model = Proposicao
help_path = '' help_path = ''
class BaseMixin(CrudBaseMixin): class BaseMixin(Crud.BaseMixin):
list_field_names = ['data_envio', 'descricao', list_field_names = ['data_envio', 'descricao',
'tipo', 'data_recebimento'] 'tipo', 'data_recebimento']
class CreateView(CrudCreateView): class CreateView(Crud.CreateView):
form_class = ProposicaoForm form_class = ProposicaoForm
permission_required = {'materia.add_proposicao'}
@property @property
def layout_key(self): def layout_key(self):
@ -483,9 +397,8 @@ class ProposicaoCrud(Crud):
else: else:
return {'autor': autor_id} return {'autor': autor_id}
class UpdateView(CrudUpdateView): class UpdateView(Crud.UpdateView):
form_class = ProposicaoForm form_class = ProposicaoForm
permission_required = permissoes_autor()
def get_initial(self): def get_initial(self):
initial = self.initial.copy() initial = self.initial.copy()
@ -519,8 +432,7 @@ class ProposicaoCrud(Crud):
messages.add_message(self.request, messages.ERROR, msg) messages.add_message(self.request, messages.ERROR, msg)
return False return False
class DetailView(CrudDetailView): class DetailView(Crud.DetailView):
permission_required = permissoes_autor()
def has_permission(self): def has_permission(self):
perms = self.get_permission_required() perms = self.get_permission_required()
@ -536,9 +448,8 @@ class ProposicaoCrud(Crud):
context['subnav_template_name'] = '' context['subnav_template_name'] = ''
return context return context
class ListView(CrudListView): class ListView(Crud.ListView):
ordering = ['-data_envio', 'descricao'] ordering = ['-data_envio', 'descricao']
permission_required = permissoes_autor()
def get_rows(self, object_list): def get_rows(self, object_list):
@ -566,8 +477,7 @@ class ProposicaoCrud(Crud):
return lista return lista
class DeleteView(CrudDeleteView): class DeleteView(Crud.DeleteView):
permission_required = {'materia.delete_proposicao'}
def has_permission(self): def has_permission(self):
perms = self.get_permission_required() perms = self.get_permission_required()
@ -630,10 +540,9 @@ class RelatoriaCrud(MasterDetailCrud):
model = Relatoria model = Relatoria
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
permission_required = permissoes_materia()
form_class = RelatoriaForm
def get_initial(self): def get_initial(self):
materia = MateriaLegislativa.objects.get(id=self.kwargs['pk']) materia = MateriaLegislativa.objects.get(id=self.kwargs['pk'])
@ -652,27 +561,20 @@ class RelatoriaCrud(MasterDetailCrud):
return {'comissao': localizacao} 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): class TramitacaoCrud(MasterDetailCrud):
model = Tramitacao model = Tramitacao
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['data_tramitacao', 'unidade_tramitacao_local', list_field_names = ['data_tramitacao', 'unidade_tramitacao_local',
'unidade_tramitacao_destino', 'status'] 'unidade_tramitacao_destino', 'status']
ordered_list = False
ordering = '-data_tramitacao', ordering = '-data_tramitacao',
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = TramitacaoForm
permission_required = permissoes_materia()
def get_initial(self): def get_initial(self):
local = MateriaLegislativa.objects.get( local = MateriaLegislativa.objects.get(
@ -688,8 +590,6 @@ class TramitacaoCrud(MasterDetailCrud):
return super(CreateView, self).post(request, *args, **kwargs) return super(CreateView, self).post(request, *args, **kwargs)
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoUpdateForm
permission_required = permissoes_materia()
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
materia = MateriaLegislativa.objects.get( materia = MateriaLegislativa.objects.get(
@ -709,7 +609,6 @@ class TramitacaoCrud(MasterDetailCrud):
return qs.filter(**kwargs).order_by('-data_tramitacao', '-id') return qs.filter(**kwargs).order_by('-data_tramitacao', '-id')
class DeleteView(MasterDetailCrud.DeleteView): class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
def delete(self, request, *args, **kwargs): def delete(self, request, *args, **kwargs):
tramitacao = Tramitacao.objects.get(id=self.kwargs['pk']) tramitacao = Tramitacao.objects.get(id=self.kwargs['pk'])
@ -762,78 +661,56 @@ class DocumentoAcessorioCrud(MasterDetailCrud):
model = DocumentoAcessorio model = DocumentoAcessorio
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['nome', 'tipo', 'data', 'autor', 'arquivo'] list_field_names = ['nome', 'tipo', 'data', 'autor', 'arquivo']
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = DocumentoAcessorioForm form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
def __init__(self, *args, **kwargs): def __init__(self, **kwargs):
montar_helper_documento_acessorio(self) montar_helper_documento_acessorio(self)
super(CreateView, self).__init__(*args, **kwargs) super(MasterDetailCrud.CreateView, self).__init__(**kwargs)
def get_context_data(self, **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 context['helper'] = self.helper
return context return context
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = DocumentoAcessorioForm form_class = DocumentoAcessorioForm
permission_required = permissoes_materia()
def __init__(self, *args, **kwargs): def __init__(self, **kwargs):
montar_helper_documento_acessorio(self) montar_helper_documento_acessorio(self)
super(UpdateView, self).__init__(*args, **kwargs) super(MasterDetailCrud.UpdateView, self).__init__(**kwargs)
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super(UpdateView, self).get_context_data(**kwargs) context = super(UpdateView, self).get_context_data(**kwargs)
context['helper'] = self.helper context['helper'] = self.helper
return context return context
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class AutoriaCrud(MasterDetailCrud): class AutoriaCrud(MasterDetailCrud):
model = Autoria model = Autoria
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
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()
class DespachoInicialCrud(MasterDetailCrud): class DespachoInicialCrud(MasterDetailCrud):
model = DespachoInicial model = DespachoInicial
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
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()
class LegislacaoCitadaCrud(MasterDetailCrud): class LegislacaoCitadaCrud(MasterDetailCrud):
model = LegislacaoCitada model = LegislacaoCitada
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['norma', 'disposicoes'] list_field_names = ['norma', 'disposicoes']
@ -843,13 +720,7 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
return reverse('%s:%s' % (namespace, self.url_name(suffix)), return reverse('%s:%s' % (namespace, self.url_name(suffix)),
args=args) args=args)
class CreateView(MasterDetailCrud.CreateView):
form_class = LegislacaoCitadaForm
permission_required = permissoes_materia()
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = LegislacaoCitadaForm
permission_required = permissoes_materia()
def get_initial(self): def get_initial(self):
self.initial['tipo'] = self.object.norma.tipo.id self.initial['tipo'] = self.object.norma.tipo.id
@ -857,9 +728,6 @@ class LegislacaoCitadaCrud(MasterDetailCrud):
self.initial['ano'] = self.object.norma.ano self.initial['ano'] = self.object.norma.ano
return self.initial return self.initial
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class DetailView(MasterDetailCrud.DetailView): class DetailView(MasterDetailCrud.DetailView):
@property @property
@ -871,69 +739,35 @@ class NumeracaoCrud(MasterDetailCrud):
model = Numeracao model = Numeracao
parent_field = 'materia' parent_field = 'materia'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
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()
class AnexadaCrud(MasterDetailCrud): class AnexadaCrud(MasterDetailCrud):
model = Anexada model = Anexada
parent_field = 'materia_principal' parent_field = 'materia_principal'
help_path = '' help_path = ''
public = [RP_LIST, RP_DETAIL]
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['materia_anexada', 'data_anexacao'] 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): class DetailView(MasterDetailCrud.DetailView):
@property @property
def layout_key(self): def layout_key(self):
return 'AnexadaDetail' return 'AnexadaDetail'
class DeleteView(MasterDetailCrud.DeleteView):
permission_required = permissoes_materia()
class MateriaLegislativaCrud(Crud): class MateriaLegislativaCrud(Crud):
model = MateriaLegislativa model = MateriaLegislativa
help_path = 'materia_legislativa' help_path = 'materia_legislativa'
public = [RP_LIST, RP_DETAIL]
class BaseMixin(CrudBaseMixin): class BaseMixin(Crud.BaseMixin):
list_field_names = ['tipo', 'numero', 'ano', 'data_apresentacao'] 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): class DocumentoAcessorioView(PermissionRequiredMixin, CreateView):
template_name = "materia/documento_acessorio.html" template_name = "materia/documento_acessorio.html"
form_class = DocumentoAcessorioForm 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 django.views.generic import FormView, ListView
from sapl.compilacao.views import IntegracaoTaView from sapl.compilacao.views import IntegracaoTaView
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.crud.base import RP_DETAIL, RP_LIST, Crud, CrudAux, make_pagination
CrudDeleteView, CrudUpdateView, make_pagination,
CrudAux, RP_LIST, RP_DETAIL)
from sapl.utils import permissoes_norma
from .forms import NormaJuridicaForm, NormaJuridicaPesquisaForm from .forms import NormaJuridicaPesquisaForm
from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica, from .models import (AssuntoNorma, LegislacaoCitada, NormaJuridica,
TipoNormaJuridica) TipoNormaJuridica)
@ -31,7 +28,6 @@ class NormaCrud(Crud):
public = [RP_LIST, RP_DETAIL] public = [RP_LIST, RP_DETAIL]
class UpdateView(Crud.UpdateView): class UpdateView(Crud.UpdateView):
form_class = NormaJuridicaForm
@property @property
def layout_key(self): def layout_key(self):
@ -46,7 +42,6 @@ class NormaCrud(Crud):
return self.initial.copy() return self.initial.copy()
class CreateView(Crud.CreateView): class CreateView(Crud.CreateView):
form_class = NormaJuridicaForm
@property @property
def layout_key(self): 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 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.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.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.comissoes.models import Participacao
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.crud.base import (RP_CHANGE, RP_DETAIL, RP_LIST, Crud, CrudAux,
CrudDeleteView, CrudDetailView, CrudListView, CrudBaseForListAndDetailExternalAppView,
CrudUpdateView, MasterDetailCrud, CrudAux, MasterDetailCrud)
RP_CHANGE, RP_DETAIL, RP_LIST,
CrudBaseForListAndDetailExternalAppView)
from sapl.materia.models import Proposicao, Relatoria from sapl.materia.models import Proposicao, Relatoria
from sapl.parlamentares.apps import AppConfig from sapl.parlamentares.apps import AppConfig
from sapl.utils import permissao_tb_aux, permissoes_parlamentares
from .forms import (ComposicaoColigacaoForm, FiliacaoForm, from .forms import LegislaturaForm, ParlamentarCreateForm, ParlamentarForm
LegislaturaForm, ParlamentarCreateForm, ParlamentarForm)
from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa,
Dependente, Filiacao, Frente, Legislatura, Mandato, Dependente, Filiacao, Frente, Legislatura, Mandato,
NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa,
SituacaoMilitar, TipoAfastamento, TipoDependente) SituacaoMilitar, TipoAfastamento, TipoDependente)
CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa') CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa')
PartidoCrud = CrudAux.build(Partido, 'partidos') PartidoCrud = CrudAux.build(Partido, 'partidos')
SessaoLegislativaCrud = CrudAux.build(SessaoLegislativa, 'sessao_legislativa') SessaoLegislativaCrud = CrudAux.build(SessaoLegislativa, 'sessao_legislativa')

9
sapl/protocoloadm/views.py

@ -1,5 +1,5 @@
from datetime import date, datetime
import json import json
from datetime import date, datetime
from braces.views import FormValidMessageMixin from braces.views import FormValidMessageMixin
from django.contrib import messages 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.apps import AppConfig as AppsAppConfig
from sapl.base.models import AppConfig from sapl.base.models import AppConfig
from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, from sapl.crud.base import Crud, CrudAux, MasterDetailCrud, make_pagination
CrudDeleteView, CrudDetailView, CrudListView,
CrudUpdateView, MasterDetailCrud, make_pagination,
CrudAux)
from sapl.materia.models import TipoMateriaLegislativa from sapl.materia.models import TipoMateriaLegislativa
from sapl.utils import (create_barcode, get_client_ip, permissoes_adm, from sapl.utils import (create_barcode, get_client_ip, permissoes_adm,
permissoes_protocoloadm) permissoes_protocoloadm)
import sapl.crud.base
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
DocumentoAdministrativoFilterSet, DocumentoAdministrativoFilterSet,
@ -36,7 +32,6 @@ from .models import (Autor, DocumentoAcessorioAdministrativo,
TipoDocumentoAdministrativo, TipoInstituicao, TipoDocumentoAdministrativo, TipoInstituicao,
TramitacaoAdministrativo) TramitacaoAdministrativo)
TipoDocumentoAdministrativoCrud = CrudAux.build( TipoDocumentoAdministrativoCrud = CrudAux.build(
TipoDocumentoAdministrativo, '') TipoDocumentoAdministrativo, '')
TipoInstituicaoCrud = CrudAux.build(TipoInstituicao, '') 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 django_filters.views import FilterView
from rest_framework import generics from rest_framework import generics
from sapl.crud.base import (Crud, MasterDetailCrud, make_pagination, from sapl.crud.base import (RP_DETAIL, RP_LIST, Crud, CrudAux,
CrudAux, RP_CHANGE, RP_DETAIL, RP_LIST,) MasterDetailCrud, make_pagination)
from sapl.materia.forms import pega_ultima_tramitacao from sapl.materia.forms import pega_ultima_tramitacao
from sapl.materia.models import (Autoria, DocumentoAcessorio, from sapl.materia.models import (Autoria, DocumentoAcessorio,
TipoMateriaLegislativa, Tramitacao) TipoMateriaLegislativa, Tramitacao)
from sapl.materia.views import MateriaLegislativaPesquisaView from sapl.materia.views import MateriaLegislativaPesquisaView
from sapl.norma.models import NormaJuridica from sapl.norma.models import NormaJuridica
from sapl.parlamentares.models import (Parlamentar, SessaoLegislativa, from sapl.parlamentares.models import (Legislatura, Parlamentar,
Legislatura) SessaoLegislativa)
from sapl.sessao.apps import AppConfig from sapl.sessao.apps import AppConfig
from sapl.sessao.serializers import SessaoPlenariaSerializer from sapl.sessao.serializers import SessaoPlenariaSerializer
from sapl.utils import permissao_tb_aux, permissoes_painel, permissoes_sessao from sapl.utils import permissoes_painel, permissoes_sessao
from .forms import (AdicionarVariasMateriasFilterSet, BancadaForm, from .forms import (AdicionarVariasMateriasFilterSet, ExpedienteForm,
ExpedienteForm, ExpedienteMateriaForm, ListMateriaForm, ListMateriaForm, MesaForm, PautaSessaoFilterSet,
MesaForm, OradorExpedienteForm, OradorForm, OrdemDiaForm, PresencaForm, SessaoPlenariaFilterSet, VotacaoEditForm,
PautaSessaoFilterSet, PresencaForm, VotacaoForm, VotacaoNominalForm)
SessaoPlenariaFilterSet, VotacaoEditForm, VotacaoForm,
VotacaoNominalForm)
from .models import (Bancada, Bloco, CargoBancada, CargoMesa, from .models import (Bancada, Bloco, CargoBancada, CargoMesa,
ExpedienteMateria, ExpedienteSessao, IntegranteMesa, ExpedienteMateria, ExpedienteSessao, IntegranteMesa,
MateriaLegislativa, Orador, OradorExpediente, OrdemDia, MateriaLegislativa, Orador, OradorExpediente, OrdemDia,
@ -45,7 +43,6 @@ from .models import (Bancada, Bloco, CargoBancada, CargoMesa,
SessaoPlenariaPresenca, TipoExpediente, SessaoPlenariaPresenca, TipoExpediente,
TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar) TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar)
OrdemDiaCrud = Crud.build(OrdemDia, '') OrdemDiaCrud = Crud.build(OrdemDia, '')
RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') RegistroVotacaoCrud = Crud.build(RegistroVotacao, '')
@ -131,14 +128,12 @@ class MateriaOrdemDiaCrud(MasterDetailCrud):
'resultado'] 'resultado']
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = OrdemDiaForm
def get_success_url(self): def get_success_url(self):
return reverse('sapl.sessao:ordemdia_list', return reverse('sapl.sessao:ordemdia_list',
kwargs={'pk': self.kwargs['pk']}) kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = OrdemDiaForm
def get_initial(self): def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id 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] return [self._as_row(obj) for obj in object_list]
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = ExpedienteMateriaForm
def get_success_url(self): def get_success_url(self):
return reverse('sapl.sessao:expedientemateria_list', return reverse('sapl.sessao:expedientemateria_list',
kwargs={'pk': self.kwargs['pk']}) kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = ExpedienteMateriaForm
def get_initial(self): def get_initial(self):
self.initial['tipo_materia'] = self.object.materia.tipo.id self.initial['tipo_materia'] = self.object.materia.tipo.id
@ -358,29 +351,21 @@ class OradorExpedienteCrud(OradorCrud):
model = OradorExpediente model = OradorExpediente
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = OradorExpedienteForm
def get_success_url(self): def get_success_url(self):
return reverse('sapl.sessao:oradorexpediente_list', return reverse('sapl.sessao:oradorexpediente_list',
kwargs={'pk': self.kwargs['pk']}) kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = OradorExpedienteForm
class OradorCrud(OradorCrud): class OradorCrud(OradorCrud):
model = Orador model = Orador
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = OradorForm
def get_success_url(self): def get_success_url(self):
return reverse('sapl.sessao:orador_list', return reverse('sapl.sessao:orador_list',
kwargs={'pk': self.kwargs['pk']}) kwargs={'pk': self.kwargs['pk']})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = OradorForm
def recuperar_numero_sessao(request): def recuperar_numero_sessao(request):
try: try:

40
scripts/inicializa_grupos_autorizacoes.py

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

Loading…
Cancel
Save