diff --git a/comissoes/views.py b/comissoes/views.py index 42da7e302..e7315e9ae 100644 --- a/comissoes/views.py +++ b/comissoes/views.py @@ -1,12 +1,13 @@ +from django import forms from django.utils.translation import ugettext_lazy as _ - -from sapl.crud import build_crud - -from .models import CargoComissao, Comissao, Periodo, TipoComissao - +from django.views.generic import ListView from django.views.generic.edit import FormMixin +from sapl.crud import build_crud from vanilla import GenericView +from .models import (CargoComissao, Comissao, Composicao, Participacao, + Periodo, TipoComissao) + cargo_crud = build_crud( CargoComissao, 'cargo_comissao', [ @@ -58,9 +59,39 @@ comissao_crud = build_crud( ]) -class ComposicaoView(comissao_crud.CrudDetailView): +class ComposicaoForm(forms.Form): + periodo = forms.CharField() + + +class ComposicaoView(FormMixin, GenericView): template_name = 'comissoes/composicao.html' + def get(self, request, *args, **kwargs): + form = ComposicaoForm() + + composicoes = Composicao.objects.filter( + comissao_id=self.kwargs['pk']).order_by('-periodo') + participacoes = Participacao.objects.all() + + return self.render_to_response({ + 'participacoes': participacoes, + 'composicoes': composicoes, + 'composicao_id': composicoes.first().id, + 'form': form}) + + def post(self, request, *args, **kwargs): + form = ComposicaoForm(request.POST) + + composicoes = Composicao.objects.filter( + comissao_id=self.kwargs['pk']).order_by('-periodo') + participacoes = Participacao.objects.all() + + return self.render_to_response({ + 'participacoes': participacoes, + 'composicoes': composicoes, + 'composicao_id': int(form.data['periodo']), + 'form': form}) + class MateriasView(comissao_crud.CrudDetailView): template_name = 'comissoes/materias.html' @@ -70,7 +101,5 @@ class ReunioesView(comissao_crud.CrudDetailView): template_name = 'comissoes/reunioes.html' -class ComissaoParlamentarIncluirView(GenericView): - - template_name = "comissoes/comissao_parlamentar.html" - +class ComissaoParlamentarIncluirView(comissao_crud.CrudDetailView): + template_name = "comissoes/comissao_parlamentar.html" diff --git a/templates/comissoes/comissao_detail.html b/templates/comissoes/comissao_detail.html index 84e7213f6..bd1afdc6b 100644 --- a/templates/comissoes/comissao_detail.html +++ b/templates/comissoes/comissao_detail.html @@ -3,9 +3,9 @@ {% block sections_nav %}
Nome | +Cargo | +Titular | +Designação | +Desligamento | +Motivo | +Observação | +
---|---|---|---|---|---|---|
{{participacao.parlamentar.nome_parlamentar}} | +{{participacao.cargo}} | +{{participacao.titular|yesno:"Sim,Não"}} | +{{participacao.data_designacao|date:"d/m/Y"}} | +{{participacao.data_desligamento|date:"d/m/Y"|default:"-"}} | +{{participacao.motivo_desligamento|default:"-"}} | +{{participacao.observacao|default:"-"}} | +