From 5c161e8d01e67544fe1a0d4750f267e5ba9796f6 Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 19 Apr 2016 13:05:43 -0300 Subject: [PATCH 01/11] Comeca a refatoracao --- protocoloadm/forms.py | 234 +++++++++++++++++++++++++++--------------- protocoloadm/views.py | 6 -- 2 files changed, 154 insertions(+), 86 deletions(-) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index 256e06788..dbaecf63f 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -5,11 +5,14 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit from django import forms from django.core.exceptions import ObjectDoesNotExist +from django.db import models from django.forms import ModelForm from django.utils.translation import ugettext_lazy as _ import crispy_layout_mixin import sapl +import django_filters + from crispy_layout_mixin import form_actions from materia.models import Autor, TipoMateriaLegislativa from sapl.utils import RANGE_ANOS @@ -25,108 +28,179 @@ NATUREZA_PROCESSO = [('0', 'Administrativo'), ('', 'Ambos')] -def get_range_anos(): - return [('', 'Selecione')] \ - + [(year, year) for year in range(date.today().year, 1960, -1)] +ANO_CHOICES = [('', '---------')] + RANGE_ANOS -class ProtocoloForm(forms.Form): +# class ProtocoloForm(forms.Form): - YEARS = get_range_anos() +# YEARS = get_range_anos() - tipo_protocolo = forms.ChoiceField(required=False, - label='Tipo de Protocolo', - choices=TIPOS_PROTOCOLO, - widget=forms.Select( - attrs={'class': 'selector'})) +# tipo_protocolo = forms.ChoiceField(required=False, +# label='Tipo de Protocolo', +# choices=TIPOS_PROTOCOLO, +# widget=forms.Select( +# attrs={'class': 'selector'})) - numero_protocolo = forms.CharField( - label='Número de Protocolo', required=False) +# numero_protocolo = forms.CharField( +# label='Número de Protocolo', required=False) - ano = forms.ChoiceField(required=False, - label='Ano', - choices=YEARS, - widget=forms.Select( - attrs={'class': 'selector'})) +# ano = forms.ChoiceField(required=False, +# label='Ano', +# choices=YEARS, +# widget=forms.Select( +# attrs={'class': 'selector'})) - inicial = forms.DateField(label='Data Inicial', - required=False, - widget=forms.TextInput( - attrs={'class': 'dateinput'})) +# inicial = forms.DateField(label='Data Inicial', +# required=False, +# widget=forms.TextInput( +# attrs={'class': 'dateinput'})) - final = forms.DateField(label='Data Final', required=False, - widget=forms.TextInput( - attrs={'class': 'dateinput'})) +# final = forms.DateField(label='Data Final', required=False, +# widget=forms.TextInput( +# attrs={'class': 'dateinput'})) - natureza_processo = forms.ChoiceField(required=False, - label='Natureza Processo', - choices=[ - ('0', 'Administrativo'), - ('1', 'Legislativo'), - ('', 'Ambos')]) +# natureza_processo = forms.ChoiceField(required=False, +# label='Natureza Processo', +# choices=[ +# ('0', 'Administrativo'), +# ('1', 'Legislativo'), +# ('', 'Ambos')]) - tipo_documento = forms.ModelChoiceField( - label='Tipo de Documento', - required=False, - queryset=TipoDocumentoAdministrativo.objects.all(), - empty_label='Selecione', - ) +# tipo_documento = forms.ModelChoiceField( +# label='Tipo de Documento', +# required=False, +# queryset=TipoDocumentoAdministrativo.objects.all(), +# empty_label='Selecione', +# ) - interessado = forms.CharField(label='Interessado', required=False) +# interessado = forms.CharField(label='Interessado', required=False) - tipo_materia = forms.ModelChoiceField( - label='Tipo de Matéria', - required=False, - queryset=TipoMateriaLegislativa.objects.all(), - empty_label='Selecione', - ) +# tipo_materia = forms.ModelChoiceField( +# label='Tipo de Matéria', +# required=False, +# queryset=TipoMateriaLegislativa.objects.all(), +# empty_label='Selecione', +# ) - autor = forms.CharField(widget=forms.HiddenInput(), required=False) +# autor = forms.CharField(widget=forms.HiddenInput(), required=False) - assunto = forms.CharField(label='Assunto', required=False) +# assunto = forms.CharField(label='Assunto', required=False) - def __init__(self, *args, **kwargs): +# def __init__(self, *args, **kwargs): - row1 = crispy_layout_mixin.to_row( - [('numero_protocolo', 6), - ('ano', 6)]) +# super(ProtocoloForm, self).__init__( +# *args, **kwargs) - row2 = crispy_layout_mixin.to_row( - [('inicial', 6), - ('final', 6)]) - row3 = crispy_layout_mixin.to_row( - [('tipo_documento', 4), - ('tipo_protocolo', 4), - ('tipo_materia', 4)]) +# Importar essa classe de materias.views quando for feito o Merge do branch 217 +class RangeWidgetOverride(forms.MultiWidget): - row4 = crispy_layout_mixin.to_row( - [('interessado', 6), - ('assunto', 6)]) + def __init__(self, attrs=None): + widgets = (forms.DateInput(format='%d/%m/%Y', + attrs={'class': 'dateinput', + 'placeholder': 'Inicial'}), + forms.DateInput(format='%d/%m/%Y', + attrs={'class': 'dateinput', + 'placeholder': 'Final'})) + super(RangeWidgetOverride, self).__init__(widgets, attrs) - row5 = crispy_layout_mixin.to_row( - [('autor', 0), - (Button('pesquisar', - 'Pesquisar Autor', - css_class='btn btn-primary btn-sm'), 2), - (Button('limpar', - 'Limpar Autor', - css_class='btn btn-primary btn-sm'), 10)]) + def decompress(self, value): + if value: + return [value.start, value.stop] + return [None, None] - row6 = crispy_layout_mixin.to_row( - [('natureza_processo', 12)]) + def format_output(self, rendered_widgets): + return ''.join(rendered_widgets) - self.helper = FormHelper() - self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'), - row1, row2, - row3, row4, - HTML(sapl.utils.autor_label), - HTML(sapl.utils.autor_modal), - row5, - row6, - form_actions(save_label='Pesquisar'))) - super(ProtocoloForm, self).__init__( - *args, **kwargs) + +class ProtocoloFilterSet(django_filters.FilterSet): + + filter_overrides = {models.DateField: { + 'filter_class': django_filters.DateFromToRangeFilter, + 'extra': lambda f: { + 'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')), + 'widget': RangeWidgetOverride} + }} + + ano = django_filters.ChoiceFilter(required=False, + label=u'Ano da Matéria', + choices=ANO_CHOICES, + help_text="") + + assunto_ementa = django_filters.CharFilter(lookup_expr='icontains') + + interessado = django_filters.CharFilter(lookup_expr='icontains') + + class Meta: + model = Protocolo + fields = ['tipo_protocolo', + 'numero', + 'tipo_documento', + 'data_publicacao', + 'tipo_materia', + 'autor' + ] + + order_by = ( + ('', 'Selecione'), + ('CRE', 'Ordem Crescente'), + ('DEC', 'Ordem Decrescente'), + ) + + order_by_mapping = { + '': [], + 'CRE': ['ano', 'numero'], + 'DEC': ['-ano', '-numero'], + } + + def get_order_by(self, order_value): + if order_value in self.order_by_mapping: + return self.order_by_mapping[order_value] + else: + return super(ProtocoloFilterSet, + self).get_order_by(order_value) + + def __init__(self, *args, **kwargs): + super(ProtocoloFilterSet, self).__init__(*args, **kwargs) + + self.filters['autor'].label = 'Tipo de Matéria' + self.filters['assunto_ementa'].label = 'Assunto' + + row1 = crispy_layout_mixin.to_row( + [('numero', 6), + ('ano', 6)]) + + row2 = crispy_layout_mixin.to_row( + [('inicial', 6), + ('final', 6)]) + + row3 = crispy_layout_mixin.to_row( + [('tipo_documento', 4), + ('tipo_protocolo', 4), + ('tipo_materia', 4)]) + + row4 = crispy_layout_mixin.to_row( + [('interessado', 6), + ('assunto_ementa', 6)]) + + row5 = crispy_layout_mixin.to_row( + [('autor', 0), + (Button('pesquisar', + 'Pesquisar Autor', + css_class='btn btn-primary btn-sm'), 2), + (Button('limpar', + 'Limpar Autor', + css_class='btn btn-primary btn-sm'), 10)]) + + self.helper = FormHelper() + self.form.helper.form_method = 'GET' + self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'), + row1, row2, + row3, row4, + HTML(sapl.utils.autor_label), + HTML(sapl.utils.autor_modal), + row5, + form_actions(save_label='Pesquisar'))) class AnularProcoloAdmForm(ModelForm): diff --git a/protocoloadm/views.py b/protocoloadm/views.py index c4b3e8b2a..ba73e1783 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -63,12 +63,6 @@ class ProtocoloPesquisaView(FormView): request.POST['inicial'], '%d/%m/%Y').strftime('%Y-%m-%d') - # if request.POST['final']: - # kwargs['final'] = request.POST['final'] - - if request.POST['natureza_processo']: - kwargs['tipo_protocolo'] = request.POST['natureza_processo'] - if request.POST['tipo_documento']: kwargs['tipo_documento'] = request.POST['tipo_documento'] From 79a8a4d72e29a70569cf79542e2d818f0f76b0db Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Tue, 19 Apr 2016 13:45:11 -0300 Subject: [PATCH 02/11] Implementa maior parte da pesquisa de Protocolo --- protocoloadm/forms.py | 94 ++++---------------- protocoloadm/views.py | 83 +++++++++-------- sapl/settings.py | 2 + templates/paginacao_pesquisa_materia.html | 37 ++++++++ templates/protocoloadm/protocolo_filter.html | 66 ++++++++++++++ 5 files changed, 169 insertions(+), 113 deletions(-) create mode 100644 templates/paginacao_pesquisa_materia.html create mode 100644 templates/protocoloadm/protocolo_filter.html diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index dbaecf63f..c27a56f8c 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -1,5 +1,3 @@ -from datetime import date - from crispy_forms.bootstrap import InlineRadios from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Field, Fieldset, Layout, Submit @@ -14,7 +12,7 @@ import sapl import django_filters from crispy_layout_mixin import form_actions -from materia.models import Autor, TipoMateriaLegislativa +from materia.models import Autor from sapl.utils import RANGE_ANOS from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo, @@ -31,67 +29,6 @@ NATUREZA_PROCESSO = [('0', 'Administrativo'), ANO_CHOICES = [('', '---------')] + RANGE_ANOS -# class ProtocoloForm(forms.Form): - -# YEARS = get_range_anos() - -# tipo_protocolo = forms.ChoiceField(required=False, -# label='Tipo de Protocolo', -# choices=TIPOS_PROTOCOLO, -# widget=forms.Select( -# attrs={'class': 'selector'})) - -# numero_protocolo = forms.CharField( -# label='Número de Protocolo', required=False) - -# ano = forms.ChoiceField(required=False, -# label='Ano', -# choices=YEARS, -# widget=forms.Select( -# attrs={'class': 'selector'})) - -# inicial = forms.DateField(label='Data Inicial', -# required=False, -# widget=forms.TextInput( -# attrs={'class': 'dateinput'})) - -# final = forms.DateField(label='Data Final', required=False, -# widget=forms.TextInput( -# attrs={'class': 'dateinput'})) - -# natureza_processo = forms.ChoiceField(required=False, -# label='Natureza Processo', -# choices=[ -# ('0', 'Administrativo'), -# ('1', 'Legislativo'), -# ('', 'Ambos')]) - -# tipo_documento = forms.ModelChoiceField( -# label='Tipo de Documento', -# required=False, -# queryset=TipoDocumentoAdministrativo.objects.all(), -# empty_label='Selecione', -# ) - -# interessado = forms.CharField(label='Interessado', required=False) - -# tipo_materia = forms.ModelChoiceField( -# label='Tipo de Matéria', -# required=False, -# queryset=TipoMateriaLegislativa.objects.all(), -# empty_label='Selecione', -# ) - -# autor = forms.CharField(widget=forms.HiddenInput(), required=False) - -# assunto = forms.CharField(label='Assunto', required=False) - -# def __init__(self, *args, **kwargs): - -# super(ProtocoloForm, self).__init__( -# *args, **kwargs) - - # Importar essa classe de materias.views quando for feito o Merge do branch 217 class RangeWidgetOverride(forms.MultiWidget): @@ -118,14 +55,13 @@ class ProtocoloFilterSet(django_filters.FilterSet): filter_overrides = {models.DateField: { 'filter_class': django_filters.DateFromToRangeFilter, 'extra': lambda f: { - 'label': '%s (%s)' % (f.verbose_name, _('Inicial - Final')), + 'label': 'Data (%s)' % (_('Inicial - Final')), 'widget': RangeWidgetOverride} }} ano = django_filters.ChoiceFilter(required=False, label=u'Ano da Matéria', - choices=ANO_CHOICES, - help_text="") + choices=ANO_CHOICES) assunto_ementa = django_filters.CharFilter(lookup_expr='icontains') @@ -136,7 +72,7 @@ class ProtocoloFilterSet(django_filters.FilterSet): fields = ['tipo_protocolo', 'numero', 'tipo_documento', - 'data_publicacao', + 'data', 'tipo_materia', 'autor' ] @@ -171,8 +107,7 @@ class ProtocoloFilterSet(django_filters.FilterSet): ('ano', 6)]) row2 = crispy_layout_mixin.to_row( - [('inicial', 6), - ('final', 6)]) + [('data', 12)]) row3 = crispy_layout_mixin.to_row( [('tipo_documento', 4), @@ -191,16 +126,19 @@ class ProtocoloFilterSet(django_filters.FilterSet): (Button('limpar', 'Limpar Autor', css_class='btn btn-primary btn-sm'), 10)]) + row6 = crispy_layout_mixin.to_row( + [('o', 12)]) - self.helper = FormHelper() + self.form.helper = FormHelper() self.form.helper.form_method = 'GET' - self.helper.layout = Layout(Fieldset(_('Pesquisar Protocolo'), - row1, row2, - row3, row4, - HTML(sapl.utils.autor_label), - HTML(sapl.utils.autor_modal), - row5, - form_actions(save_label='Pesquisar'))) + self.form.helper.layout = Layout(Fieldset(_( + 'Pesquisar Protocolo'), + row1, row2, + row3, row4, + HTML(sapl.utils.autor_label), + HTML(sapl.utils.autor_modal), + row5, row6, + form_actions(save_label='Pesquisar'))) class AnularProcoloAdmForm(ModelForm): diff --git a/protocoloadm/views.py b/protocoloadm/views.py index ba73e1783..fe10a7628 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -9,6 +9,7 @@ from django.shortcuts import redirect from django.utils.translation import ugettext_lazy as _ from django.views.generic import CreateView, DetailView, FormView, ListView from django.views.generic.base import TemplateView +from django_filters.views import FilterView from crud.base import Crud, make_pagination from materia.models import Proposicao, TipoMateriaLegislativa @@ -16,8 +17,8 @@ from sapl.utils import create_barcode, get_client_ip from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoForm, ProposicaoSimpleForm, - ProtocoloDocumentForm, ProtocoloForm, ProtocoloMateriaForm, - TramitacaoAdmForm) + ProtocoloDocumentForm, ProtocoloFilterSet, + ProtocoloMateriaForm, TramitacaoAdmForm) from .models import (Autor, DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, StatusTramitacaoAdministrativo, @@ -37,51 +38,63 @@ ProtocoloDocumentoCrud = Crud.build(Protocolo, '') ProtocoloMateriaCrud = Crud.build(Protocolo, '') -class ProtocoloPesquisaView(FormView): - template_name = 'protocoloadm/protocolo_pesquisa.html' - form_class = ProtocoloForm - context_object_name = 'protocolos' - success_url = reverse_lazy('protocoloadm:protocolo') +class ProtocoloPesquisaView(FilterView): + model = Protocolo + filterset_class = ProtocoloFilterSet + paginate_by = 10 - def post(self, request, *args, **kwargs): - form = ProtocoloForm(request.POST or None) + def get_filterset_kwargs(self, filterset_class): + super(ProtocoloPesquisaView, + self).get_filterset_kwargs(filterset_class) - if form.is_valid(): - kwargs = {} + kwargs = {'data': self.request.GET or None} + + qs = self.get_queryset() - if request.POST['tipo_protocolo']: - kwargs['tipo_protocolo'] = request.POST['tipo_protocolo'] + qs = qs.distinct() - if request.POST['numero_protocolo']: - kwargs['numero'] = request.POST['numero_protocolo'] + kwargs.update({ + 'queryset': qs, + }) + return kwargs - if request.POST['ano']: - kwargs['ano'] = request.POST['ano'] + def get_context_data(self, **kwargs): + context = super(ProtocoloPesquisaView, + self).get_context_data(**kwargs) - if request.POST['inicial']: - kwargs['data'] = datetime.strptime( - request.POST['inicial'], - '%d/%m/%Y').strftime('%Y-%m-%d') + paginator = context['paginator'] + page_obj = context['page_obj'] - if request.POST['tipo_documento']: - kwargs['tipo_documento'] = request.POST['tipo_documento'] + context['page_range'] = make_pagination( + page_obj.number, paginator.num_pages) - if request.POST['interessado']: - kwargs['interessado__icontains'] = request.POST['interessado'] + return context - if request.POST['tipo_materia']: - kwargs['tipo_materia'] = request.POST['tipo_materia'] + def get(self, request, *args, **kwargs): + super(ProtocoloPesquisaView, self).get(request) + + # Se a pesquisa estiver quebrando com a paginação + # Olhe esta função abaixo + # Provavelmente você criou um novo campo no Form/FilterSet + # Então a ordem da URL está diferente + data = self.filterset.data + if (data and data.get('numero') is not None): + url = "&"+str(self.request.environ['QUERY_STRING']) + if url[:5] == "&page": + ponto_comeco = url.find('numero=') - 1 + url = url[ponto_comeco:] + else: + url = '' - if request.POST['autor']: - kwargs['autor'] = request.POST['autor'] + self.filterset.form.fields['o'].label = _('Ordenação') - if request.POST['assunto']: - kwargs['assunto_ementa__icontains'] = request.POST['assunto'] + context = self.get_context_data(filter=self.filterset, + object_list=self.object_list, + filter_url=url, + numero_res=len(self.object_list) + ) - request.session['kwargs'] = kwargs - return redirect('protocoloadm:protocolo_list') - else: - return self.form_invalid(form) + return self.render_to_response(context) class ProtocoloListView(ListView): diff --git a/sapl/settings.py b/sapl/settings.py index e0d02f524..1a1869b12 100644 --- a/sapl/settings.py +++ b/sapl/settings.py @@ -187,3 +187,5 @@ SASS_PROCESSOR_INCLUDE_DIRS = (BOWER_COMPONENTS_ROOT.child( # hack to suppress many annoying warnings from crispy_forms # see sapl.temp_suppress_crispy_form_warnings LOGGING = SUPRESS_CRISPY_FORM_WARNINGS_LOGGING + +FILTERS_HELP_TEXT_FILTER = False diff --git a/templates/paginacao_pesquisa_materia.html b/templates/paginacao_pesquisa_materia.html new file mode 100644 index 000000000..f82dcd48a --- /dev/null +++ b/templates/paginacao_pesquisa_materia.html @@ -0,0 +1,37 @@ +{% if is_paginated %} + +{% endif %} \ No newline at end of file diff --git a/templates/protocoloadm/protocolo_filter.html b/templates/protocoloadm/protocolo_filter.html new file mode 100644 index 000000000..6e84f4381 --- /dev/null +++ b/templates/protocoloadm/protocolo_filter.html @@ -0,0 +1,66 @@ +{% extends "protocoloadm/protocoloadm_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} +{% load static %} +{% block actions %}{% endblock %} + +{% block sections_nav %} {% endblock %} + +{% block detail_content %} +

Pesquisar Protocolo

+

+ + {% crispy filter.form %} + +

+ + + + + {% if page_obj|length %} + {% if filter_url %} +

Pesquisa concluída com sucesso! Foram encontrados {{numero_res}} protocolos.

+ {% endif %} + {% for p in page_obj %} + + + + {% endfor %} + {% else %} + + + {% endif %} + +

Resultados

+ Protocolo: + + {{ p.numero|stringformat:'06d' }}/{{ p.ano }} + +   -   + + + Etiqueta Individual +
+ + Assunto: {{ p.assunto_ementa }}
+ + Data Protocolo: {{ p.data|date:"d/m/Y" }} - Horário: {{ p.timestamp|date:"H:m:s" }}
+ + Interessado: {{ p.interessado }}
+ + Natureza do Processo: + {% if p.tipo_processo == 0 %} + Administrativo + {% elif p.tipo_processo == 1 %} + Matéria Legislativa + {% endif %}
+ + Classificação: {{ p.tipo_documento }}
+

+
+

Nenhum protocolo encontrado com essas especificações

+
+ +{% include "paginacao_pesquisa_materia.html" %} + +{% endblock detail_content %} \ No newline at end of file From 91c913774d99855a30dcfb597bd572d815174dcd Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 20 Apr 2016 11:39:32 -0300 Subject: [PATCH 03/11] Finaliza a funcionalidade e o layout da Pesquisa de Protocolo --- protocoloadm/forms.py | 114 ++++++++++--------- templates/protocoloadm/protocolo_filter.html | 12 +- 2 files changed, 66 insertions(+), 60 deletions(-) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index c27a56f8c..52bb4dc6c 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -67,6 +67,8 @@ class ProtocoloFilterSet(django_filters.FilterSet): interessado = django_filters.CharFilter(lookup_expr='icontains') + autor = django_filters.CharFilter(widget=forms.HiddenInput()) + class Meta: model = Protocolo fields = ['tipo_protocolo', @@ -74,7 +76,6 @@ class ProtocoloFilterSet(django_filters.FilterSet): 'tipo_documento', 'data', 'tipo_materia', - 'autor' ] order_by = ( @@ -83,62 +84,63 @@ class ProtocoloFilterSet(django_filters.FilterSet): ('DEC', 'Ordem Decrescente'), ) - order_by_mapping = { - '': [], - 'CRE': ['ano', 'numero'], - 'DEC': ['-ano', '-numero'], - } + order_by_mapping = { + '': [], + 'CRE': ['ano', 'numero'], + 'DEC': ['-ano', '-numero'], + } + + def get_order_by(self, order_value): + if order_value in self.order_by_mapping: + return self.order_by_mapping[order_value] + else: + return super(ProtocoloFilterSet, + self).get_order_by(order_value) + + def __init__(self, *args, **kwargs): + super(ProtocoloFilterSet, self).__init__(*args, **kwargs) + + self.filters['autor'].label = 'Tipo de Matéria' + self.filters['assunto_ementa'].label = 'Assunto' + + row1 = crispy_layout_mixin.to_row( + [('numero', 6), + ('ano', 6)]) - def get_order_by(self, order_value): - if order_value in self.order_by_mapping: - return self.order_by_mapping[order_value] - else: - return super(ProtocoloFilterSet, - self).get_order_by(order_value) - - def __init__(self, *args, **kwargs): - super(ProtocoloFilterSet, self).__init__(*args, **kwargs) - - self.filters['autor'].label = 'Tipo de Matéria' - self.filters['assunto_ementa'].label = 'Assunto' - - row1 = crispy_layout_mixin.to_row( - [('numero', 6), - ('ano', 6)]) - - row2 = crispy_layout_mixin.to_row( - [('data', 12)]) - - row3 = crispy_layout_mixin.to_row( - [('tipo_documento', 4), - ('tipo_protocolo', 4), - ('tipo_materia', 4)]) - - row4 = crispy_layout_mixin.to_row( - [('interessado', 6), - ('assunto_ementa', 6)]) - - row5 = crispy_layout_mixin.to_row( - [('autor', 0), - (Button('pesquisar', - 'Pesquisar Autor', - css_class='btn btn-primary btn-sm'), 2), - (Button('limpar', - 'Limpar Autor', - css_class='btn btn-primary btn-sm'), 10)]) - row6 = crispy_layout_mixin.to_row( - [('o', 12)]) - - self.form.helper = FormHelper() - self.form.helper.form_method = 'GET' - self.form.helper.layout = Layout(Fieldset(_( - 'Pesquisar Protocolo'), - row1, row2, - row3, row4, - HTML(sapl.utils.autor_label), - HTML(sapl.utils.autor_modal), - row5, row6, - form_actions(save_label='Pesquisar'))) + row2 = crispy_layout_mixin.to_row( + [('data', 12)]) + + row3 = crispy_layout_mixin.to_row( + [('tipo_documento', 4), + ('tipo_protocolo', 4), + ('tipo_materia', 4)]) + + row4 = crispy_layout_mixin.to_row( + [('interessado', 6), + ('assunto_ementa', 6)]) + + row5 = crispy_layout_mixin.to_row( + [('autor', 0), + (Button('pesquisar', + 'Pesquisar Autor', + css_class='btn btn-primary btn-sm'), 2), + (Button('limpar', + 'Limpar Autor', + css_class='btn btn-primary btn-sm'), 10)]) + row6 = crispy_layout_mixin.to_row( + [('o', 12)]) + + self.form.helper = FormHelper() + self.form.helper.form_method = 'GET' + self.form.helper.layout = Layout( + Fieldset(_('Pesquisar Protocolo'), + row1, row2, + row3, row4, + HTML(sapl.utils.autor_label), + HTML(sapl.utils.autor_modal), + row5, row6, + form_actions(save_label='Pesquisar')) + ) class AnularProcoloAdmForm(ModelForm): diff --git a/templates/protocoloadm/protocolo_filter.html b/templates/protocoloadm/protocolo_filter.html index 6e84f4381..ed9219c67 100644 --- a/templates/protocoloadm/protocolo_filter.html +++ b/templates/protocoloadm/protocolo_filter.html @@ -19,7 +19,11 @@ {% if page_obj|length %} {% if filter_url %} -

Pesquisa concluída com sucesso! Foram encontrados {{numero_res}} protocolos.

+ {% if numero_res > 1 %} +

Pesquisa concluída com sucesso! Foram encontrados {{numero_res}} protocolos.

+ {% elif numero_res == 1 %} +

Pesquisa concluída com sucesso! Foi encontrado {{numero_res}} protocolo.

+ {% endif %} {% endif %} {% for p in page_obj %} @@ -34,9 +38,9 @@ Etiqueta Individual
- Assunto: {{ p.assunto_ementa }}
+ Assunto: {{ p.assunto_ementa|default_if_none:"Não Informado"}}
- Data Protocolo: {{ p.data|date:"d/m/Y" }} - Horário: {{ p.timestamp|date:"H:m:s" }}
+ Data Protocolo: {{ p.data|date:"d/m/Y"|default_if_none:"Não Informado" }} - Horário: {{ p.timestamp|date:"H:m:s" }}
Interessado: {{ p.interessado }}
@@ -47,7 +51,7 @@ Matéria Legislativa {% endif %}
- Classificação: {{ p.tipo_documento }}
+ Classificação: {{ p.tipo_documento|default_if_none:"Não Informado" }}

From 47ed37e3e0d360cf75052ce64d940d437959d15f Mon Sep 17 00:00:00 2001 From: Eduardo Calil Date: Wed, 20 Apr 2016 12:33:50 -0300 Subject: [PATCH 04/11] Finaliza os detalhes adicionais da tela e resolve alguns bugs --- protocoloadm/forms.py | 18 +++++----- protocoloadm/views.py | 2 +- templates/paginacao.html | 6 ++-- templates/paginacao_pesquisa_materia.html | 37 -------------------- templates/protocoloadm/protocolo_filter.html | 8 ++--- 5 files changed, 16 insertions(+), 55 deletions(-) delete mode 100644 templates/paginacao_pesquisa_materia.html diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index 52bb4dc6c..dc65e9589 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -104,22 +104,20 @@ class ProtocoloFilterSet(django_filters.FilterSet): self.filters['assunto_ementa'].label = 'Assunto' row1 = crispy_layout_mixin.to_row( - [('numero', 6), - ('ano', 6)]) + [('numero', 4), + ('ano', 4), + ('data', 4)]) row2 = crispy_layout_mixin.to_row( - [('data', 12)]) - - row3 = crispy_layout_mixin.to_row( [('tipo_documento', 4), ('tipo_protocolo', 4), ('tipo_materia', 4)]) - row4 = crispy_layout_mixin.to_row( + row3 = crispy_layout_mixin.to_row( [('interessado', 6), ('assunto_ementa', 6)]) - row5 = crispy_layout_mixin.to_row( + row4 = crispy_layout_mixin.to_row( [('autor', 0), (Button('pesquisar', 'Pesquisar Autor', @@ -127,7 +125,7 @@ class ProtocoloFilterSet(django_filters.FilterSet): (Button('limpar', 'Limpar Autor', css_class='btn btn-primary btn-sm'), 10)]) - row6 = crispy_layout_mixin.to_row( + row5 = crispy_layout_mixin.to_row( [('o', 12)]) self.form.helper = FormHelper() @@ -135,10 +133,10 @@ class ProtocoloFilterSet(django_filters.FilterSet): self.form.helper.layout = Layout( Fieldset(_('Pesquisar Protocolo'), row1, row2, - row3, row4, + row3, HTML(sapl.utils.autor_label), HTML(sapl.utils.autor_modal), - row5, row6, + row4, row5, form_actions(save_label='Pesquisar')) ) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index fe10a7628..7bdf59fe2 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -80,7 +80,7 @@ class ProtocoloPesquisaView(FilterView): data = self.filterset.data if (data and data.get('numero') is not None): url = "&"+str(self.request.environ['QUERY_STRING']) - if url[:5] == "&page": + if url.startswith("&page"): ponto_comeco = url.find('numero=') - 1 url = url[ponto_comeco:] else: diff --git a/templates/paginacao.html b/templates/paginacao.html index 1092432ac..7bb7db04b 100644 --- a/templates/paginacao.html +++ b/templates/paginacao.html @@ -3,7 +3,7 @@