From d8a49e1d5f432ac640107c61945fc55ddcae519c Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Tue, 4 Oct 2016 18:42:42 -0300 Subject: [PATCH] Filtra parlamentares de acordo com presenca na sessao --- sapl/base/templatetags/menus.py | 3 +-- sapl/sessao/forms.py | 13 +++++++++++-- sapl/sessao/views.py | 17 ++++++++++++++--- 3 files changed, 26 insertions(+), 7 deletions(-) diff --git a/sapl/base/templatetags/menus.py b/sapl/base/templatetags/menus.py index 61c468acf..3cbf5e46c 100644 --- a/sapl/base/templatetags/menus.py +++ b/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() diff --git a/sapl/sessao/forms.py b/sapl/sessao/forms.py index 3320ab685..0ac7b1f0e 100644 --- a/sapl/sessao/forms.py +++ b/sapl/sessao/forms.py @@ -15,7 +15,8 @@ from sapl.parlamentares.models import Parlamentar from sapl.utils import RANGE_DIAS_MES, RANGE_MESES, autor_label, autor_modal from .models import (Bancada, ExpedienteMateria, Orador, OradorExpediente, - OrdemDia, SessaoPlenaria) + OrdemDia, PresencaOrdemDia, SessaoPlenaria, + SessaoPlenariaPresenca) def pega_anos(): @@ -275,8 +276,15 @@ class OradorForm(ModelForm): def __init__(self, *args, **kwargs): super(OradorForm, self).__init__(*args, **kwargs) + + id_sessao = int(self.initial['id_sessao']) + + ids = [s.parlamentar.id for + s in SessaoPlenariaPresenca.objects.filter( + sessao_plenaria_id=id_sessao)] + self.fields['parlamentar'].queryset = Parlamentar.objects.filter( - ativo=True).order_by('nome_completo') + id__in=ids).order_by('nome_completo') class Meta: model = Orador @@ -287,6 +295,7 @@ class OradorExpedienteForm(ModelForm): def __init__(self, *args, **kwargs): super(OradorExpedienteForm, self).__init__(*args, **kwargs) + self.fields['parlamentar'].queryset = Parlamentar.objects.filter( ativo=True).order_by('nome_completo') diff --git a/sapl/sessao/views.py b/sapl/sessao/views.py index c307f98bb..f4d00dd65 100644 --- a/sapl/sessao/views.py +++ b/sapl/sessao/views.py @@ -34,9 +34,10 @@ from sapl.sessao.serializers import SessaoPlenariaSerializer from sapl.utils import permission_required_for_app from .forms import (AdicionarVariasMateriasFilterSet, ExpedienteForm, - ListMateriaForm, MesaForm, PautaSessaoFilterSet, - PresencaForm, SessaoPlenariaFilterSet, VotacaoEditForm, - VotacaoForm, VotacaoNominalForm) + ListMateriaForm, MesaForm, OradorExpedienteForm, + OradorForm, PautaSessaoFilterSet, PresencaForm, + SessaoPlenariaFilterSet, VotacaoEditForm, VotacaoForm, + VotacaoNominalForm) from .models import (Bancada, Bloco, CargoBancada, CargoMesa, ExpedienteMateria, ExpedienteSessao, IntegranteMesa, MateriaLegislativa, Orador, OradorExpediente, OrdemDia, @@ -364,6 +365,11 @@ class OradorExpedienteCrud(OradorCrud): class CreateView(MasterDetailCrud.CreateView): + form_class = OradorExpedienteForm + + def get_initial(self): + return {'id_sessao': self.kwargs['pk']} + def get_success_url(self): return reverse('sapl.sessao:oradorexpediente_list', kwargs={'pk': self.kwargs['pk']}) @@ -374,6 +380,11 @@ class OradorCrud(OradorCrud): class CreateView(MasterDetailCrud.CreateView): + form_class = OradorForm + + def get_initial(self): + return {'id_sessao': self.kwargs['pk']} + def get_success_url(self): return reverse('sapl.sessao:orador_list', kwargs={'pk': self.kwargs['pk']})