From a07e53257e7cf0a108f17542160df2ca336f0beb Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Fri, 11 Aug 2017 15:05:23 -0300 Subject: [PATCH] Fix #1395 --- sapl/crud/base.py | 6 ++- sapl/parlamentares/views.py | 74 ++++++++++++++++++++++--------------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/sapl/crud/base.py b/sapl/crud/base.py index a00336fc7..70ea1c859 100644 --- a/sapl/crud/base.py +++ b/sapl/crud/base.py @@ -17,8 +17,8 @@ from django.http.response import Http404 from django.shortcuts import redirect from django.utils.decorators import classonlymethod from django.utils.encoding import force_text -from django.utils.translation import ugettext_lazy as _ 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 @@ -30,6 +30,7 @@ from sapl.rules.map_rules import (RP_ADD, RP_CHANGE, RP_DELETE, RP_DETAIL, from sapl.settings import BASE_DIR from sapl.utils import normalize + logger = logging.getLogger(BASE_DIR.name) ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \ @@ -955,7 +956,8 @@ class CrudAux(Crud): Se o valor de subnav_template_name é nulo faz o filter subnav não abrir o padrão e nem um outro arquivo. """ - context['subnav_template_name'] = self.subnav_template_name + if 'subnav_template_name' not in context: + context['subnav_template_name'] = self.subnav_template_name return context @classonlymethod diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 309c8b3cd..00c0c5aef 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -1,7 +1,12 @@ +import datetime +import json + from django.contrib import messages +from django.contrib.contenttypes.models import ContentType from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.core.urlresolvers import reverse, reverse_lazy from django.db.models import F, Q +from django.db.models.aggregates import Count from django.http import JsonResponse from django.http.response import HttpResponseRedirect from django.templatetags.static import static @@ -9,11 +14,14 @@ from django.utils.datastructures import MultiValueDictKeyError from django.utils.translation import ugettext_lazy as _ from django.views.decorators.clickjacking import xframe_options_exempt from django.views.generic import FormView +from django.views.generic.edit import UpdateView +from sapl.base.models import Autor from sapl.comissoes.models import Participacao from sapl.crud.base import (RP_CHANGE, RP_DETAIL, RP_LIST, Crud, CrudAux, CrudBaseForListAndDetailExternalAppView, MasterDetailCrud) +from sapl.materia.models import Autoria from sapl.materia.models import Proposicao, Relatoria from sapl.parlamentares.apps import AppConfig @@ -25,14 +33,6 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, SituacaoMilitar, TipoAfastamento, TipoDependente, Votante) -from sapl.base.models import Autor -from sapl.materia.models import Autoria -from django.contrib.contenttypes.models import ContentType -from django.db.models.aggregates import Count - -import datetime -import json - CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa') PartidoCrud = CrudAux.build(Partido, 'partidos') @@ -189,7 +189,8 @@ class ColigacaoCrud(CrudAux): ordering = ('-numero_votos', 'nome') def get_context_data(self, **kwargs): - context = super(ColigacaoCrud.ListView, self).get_context_data(kwargs=kwargs) + context = super(ColigacaoCrud.ListView, self).get_context_data( + kwargs=kwargs) rows = context['rows'] coluna_votos_recebidos = 2 for row in rows: @@ -201,15 +202,25 @@ class ColigacaoCrud(CrudAux): class DetailView(CrudAux.DetailView): def get_context_data(self, **kwargs): - context = super(ColigacaoCrud.DetailView, self).get_context_data(kwargs=kwargs) + context = super().get_context_data(kwargs=kwargs) coligacao = context['coligacao'] if not coligacao.numero_votos: coligacao.numero_votos = '0' + context['subnav_template_name'] = \ + 'parlamentares/subnav_coligacao.yaml' + return context - class BaseMixin(CrudAux.BaseMixin): - subnav_template_name = 'parlamentares/subnav_coligacao.yaml' + class UpdateView(CrudAux.UpdateView): + + def get_context_data(self, **kwargs): + context = super(UpdateView, self).get_context_data(kwargs=kwargs) + + context['subnav_template_name'] = \ + 'parlamentares/subnav_coligacao.yaml' + + return context def json_date_convert(date): @@ -295,6 +306,7 @@ class FrenteCrud(CrudAux): list_field_names = ['nome', 'data_criacao', 'parlamentares'] class CreateView(CrudAux.CreateView): + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -305,6 +317,7 @@ class FrenteCrud(CrudAux): return context class UpdateView(CrudAux.UpdateView): + def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) @@ -343,7 +356,6 @@ class MandatoCrud(MasterDetailCrud): return context - class CreateView(MasterDetailCrud.CreateView): form_class = MandatoForm @@ -388,6 +400,7 @@ class LegislaturaCrud(CrudAux): form_class = LegislaturaUpdateForm class DetailView(CrudAux.DetailView): + def has_permission(self): return True @@ -396,6 +409,7 @@ class LegislaturaCrud(CrudAux): return super().get(request, *args, **kwargs) class ListView(CrudAux.ListView): + def has_permission(self): return True @@ -621,7 +635,7 @@ class ParlamentarMateriasView(FormView): 'materia__tipo__sigla', 'materia__tipo__descricao').annotate( total=Count('materia__tipo__pk')).order_by( - '-materia__ano', 'materia__tipo') + '-materia__ano', 'materia__tipo') autor_list = self.get_autoria(autoria) coautor_list = self.get_autoria(coautoria) @@ -823,24 +837,24 @@ def remove_parlamentar_composicao(request): '%s.delete_%s' % ( AppConfig.label, ComposicaoMesa._meta.model_name)): - if 'composicao_mesa' in request.POST: - try: - composicao = ComposicaoMesa.objects.get( - id=request.POST['composicao_mesa']) - except ObjectDoesNotExist: - return JsonResponse( - {'msg': ( - 'Composição da Mesa não pôde ser removida!', 0)}) - - composicao.delete() - - return JsonResponse( - {'msg': ( - 'Parlamentar excluido com sucesso!', 1)}) - else: + if 'composicao_mesa' in request.POST: + try: + composicao = ComposicaoMesa.objects.get( + id=request.POST['composicao_mesa']) + except ObjectDoesNotExist: return JsonResponse( {'msg': ( - 'Selecione algum parlamentar para ser excluido!', 0)}) + 'Composição da Mesa não pôde ser removida!', 0)}) + + composicao.delete() + + return JsonResponse( + {'msg': ( + 'Parlamentar excluido com sucesso!', 1)}) + else: + return JsonResponse( + {'msg': ( + 'Selecione algum parlamentar para ser excluido!', 0)}) def partido_parlamentar_sessao_legislativa(sessao, parlamentar):