From 04c8cd6ee6f19e897ca844b7aefff11dd774b8a1 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Fri, 6 Nov 2015 15:24:55 -0200 Subject: [PATCH] Add pagination to Pesquisa Protocolo --- protocoloadm/views.py | 34 ++++++++----------- templates/protocoloadm/protocolo_list.html | 8 +++-- .../protocoloadm/protocolo_pesquisa.html | 25 -------------- 3 files changed, 21 insertions(+), 46 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 1b2a312e9..dc6b1bdce 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -127,14 +127,6 @@ TIPOS_PROTOCOLO = [('', 'Selecione'), ('0', 'Enviado'), ('1', 'Recebido')] - -class ProtocoloListView(ListView): - template_name = 'protocoloadm/protocolo_list.html' - context_object_name = 'protocolos' - model = Protocolo - paginate_by = 10 - - class ProtocoloForm(forms.Form): YEARS = get_range_anos() @@ -180,6 +172,16 @@ class ProtocoloForm(forms.Form): autor = forms.CharField(label='Autor', required=False) assunto = forms.CharField(label='Assunto', required=False) +class ProtocoloListView(FormMixin, ListView): + template_name = 'protocoloadm/protocolo_list.html' + context_object_name = 'protocolos' + model = Protocolo + paginate_by = 10 + + def get_queryset(self): + kwargs = self.request.session['kwargs'] + return Protocolo.objects.filter( + **kwargs) class ProtocoloPesquisaView(FormMixin, GenericView): template_name = 'protocoloadm/protocolo_pesquisa.html' @@ -244,16 +246,9 @@ class ProtocoloPesquisaView(FormMixin, GenericView): if request.POST['assunto']: kwargs['assunto'] = request.POST['assunto'] - protocolos = Protocolo.objects.filter( - **kwargs) - - self.extra_context['protocolos'] = protocolos - self.extra_context['form'] = form - - # return self.form_valid(form) - return self.render_to_response( - {'protocolos': protocolos} - ) + request.session['kwargs'] = kwargs + from django.shortcuts import redirect + return redirect('protocolo_list') else: return self.form_invalid(form) @@ -909,6 +904,7 @@ class TramitacaoAdmEditView(FormMixin, GenericView): def post(self, request, *args, **kwargs): pk = kwargs['pk'] + print(kwargs) tramitacao = TramitacaoAdministrativo.objects.get(id=pk) form = TramitacaoAdmForm(request.POST, instance=tramitacao) @@ -917,7 +913,7 @@ class TramitacaoAdmEditView(FormMixin, GenericView): tramitacao.ultima = False tramitacao.save() return HttpResponseRedirect( - reverse('tramitacao', kwargs={'pk': pk})) + reverse('tramitacao', kwargs={'pk': tramitacao.documento.id})) else: return self.form_invalid(form) diff --git a/templates/protocoloadm/protocolo_list.html b/templates/protocoloadm/protocolo_list.html index 3dd07a07d..cc7b6e400 100644 --- a/templates/protocoloadm/protocolo_list.html +++ b/templates/protocoloadm/protocolo_list.html @@ -3,7 +3,8 @@ {% load crispy_forms_tags %} {% block detail_content %} - Total: {{ protocolos|length }} + {% if protocolos %} + @@ -21,4 +22,7 @@ {% endfor %}
Número de Protocolo Assunto
{% include "paginacao.html" %} -{% endblock detail_content %} + {% else %} +

Nenhum Registro recuperado

+ {% endif %} +{% endblock detail_content %} \ No newline at end of file diff --git a/templates/protocoloadm/protocolo_pesquisa.html b/templates/protocoloadm/protocolo_pesquisa.html index e85470fe0..7fd0d9b5c 100644 --- a/templates/protocoloadm/protocolo_pesquisa.html +++ b/templates/protocoloadm/protocolo_pesquisa.html @@ -3,30 +3,6 @@ {% load crispy_forms_tags %} {% block detail_content %} - {% if protocolos %} -
- {% csrf_token %} - Total: {{ protocolos|length }} - - - - - - - - - {% for p in protocolos %} - - - - - - - {% endfor %} -
Número de ProtocoloAnoAssuntoTipo de DocumentoData
{{ p.numero }}{{ p.ano }}{{ p.assunto_ementa }}{{ p.tipo_documento }}{{ p.data|date:"d/m/Y" }}
- {% include "paginacao.html" %} -
- {% else %}
{% csrf_token %}
@@ -35,7 +11,6 @@
- {% endif %} {% endblock detail_content %} {% block foot_js %}