Browse Source

Add pagination to Pesquisa Protocolo

pull/11/merge
Edward Ribeiro 9 years ago
parent
commit
04c8cd6ee6
  1. 34
      protocoloadm/views.py
  2. 6
      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'), ('0', 'Enviado'),
('1', 'Recebido')] ('1', 'Recebido')]
class ProtocoloListView(ListView):
template_name = 'protocoloadm/protocolo_list.html'
context_object_name = 'protocolos'
model = Protocolo
paginate_by = 10
class ProtocoloForm(forms.Form): class ProtocoloForm(forms.Form):
YEARS = get_range_anos() YEARS = get_range_anos()
@ -180,6 +172,16 @@ class ProtocoloForm(forms.Form):
autor = forms.CharField(label='Autor', required=False) autor = forms.CharField(label='Autor', required=False)
assunto = forms.CharField(label='Assunto', 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): class ProtocoloPesquisaView(FormMixin, GenericView):
template_name = 'protocoloadm/protocolo_pesquisa.html' template_name = 'protocoloadm/protocolo_pesquisa.html'
@ -244,16 +246,9 @@ class ProtocoloPesquisaView(FormMixin, GenericView):
if request.POST['assunto']: if request.POST['assunto']:
kwargs['assunto'] = request.POST['assunto'] kwargs['assunto'] = request.POST['assunto']
protocolos = Protocolo.objects.filter( request.session['kwargs'] = kwargs
**kwargs) from django.shortcuts import redirect
return redirect('protocolo_list')
self.extra_context['protocolos'] = protocolos
self.extra_context['form'] = form
# return self.form_valid(form)
return self.render_to_response(
{'protocolos': protocolos}
)
else: else:
return self.form_invalid(form) return self.form_invalid(form)
@ -909,6 +904,7 @@ class TramitacaoAdmEditView(FormMixin, GenericView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
pk = kwargs['pk'] pk = kwargs['pk']
print(kwargs)
tramitacao = TramitacaoAdministrativo.objects.get(id=pk) tramitacao = TramitacaoAdministrativo.objects.get(id=pk)
form = TramitacaoAdmForm(request.POST, instance=tramitacao) form = TramitacaoAdmForm(request.POST, instance=tramitacao)
@ -917,7 +913,7 @@ class TramitacaoAdmEditView(FormMixin, GenericView):
tramitacao.ultima = False tramitacao.ultima = False
tramitacao.save() tramitacao.save()
return HttpResponseRedirect( return HttpResponseRedirect(
reverse('tramitacao', kwargs={'pk': pk})) reverse('tramitacao', kwargs={'pk': tramitacao.documento.id}))
else: else:
return self.form_invalid(form) return self.form_invalid(form)

6
templates/protocoloadm/protocolo_list.html

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

25
templates/protocoloadm/protocolo_pesquisa.html

@ -3,30 +3,6 @@
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block detail_content %} {% 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"> <form method="post">
{% csrf_token %} {% csrf_token %}
<fieldset> <fieldset>
@ -35,7 +11,6 @@
<input type="submit" value="Pesquisar" name="pesquisa" class="button primary"/> <input type="submit" value="Pesquisar" name="pesquisa" class="button primary"/>
</fieldset> </fieldset>
</form> </form>
{% endif %}
{% endblock detail_content %} {% endblock detail_content %}
{% block foot_js %} {% block foot_js %}

Loading…
Cancel
Save