Browse Source

Fix #1395

pull/1405/head
LeandroRoberto 8 years ago
parent
commit
a07e53257e
  1. 4
      sapl/crud/base.py
  2. 40
      sapl/parlamentares/views.py

4
sapl/crud/base.py

@ -17,8 +17,8 @@ from django.http.response import Http404
from django.shortcuts import redirect from django.shortcuts import redirect
from django.utils.decorators import classonlymethod from django.utils.decorators import classonlymethod
from django.utils.encoding import force_text 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 string_concat
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 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.settings import BASE_DIR
from sapl.utils import normalize from sapl.utils import normalize
logger = logging.getLogger(BASE_DIR.name) logger = logging.getLogger(BASE_DIR.name)
ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \ ACTION_LIST, ACTION_CREATE, ACTION_DETAIL, ACTION_UPDATE, ACTION_DELETE = \
@ -955,6 +956,7 @@ class CrudAux(Crud):
Se o valor de subnav_template_name é nulo faz o filter subnav Se o valor de subnav_template_name é nulo faz o filter subnav
não abrir o padrão e nem um outro arquivo. não abrir o padrão e nem um outro arquivo.
""" """
if 'subnav_template_name' not in context:
context['subnav_template_name'] = self.subnav_template_name context['subnav_template_name'] = self.subnav_template_name
return context return context

40
sapl/parlamentares/views.py

@ -1,7 +1,12 @@
import datetime
import json
from django.contrib import messages from django.contrib import messages
from django.contrib.contenttypes.models import ContentType
from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist from django.core.exceptions import MultipleObjectsReturned, ObjectDoesNotExist
from django.core.urlresolvers import reverse, reverse_lazy from django.core.urlresolvers import reverse, reverse_lazy
from django.db.models import F, Q from django.db.models import F, Q
from django.db.models.aggregates import Count
from django.http import JsonResponse from django.http import JsonResponse
from django.http.response import HttpResponseRedirect from django.http.response import HttpResponseRedirect
from django.templatetags.static import static 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.utils.translation import ugettext_lazy as _
from django.views.decorators.clickjacking import xframe_options_exempt from django.views.decorators.clickjacking import xframe_options_exempt
from django.views.generic import FormView 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.comissoes.models import Participacao
from sapl.crud.base import (RP_CHANGE, RP_DETAIL, RP_LIST, Crud, CrudAux, from sapl.crud.base import (RP_CHANGE, RP_DETAIL, RP_LIST, Crud, CrudAux,
CrudBaseForListAndDetailExternalAppView, CrudBaseForListAndDetailExternalAppView,
MasterDetailCrud) MasterDetailCrud)
from sapl.materia.models import Autoria
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
@ -25,14 +33,6 @@ from .models import (CargoMesa, Coligacao, ComposicaoColigacao, ComposicaoMesa,
NivelInstrucao, Parlamentar, Partido, SessaoLegislativa, NivelInstrucao, Parlamentar, Partido, SessaoLegislativa,
SituacaoMilitar, TipoAfastamento, TipoDependente, Votante) 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') CargoMesaCrud = CrudAux.build(CargoMesa, 'cargo_mesa')
PartidoCrud = CrudAux.build(Partido, 'partidos') PartidoCrud = CrudAux.build(Partido, 'partidos')
@ -189,7 +189,8 @@ class ColigacaoCrud(CrudAux):
ordering = ('-numero_votos', 'nome') ordering = ('-numero_votos', 'nome')
def get_context_data(self, **kwargs): 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'] rows = context['rows']
coluna_votos_recebidos = 2 coluna_votos_recebidos = 2
for row in rows: for row in rows:
@ -201,15 +202,25 @@ class ColigacaoCrud(CrudAux):
class DetailView(CrudAux.DetailView): class DetailView(CrudAux.DetailView):
def get_context_data(self, **kwargs): 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'] coligacao = context['coligacao']
if not coligacao.numero_votos: if not coligacao.numero_votos:
coligacao.numero_votos = '0' coligacao.numero_votos = '0'
context['subnav_template_name'] = \
'parlamentares/subnav_coligacao.yaml'
return context return context
class BaseMixin(CrudAux.BaseMixin): class UpdateView(CrudAux.UpdateView):
subnav_template_name = 'parlamentares/subnav_coligacao.yaml'
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): def json_date_convert(date):
@ -295,6 +306,7 @@ class FrenteCrud(CrudAux):
list_field_names = ['nome', 'data_criacao', 'parlamentares'] list_field_names = ['nome', 'data_criacao', 'parlamentares']
class CreateView(CrudAux.CreateView): class CreateView(CrudAux.CreateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -305,6 +317,7 @@ class FrenteCrud(CrudAux):
return context return context
class UpdateView(CrudAux.UpdateView): class UpdateView(CrudAux.UpdateView):
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
@ -343,7 +356,6 @@ class MandatoCrud(MasterDetailCrud):
return context return context
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = MandatoForm form_class = MandatoForm
@ -388,6 +400,7 @@ class LegislaturaCrud(CrudAux):
form_class = LegislaturaUpdateForm form_class = LegislaturaUpdateForm
class DetailView(CrudAux.DetailView): class DetailView(CrudAux.DetailView):
def has_permission(self): def has_permission(self):
return True return True
@ -396,6 +409,7 @@ class LegislaturaCrud(CrudAux):
return super().get(request, *args, **kwargs) return super().get(request, *args, **kwargs)
class ListView(CrudAux.ListView): class ListView(CrudAux.ListView):
def has_permission(self): def has_permission(self):
return True return True

Loading…
Cancel
Save