Browse Source

Add pagination to Pesquisa Protocolo

pull/11/merge
Edward Ribeiro 9 years ago
parent
commit
04c8cd6ee6
  1. 34
      protocoloadm/views.py
  2. 8
      templates/protocoloadm/protocolo_list.html
  3. 25
      templates/protocoloadm/protocolo_pesquisa.html

34
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)

8
templates/protocoloadm/protocolo_list.html

@ -3,7 +3,8 @@
{% load crispy_forms_tags %}
{% block detail_content %}
Total: {{ protocolos|length }}
{% if protocolos %}
<!-- Total: {{ protocolos|length }} -->
<table>
<tr><td>Número de Protocolo</td>
<td>Assunto</td>
@ -21,4 +22,7 @@
{% endfor %}
</table>
{% include "paginacao.html" %}
{% endblock detail_content %}
{% else %}
<h2>Nenhum Registro recuperado</h2>
{% endif %}
{% endblock detail_content %}

25
templates/protocoloadm/protocolo_pesquisa.html

@ -3,30 +3,6 @@
{% load crispy_forms_tags %}
{% block detail_content %}
{% if protocolos %}
<form method="POST">
{% csrf_token %}
Total: {{ protocolos|length }}
<table>
<tr><td>Número de Protocolo</td>
<td>Ano</td>
<td>Assunto</td>
<td>Tipo de Documento</td>
<td>Data</td>
</tr>
{% for p in protocolos %}
<tr><td>{{ p.numero }}</td>
<td>{{ p.ano }}</td>
<td>{{ p.assunto_ementa }}</td>
<td>{{ p.tipo_documento }}</td>
<td>{{ p.data|date:"d/m/Y" }}</td>
</tr>
{% endfor %}
</table>
{% include "paginacao.html" %}
</form>
{% else %}
<form method="post">
{% csrf_token %}
<fieldset>
@ -35,7 +11,6 @@
<input type="submit" value="Pesquisar" name="pesquisa" class="button primary"/>
</fieldset>
</form>
{% endif %}
{% endblock detail_content %}
{% block foot_js %}

Loading…
Cancel
Save