From 75d622d0d97b5efd34741699076af0194543dfff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Cantu=C3=A1ria?= Date: Mon, 23 Nov 2020 15:52:54 -0300 Subject: [PATCH] =?UTF-8?q?Cria=20pesquisa=20de=20coliga=C3=A7=C3=A3o=20(#?= =?UTF-8?q?3304)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Adiciona link para criação de coligação em tabelas auxiliares --- sapl/parlamentares/forms.py | 22 ++++++- sapl/parlamentares/urls.py | 15 ++--- sapl/parlamentares/views.py | 62 +++++++++++++++++-- sapl/templates/menu_tabelas_auxiliares.yaml | 9 ++- .../parlamentares/coligacao_detail.html | 13 ++++ .../parlamentares/coligacao_filter.html | 51 +++++++++++++++ 6 files changed, 153 insertions(+), 19 deletions(-) create mode 100644 sapl/templates/parlamentares/coligacao_detail.html create mode 100644 sapl/templates/parlamentares/coligacao_filter.html diff --git a/sapl/parlamentares/forms.py b/sapl/parlamentares/forms.py index a8ab4a111..d863d78e6 100755 --- a/sapl/parlamentares/forms.py +++ b/sapl/parlamentares/forms.py @@ -22,7 +22,7 @@ from sapl.crispy_layout_mixin import form_actions, to_row from sapl.rules import SAPL_GROUP_VOTANTE import django_filters -from .models import (ComposicaoColigacao, Filiacao, Frente, Legislatura, +from .models import (Coligacao, ComposicaoColigacao, Filiacao, Frente, Legislatura, Mandato, Parlamentar, Votante, Bloco, FrenteParlamentar) @@ -251,6 +251,26 @@ class ParlamentarFilterSet(django_filters.FilterSet): ) +class ColigacaoFilterSet(django_filters.FilterSet): + nome = django_filters.CharFilter(label=_('Nome da Coligação'), lookup_expr='icontains') + + class Meta: + model = Coligacao + fields = ['nome'] + + def __init__(self, *args, **kwargs): + super(ColigacaoFilterSet, self).__init__(*args, **kwargs) + + row0 = to_row([('nome', 12)]) + + self.form.helper = SaplFormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Pesquisa de Coligação'), + row0, + form_actions(label='Pesquisar'))) + + class ParlamentarCreateForm(ParlamentarForm): logger = logging.getLogger(__name__) diff --git a/sapl/parlamentares/urls.py b/sapl/parlamentares/urls.py index 2b50c208c..66a5ae406 100644 --- a/sapl/parlamentares/urls.py +++ b/sapl/parlamentares/urls.py @@ -22,7 +22,7 @@ from sapl.parlamentares.views import (CargoMesaCrud, ColigacaoCrud, parlamentares_filiados, BlocoCrud, PesquisarParlamentarView, VincularParlamentarView, get_sessoes_legislatura, FrenteCargoCrud, FrenteParlamentarCrud, - get_parlamentar_frentes) + get_parlamentar_frentes, PesquisarColigacaoView) from .apps import AppConfig @@ -49,14 +49,11 @@ urlpatterns = [ url(r'^parlamentar/vincular-parlamentar/$', VincularParlamentarView.as_view(), name='vincular_parlamentar'), - url(r'^parlamentar/coligacao-legislatura/', - coligacao_legislatura, name="coligacao_legislatura"), - - url(r'^sistema/coligacao/', - include(ColigacaoCrud.get_urls() + - ComposicaoColigacaoCrud.get_urls())), - url(r'^sistema/bloco/', - include(BlocoCrud.get_urls())), + url(r'^parlamentar/coligacao-legislatura/', coligacao_legislatura, name="coligacao_legislatura"), + url(r'^sistema/coligacao/', include(ColigacaoCrud.get_urls() + ComposicaoColigacaoCrud.get_urls())), + url(r'^sistema/pesquisar-coligacao/', PesquisarColigacaoView.as_view(), name='pesquisar_coligacao'), + + url(r'^sistema/bloco/', include(BlocoCrud.get_urls())), url(r'^sistema/frente/', include(FrenteCrud.get_urls())), url(r'^sistema/frente-cargo/', include(FrenteCargoCrud.get_urls())), diff --git a/sapl/parlamentares/views.py b/sapl/parlamentares/views.py index 39d244203..e14c3c333 100644 --- a/sapl/parlamentares/views.py +++ b/sapl/parlamentares/views.py @@ -33,7 +33,7 @@ from sapl.materia.models import Autoria, Proposicao, Relatoria from sapl.parlamentares.apps import AppConfig from sapl.utils import (parlamentares_ativos, show_results_filter_set) -from .forms import (FiliacaoForm, FrenteForm, LegislaturaForm, MandatoForm, +from .forms import (ColigacaoFilterSet, FiliacaoForm, FrenteForm, LegislaturaForm, MandatoForm, ParlamentarCreateForm, ParlamentarForm, VotanteForm, ParlamentarFilterSet, VincularParlamentarForm, BlocoForm, FrenteParlamentarForm) @@ -230,6 +230,55 @@ class PesquisarParlamentarView(FilterView): return self.render_to_response(context) +class PesquisarColigacaoView(FilterView): + model = Coligacao + filterset_class = ColigacaoFilterSet + paginate_by = 10 + + def get_filterset_kwargs(self, filterset_class): + super(PesquisarColigacaoView, self).get_filterset_kwargs(filterset_class) + + return ({ + 'data': self.request.GET or None, + 'queryset': self.get_queryset().order_by('nome').distinct() + }) + + + def get_context_data(self, **kwargs): + context = super(PesquisarColigacaoView, self).get_context_data(**kwargs) + + paginator = context['paginator'] + page_obj = context['page_obj'] + + context.update({ + 'page_range': make_pagination(page_obj.number, paginator.num_pages), + 'NO_ENTRIES_MSG': 'Nenhuma coligação encontrada!', + 'title': _('Coligações') + }) + + return context + + def get(self, request, *args, **kwargs): + super(PesquisarColigacaoView, self).get(request) + + data = self.filterset.data + url = '' + if data: + url = "&" + str(self.request.META['QUERY_STRING']) + if url.startswith("&page"): + ponto_comeco = url.find('nome=') - 1 + url = url[ponto_comeco:] + + context = self.get_context_data(filter=self.filterset, + object_list=self.object_list, + filter_url=url, + numero_res=len(self.object_list)) + + context['show_results'] = show_results_filter_set(self.request.GET.copy()) + + return self.render_to_response(context) + + class ParticipacaoParlamentarCrud(CrudBaseForListAndDetailExternalAppView): model = Participacao parent_field = 'parlamentar' @@ -297,8 +346,7 @@ class ColigacaoCrud(CrudAux): if not coligacao.numero_votos: coligacao.numero_votos = '0' - context['subnav_template_name'] = \ - 'parlamentares/subnav_coligacao.yaml' + context['subnav_template_name'] = 'parlamentares/subnav_coligacao.yaml' return context @@ -306,12 +354,14 @@ class ColigacaoCrud(CrudAux): def get_context_data(self, **kwargs): context = super(UpdateView, self).get_context_data(kwargs=kwargs) - - context['subnav_template_name'] = \ - 'parlamentares/subnav_coligacao.yaml' + context['subnav_template_name'] = 'parlamentares/subnav_coligacao.yaml' return context + class DeleteView(CrudAux.DeleteView): + def get_success_url(self): + return reverse('sapl.parlamentares:pesquisar_coligacao') + def coligacao_legislatura(request): try: diff --git a/sapl/templates/menu_tabelas_auxiliares.yaml b/sapl/templates/menu_tabelas_auxiliares.yaml index 3af2d293e..b2b55a0b1 100644 --- a/sapl/templates/menu_tabelas_auxiliares.yaml +++ b/sapl/templates/menu_tabelas_auxiliares.yaml @@ -41,12 +41,15 @@ - title: {% trans 'Nível de Instrução' %} url: sapl.parlamentares:nivelinstrucao_list css_class: btn btn-link + - title: {% trans 'Pesquisar Coligação' %} + url: sapl.parlamentares:pesquisar_coligacao + css_class: btn btn-link + - title: {% trans 'Adicionar Coligação' %} + url: sapl.parlamentares:coligacao_create + css_class: btn btn-link - title: {% trans 'Partido' %} url: sapl.parlamentares:partido_list css_class: btn btn-link - - title: {% trans 'Coligação' %} - url: sapl.parlamentares:coligacao_list - css_class: btn btn-link - title: {% trans 'Módulo Mesa Diretora' %} css_class: head_title children: diff --git a/sapl/templates/parlamentares/coligacao_detail.html b/sapl/templates/parlamentares/coligacao_detail.html new file mode 100644 index 000000000..5002901e7 --- /dev/null +++ b/sapl/templates/parlamentares/coligacao_detail.html @@ -0,0 +1,13 @@ +{% extends "crud/detail.html" %} +{% load i18n %} +{% load crispy_forms_tags cropping %} +{% block actions %} +
+ Pesquisar Coligação + Adicionar Coligação +
+
+ Editar + Excluir +
+{% endblock actions %} \ No newline at end of file diff --git a/sapl/templates/parlamentares/coligacao_filter.html b/sapl/templates/parlamentares/coligacao_filter.html new file mode 100644 index 000000000..ba3a82c33 --- /dev/null +++ b/sapl/templates/parlamentares/coligacao_filter.html @@ -0,0 +1,51 @@ +{% extends "crud/list.html" %} +{% load i18n %} +{% load crispy_forms_tags staticfiles %} + +{% block base_content %} + {% if not show_results %} + {% crispy filter.form %} + {% else %} +
+ {% trans 'Fazer nova pesquisa' %} + {% if not request.user.is_anonymous %} + Adicionar Coligação + {% endif %} +
+
+ {% if numero_res > 0 %} + {% if numero_res == 1 %} +

Foi encontrado {{ numero_res }} resultado.

+ {% else %} +

Foram encontrados {{ numero_res }} resultados.

+ {% endif %} + + + + + + + + + + {% for coligacao in page_obj %} + + + + + + {% endfor %} + +
Nome da ColigaçãoLegislaturaNúmero de Votos
+ {{coligacao.nome}} + + {{coligacao.legislatura}} + {% if coligacao.numero_votos %} {{ coligacao.numero_votos }} {% else %} - {% endif %}
+ {% else %} +

{{ NO_ENTRIES_MSG }}

+ {% endif %} + {% endif %} +
+ {% include 'paginacao.html'%} +


+{% endblock base_content %}