diff --git a/sapl/crispy_layout_mixin.py b/sapl/crispy_layout_mixin.py index 1d0c5c17e..7d64aa011 100644 --- a/sapl/crispy_layout_mixin.py +++ b/sapl/crispy_layout_mixin.py @@ -150,7 +150,7 @@ class CrispyLayoutFormMixin: in the first fieldset of the layout. ''' obj = self.crud if hasattr(self, 'crud') else self - if hasattr(obj, 'list_field_names'): + if hasattr(obj, 'list_field_names') and obj.list_field_names: return obj.list_field_names rows = self.get_layout()[0][1:] return [fieldname for row in rows for fieldname, __ in row] diff --git a/sapl/crud/base.py b/sapl/crud/base.py index a0cc93608..89e589667 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -668,7 +668,9 @@ class CrudDetailView(PermissionRequiredContainerCrudMixin, for i, name in enumerate(self.list_field_names_set)] def get_object(self, queryset=None): - return self.object + if hasattr(self, 'object'): + return self.object + return DetailView.get_object(self, queryset=queryset) def get(self, request, *args, **kwargs): self.object = self.model.objects.get(pk=kwargs.get('pk')) @@ -680,7 +682,10 @@ class CrudDetailView(PermissionRequiredContainerCrudMixin, def get_queryset(self): obj = self.crud if hasattr(self, 'crud') else self - queryset = getattr(self.object, obj.model_set).all() + if hasattr(obj, 'model_set') and obj.model_set: + queryset = getattr(self.object, obj.model_set).all() + else: + queryset = super().get_queryset() if not self.request.user.is_authenticated(): return queryset @@ -782,13 +787,6 @@ class CrudDeleteView(PermissionRequiredContainerCrudMixin, return self.list_url -class DeactivatedMixin(View): - - @classmethod - def get_url_regex(cls): - return r'^dummy$' - - class Crud: BaseMixin = CrudBaseMixin ListView = CrudListView @@ -842,28 +840,16 @@ class Crud: @classonlymethod def build(cls, _model, _help_path, _model_set=None, list_field_names=[]): - def create_class_with_list_field(_list_field_names): - class ModelCrud(cls): - model = _model - model_set = _model_set - help_path = _help_path - - class BaseMixin(cls.BaseMixin): - list_field_names = _list_field_names - return ModelCrud - - def create_class(): + def create_class(_list_field_names): class ModelCrud(cls): model = _model model_set = _model_set help_path = _help_path + list_field_names = _list_field_names return ModelCrud - ModelCrud = create_class() if not list_field_names\ - else create_class_with_list_field(list_field_names) - + ModelCrud = create_class(list_field_names) ModelCrud.__name__ = '%sCrud' % _model.__name__ - return ModelCrud diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 4bdc115dc..bbd57ae74 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -15,7 +15,7 @@ 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, DeactivatedMixin, + RP_CHANGE, RP_DETAIL, RP_LIST, CrudBaseForListAndDetailExternalAppView) from sapl.materia.models import Proposicao, Relatoria from sapl.parlamentares.apps import AppConfig diff --git a/sapl/sessao/models.py b/sapl/sessao/models.py index 78ff6a410..86ce4c2e2 100644 --- a/sapl/sessao/models.py +++ b/sapl/sessao/models.py @@ -41,6 +41,7 @@ class Bancada(models.Model): class Meta: verbose_name = _('Bancada') verbose_name_plural = _('Bancadas') + ordering = ('-legislatura__numero', ) def __str__(self): return self.nome diff --git a/sapl/sessao/urls.py b/sapl/sessao/urls.py index e23bb4113..efbfbaf9a 100644 --- a/sapl/sessao/urls.py +++ b/sapl/sessao/urls.py @@ -39,6 +39,7 @@ urlpatterns = [ ExpedienteMateriaCrud.get_urls() + MateriaOrdemDiaCrud.get_urls())), + url(r'^sessao/(?P\d+)/mesa$', MesaView.as_view(), name='mesa'), url(r'^recuperar-materia/', recuperar_materia), url(r'^recuperar-numero-sessao/', recuperar_numero_sessao), @@ -86,17 +87,16 @@ urlpatterns = [ PautaOrdemDetail.as_view(), name='pauta_ordem_detail'), # Subnav sessão - url(r'^(?P\d+)/expediente$', + url(r'^sessao/(?P\d+)/expediente$', ExpedienteView.as_view(), name='expediente'), - url(r'^(?P\d+)/presenca$', + url(r'^sessao/(?P\d+)/presenca$', PresencaView.as_view(), name='presenca'), - url(r'^(?P\d+)/painel$', + url(r'^sessao/(?P\d+)/painel$', PainelView.as_view(), name='painel'), - url(r'^(?P\d+)/presencaordemdia$', + url(r'^sessao/(?P\d+)/presencaordemdia$', PresencaOrdemDiaView.as_view(), name='presencaordemdia'), - url(r'^(?P\d+)/mesa$', MesaView.as_view(), name='mesa'), - url(r'^(?P\d+)/resumo$', + url(r'^sessao/(?P\d+)/resumo$', ResumoView.as_view(), name='resumo'), url(r'^sessao/pesquisar-sessao$', PesquisarSessaoPlenariaView.as_view(), name='pesquisar_sessao'), diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index b23af488b..28b8764cd 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -3,22 +3,24 @@ from re import sub from braces.views import PermissionRequiredMixin from django.contrib import messages +from django.contrib.auth.decorators import permission_required from django.core.exceptions import ObjectDoesNotExist, ValidationError from django.core.urlresolvers import reverse from django.forms.utils import ErrorList from django.http import JsonResponse from django.http.response import HttpResponseRedirect from django.utils.datastructures import MultiValueDictKeyError +from django.utils.decorators import method_decorator from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ from django.views.generic import ListView, TemplateView +from django.views.generic.detail import DetailView from django.views.generic.edit import FormMixin from django_filters.views import FilterView from rest_framework import generics -from sapl.crud.base import (Crud, CrudBaseMixin, CrudCreateView, - CrudDeleteView, CrudDetailView, CrudListView, - CrudUpdateView, MasterDetailCrud, make_pagination) +from sapl.crud.base import (Crud, MasterDetailCrud, make_pagination, + CrudAux, RP_CHANGE, RP_DETAIL, RP_LIST,) from sapl.materia.forms import pega_ultima_tramitacao from sapl.materia.models import (Autoria, DocumentoAcessorio, TipoMateriaLegislativa, Tramitacao) @@ -26,6 +28,7 @@ from sapl.materia.views import MateriaLegislativaPesquisaView from sapl.norma.models import NormaJuridica from sapl.parlamentares.models import (Parlamentar, SessaoLegislativa, Legislatura) +from sapl.sessao.apps import AppConfig from sapl.sessao.serializers import SessaoPlenariaSerializer from sapl.utils import permissao_tb_aux, permissoes_painel, permissoes_sessao @@ -42,9 +45,23 @@ from .models import (Bancada, Bloco, CargoBancada, CargoMesa, SessaoPlenariaPresenca, TipoExpediente, TipoResultadoVotacao, TipoSessaoPlenaria, VotoParlamentar) + OrdemDiaCrud = Crud.build(OrdemDia, '') RegistroVotacaoCrud = Crud.build(RegistroVotacao, '') +TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') +TipoExpedienteCrud = CrudAux.build(TipoExpediente, 'tipo_expediente') +CargoBancadaCrud = CrudAux.build(CargoBancada, '') +TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') +TipoSessaoCrud = CrudAux.build(TipoSessaoPlenaria, 'tipo_sessao_plenaria') + +BlocoCrud = CrudAux.build( + Bloco, '', list_field_names=['nome', 'data_criacao', 'partidos']) +BancadaCrud = CrudAux.build( + Bancada, '', list_field_names=['nome', 'legislatura']) +TipoResultadoVotacaoCrud = CrudAux.build( + TipoResultadoVotacao, 'tipo_resultado_votacao') + def reordernar_materias_expediente(request, pk): expedientes = ExpedienteMateria.objects.filter( @@ -72,77 +89,6 @@ def reordernar_materias_ordem(request, pk): reverse('sapl.sessao:ordemdia_list', kwargs={'pk': pk})) -class BlocoCrud(Crud): - model = Bloco - help_path = '' - - class BaseMixin(CrudBaseMixin): - list_field_names = ['nome', 'data_criacao', 'partidos'] - - def has_permission(self): - return permissao_tb_aux(self) - - -class BancadaCrud(Crud): - model = Bancada - help_path = '' - - class BaseMixin(CrudBaseMixin): - list_field_names = ['nome', 'legislatura'] - - def has_permission(self): - return permissao_tb_aux(self) - - class ListView(CrudListView): - ordering = 'legislatura' - - class CreateView(CrudCreateView): - form_class = BancadaForm - - class UpdateView(CrudUpdateView): - form_class = BancadaForm - - -class TipoSessaoCrud(Crud): - model = TipoSessaoPlenaria - help_path = 'tipo_sessao_plenaria' - - class BaseMixin(CrudBaseMixin): - - def has_permission(self): - return permissao_tb_aux(self) - - -class TipoResultadoVotacaoCrud(Crud): - model = TipoResultadoVotacao - help_path = 'tipo_resultado_votacao' - - class BaseMixin(CrudBaseMixin): - - def has_permission(self): - return permissao_tb_aux(self) - - -class TipoExpedienteCrud(Crud): - model = TipoExpediente - help_path = 'tipo_expediente' - - class BaseMixin(CrudBaseMixin): - - def has_permission(self): - return permissao_tb_aux(self) - - -class CargoBancadaCrud(Crud): - model = CargoBancada - help_path = '' - - class BaseMixin(CrudBaseMixin): - - def has_permission(self): - return permissao_tb_aux(self) - - def abrir_votacao_expediente_view(request, pk, spk): existe_votacao_aberta = ExpedienteMateria.objects.filter( sessao_plenaria_id=spk, votacao_aberta=True @@ -245,7 +191,7 @@ class MateriaOrdemDiaCrud(MasterDetailCrud): url = reverse('sapl.sessao:abrir_votacao', kwargs={ 'pk': obj.pk, 'spk': obj.sessao_plenaria_id}) - if self.request.user.has_perms(permissoes_sessao()): + if self.request.user.has_module_perms(AppConfig.label): btn_abrir = ''' Matéria não votada
Abrir Votação''' % (url) + obj.resultado = btn_abrir else: url = '' @@ -376,7 +323,6 @@ class ExpedienteMateriaCrud(MasterDetailCrud): class CreateView(MasterDetailCrud.CreateView): form_class = ExpedienteMateriaForm - permission_required = permissoes_sessao() def get_success_url(self): return reverse('sapl.sessao:expedientemateria_list', @@ -384,7 +330,6 @@ class ExpedienteMateriaCrud(MasterDetailCrud): class UpdateView(MasterDetailCrud.UpdateView): form_class = ExpedienteMateriaForm - permission_required = permissoes_sessao() def get_initial(self): self.initial['tipo_materia'] = self.object.materia.tipo.id @@ -392,9 +337,6 @@ class ExpedienteMateriaCrud(MasterDetailCrud): self.initial['ano_materia'] = self.object.materia.ano return self.initial - class DeleteView(PermissionRequiredMixin, MasterDetailCrud.DeleteView): - permission_required = permissoes_sessao() - class DetailView(MasterDetailCrud.DetailView): @property @@ -406,25 +348,16 @@ class OradorCrud(MasterDetailCrud): model = '' parent_field = 'sessao_plenaria' help_path = '' + public = [RP_LIST, RP_DETAIL] class ListView(MasterDetailCrud.ListView): ordering = ['numero_ordem', 'parlamentar'] - class CreateView(MasterDetailCrud.CreateView): - permission_required = permissoes_sessao() - - class UpdateView(MasterDetailCrud.UpdateView): - permission_required = permissoes_sessao() - - class DeleteView(MasterDetailCrud.DeleteView): - permission_required = permissoes_sessao() - class OradorExpedienteCrud(OradorCrud): model = OradorExpediente class CreateView(MasterDetailCrud.CreateView): - permission_required = permissoes_sessao() form_class = OradorExpedienteForm def get_success_url(self): @@ -432,18 +365,13 @@ class OradorExpedienteCrud(OradorCrud): kwargs={'pk': self.kwargs['pk']}) class UpdateView(MasterDetailCrud.UpdateView): - permission_required = permissoes_sessao() form_class = OradorExpedienteForm - class DeleteView(MasterDetailCrud.DeleteView): - permission_required = permissoes_sessao() - class OradorCrud(OradorCrud): model = Orador class CreateView(MasterDetailCrud.CreateView): - permission_required = permissoes_sessao() form_class = OradorForm def get_success_url(self): @@ -451,12 +379,8 @@ class OradorCrud(OradorCrud): kwargs={'pk': self.kwargs['pk']}) class UpdateView(MasterDetailCrud.UpdateView): - permission_required = permissoes_sessao() form_class = OradorForm - class DeleteView(MasterDetailCrud.DeleteView): - permission_required = permissoes_sessao() - def recuperar_numero_sessao(request): try: @@ -473,22 +397,19 @@ def recuperar_numero_sessao(request): class SessaoCrud(Crud): model = SessaoPlenaria help_path = 'sessao_plenaria' + public = [RP_DETAIL] - class BaseMixin(CrudBaseMixin): + class BaseMixin(Crud.BaseMixin): list_field_names = ['data_inicio', 'legislatura', 'sessao_legislativa', 'tipo'] - # FIXME!!!! corrigir referencias no codigo e remover isso!!!!! - # fazer com #230 - class CrudDetailView(CrudDetailView): + class CrudDetailView(DetailView): model = SessaoPlenaria - help_path = 'sessao_plenaria' - class ListView(CrudListView): + class ListView(Crud.ListView): ordering = ['-data_inicio'] - class CreateView(CrudCreateView): - permission_required = permissoes_sessao() + class CreateView(Crud.CreateView): def get_initial(self): legislatura = Legislatura.objects.order_by('-numero')[0] @@ -497,12 +418,6 @@ class SessaoCrud(Crud): return {'legislatura': legislatura, 'sessao_legislativa': sessao_legislativa} - class UpdateView(CrudUpdateView): - permission_required = permissoes_sessao() - - class DeleteView(CrudDeleteView): - permission_required = permissoes_sessao() - class PresencaMixin: @@ -535,18 +450,24 @@ class PresencaMixin: yield (parlamentar, False) -class PresencaView(FormMixin, - PresencaMixin, - SessaoCrud.CrudDetailView): +class PresencaView(FormMixin, PresencaMixin, DetailView): template_name = 'sessao/presenca.html' form_class = PresencaForm model = SessaoPlenaria + @method_decorator(permission_required(( + '%s.add_%s' % ( + AppConfig.label, SessaoPlenariaPresenca._meta.model_name), + '%s.change_%s' % ( + AppConfig.label, SessaoPlenariaPresenca._meta.model_name), + '%s.delete_%s' % ( + AppConfig.label, SessaoPlenariaPresenca._meta.model_name), + ))) def post(self, request, *args, **kwargs): self.object = self.get_object() form = self.get_form() - if not self.request.user.has_perms(permissoes_sessao()): + if not self.request.user.has_module_perms(AppConfig.label): return self.form_invalid(form) if form.is_valid(): @@ -586,12 +507,16 @@ class PainelView(PermissionRequiredMixin, TemplateView): permission_required = permissoes_painel() -class PresencaOrdemDiaView(FormMixin, - PresencaMixin, - SessaoCrud.CrudDetailView): +class PresencaOrdemDiaView(FormMixin, PresencaMixin, DetailView): template_name = 'sessao/presenca_ordemdia.html' form_class = PresencaForm + model = SessaoPlenaria + @method_decorator(permission_required(( + '%s.add_%s' % (AppConfig.label, PresencaOrdemDia._meta.model_name), + '%s.change_%s' % (AppConfig.label, PresencaOrdemDia._meta.model_name), + '%s.delete_%s' % (AppConfig.label, PresencaOrdemDia._meta.model_name), + ))) def post(self, request, *args, **kwargs): self.object = self.get_object() @@ -634,9 +559,10 @@ class PresencaOrdemDiaView(FormMixin, return reverse('sapl.sessao:presencaordemdia', kwargs={'pk': pk}) -class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): +class ListMateriaOrdemDiaView(FormMixin, DetailView): template_name = 'sessao/materia_ordemdia_list.html' form_class = ListMateriaForm + model = SessaoPlenaria def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -673,6 +599,11 @@ class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): return self.render_to_response(context) + @method_decorator(permission_required(( + '%s.add_%s' % (AppConfig.label, OrdemDia._meta.model_name), + '%s.change_%s' % (AppConfig.label, OrdemDia._meta.model_name), + '%s.delete_%s' % (AppConfig.label, OrdemDia._meta.model_name), + ))) def post(self, request, *args, **kwargs): self.object = self.get_object() context = self.get_context_data(object=self.object) @@ -737,12 +668,13 @@ class ListMateriaOrdemDiaView(FormMixin, SessaoCrud.CrudDetailView): return self.get(self, request, args, kwargs) -class MesaView(PermissionRequiredMixin, FormMixin, SessaoCrud.CrudDetailView): +class MesaView(FormMixin, DetailView): template_name = 'sessao/mesa.html' form_class = MesaForm - permission_required = permissoes_sessao() + model = SessaoPlenaria def get(self, request, *args, **kwargs): + self.object = self.get_object() context = self.get_context_data(object=self.object) @@ -762,6 +694,11 @@ class MesaView(PermissionRequiredMixin, FormMixin, SessaoCrud.CrudDetailView): return self.render_to_response(context) + @method_decorator(permission_required(( + '%s.add_integrantemesa' % AppConfig.label, + '%s.change_integrantemesa' % AppConfig.label, + '%s.delete_integrantemesa' % AppConfig.label, + ))) def post(self, request, *args, **kwargs): self.object = self.get_object() form = MesaForm(request.POST) diff --git a/sapl/templates/parlamentares/composicaomesa_form.html b/sapl/templates/parlamentares/composicaomesa_form.html index d8f08ac30..6f793155f 100644 --- a/sapl/templates/parlamentares/composicaomesa_form.html +++ b/sapl/templates/parlamentares/composicaomesa_form.html @@ -48,7 +48,7 @@


{% if cargos_vagos %} - {% if perms.parlamentares.add_cargomesa%} + {% if perms.parlamentares.add_cargomesa %} {% endif %} {% endif %} diff --git a/sapl/templates/sessao/mesa.html b/sapl/templates/sessao/mesa.html index 6909363a6..9bdef7b1c 100644 --- a/sapl/templates/sessao/mesa.html +++ b/sapl/templates/sessao/mesa.html @@ -20,10 +20,12 @@
-

- {% if view.get_cargos_mesa %}{% endif %} -

- + {% if perms.sessao %} +

+ {% if view.get_cargos_mesa %}{% endif %} +

+ + {% endif %}
{% if view.get_cargos_mesa %}