Browse Source

Implement search Protocolo

pull/7/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
99e460c581
  1. 2
      protocoloadm/urls.py
  2. 94
      protocoloadm/views.py
  3. 230
      templates/protocoloadm/protocolo_pesquisa.html
  4. 6
      templates/protocoloadm/protocolo_resultados.html
  5. 7
      templates/protocoloadm/protocoloadm_detail.html

2
protocoloadm/urls.py

@ -23,6 +23,6 @@ urlpatterns = [
url(r'^protocoloadm/protocolo-mat/', include(protocolo_materia_crud.urls)), url(r'^protocoloadm/protocolo-mat/', include(protocolo_materia_crud.urls)),
url(r'^protocoloadm/anular-protocolo/', url(r'^protocoloadm/anular-protocolo/',
include(anular_protocolo_crud.urls)), include(anular_protocolo_crud.urls)),
url(r'^protocoloadm/protocolo', url(r'^protocoloadm/protocolo$',
ProtocoloPesquisaView.as_view(), name='protocolo'), ProtocoloPesquisaView.as_view(), name='protocolo'),
] ]

94
protocoloadm/views.py

@ -3,8 +3,7 @@ from datetime import datetime
from django import forms from django import forms
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView from django.views.generic import ListView, TemplateView
from django.views.generic.edit import UpdateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from materia.models import TipoMateriaLegislativa from materia.models import TipoMateriaLegislativa
@ -97,11 +96,13 @@ anular_protocolo_crud = build_crud(
class ProtocoloForm(forms.Form): class ProtocoloForm(forms.Form):
tipo_protocolo = forms.CharField(label='Tipo de Protocolo', required=False) tipo_protocolo = forms.CharField(label='Tipo de Protocolo', required=False)
numero_protocolo = forms.CharField(label='Número de Protocolo', required=False) numero_protocolo = forms.CharField(
label='Número de Protocolo', required=False)
ano = forms.CharField(label='Ano', required=False) ano = forms.CharField(label='Ano', required=False)
inicial = forms.DateField(label='Data Inicial', required=False) inicial = forms.DateField(label='Data Inicial', required=False)
final = forms.DateField(label='Data Final', required=False) final = forms.DateField(label='Data Final', required=False)
natureza_processo = forms.CharField(label='Natureza Processo', required=False) natureza_processo = forms.CharField(
label='Natureza Processo', required=False)
tipo_documento = forms.CharField(label='Tipo de Documento', required=False) tipo_documento = forms.CharField(label='Tipo de Documento', required=False)
interessado = forms.CharField(label='Interessado', required=False) interessado = forms.CharField(label='Interessado', required=False)
tipo_materia = forms.CharField(label='Tipo de Matéria', required=False) tipo_materia = forms.CharField(label='Tipo de Matéria', required=False)
@ -109,10 +110,10 @@ class ProtocoloForm(forms.Form):
assunto = forms.CharField(label='Assunto <DFS', required=False) assunto = forms.CharField(label='Assunto <DFS', required=False)
class ProtocoloPesquisaView(FormMixin, ListView): class ProtocoloPesquisaView(TemplateView, FormMixin):
template_name = 'protocoloadm/protocolo_pesquisa.html' template_name = 'protocoloadm/protocolo_pesquisa.html'
form_class = ProtocoloForm form_class = ProtocoloForm
context_object_name = 'protocolos' context_object_name = 'protocolos'
paginate_by = 10 paginate_by = 10
extra_context = {} extra_context = {}
@ -121,8 +122,6 @@ class ProtocoloPesquisaView(FormMixin, ListView):
return reverse('protocolo') return reverse('protocolo')
def get_form(self, data=None, files=None, **kwargs): def get_form(self, data=None, files=None, **kwargs):
# kwargs['user'] = self.request.user
# return AccountForm(data, files, **kwargs)
return ProtocoloForm() return ProtocoloForm()
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
@ -130,71 +129,64 @@ class ProtocoloPesquisaView(FormMixin, ListView):
context.update(self.extra_context) context.update(self.extra_context)
return context return context
def get_queryset(self):
return Protocolo.objects.all()
def get_tipo_documento(self): def get_tipo_documento(self):
return TipoDocumentoAdministrativo.objects.all() return TipoDocumentoAdministrativo.objects.all()
def get_tipo_materia(self): def get_tipo_materia(self):
return TipoMateriaLegislativa.objects.all() return TipoMateriaLegislativa.objects.all()
# def get(self, request, *args, **kwargs):
# context = self.get_context_data(self)
# form = ProtocoloForm()
# # return self.render(request, self.template_name, {'form': form})
# context.update({'form': form})
# return self.render_to_response(context)
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
#form = self.get_form()
form = ProtocoloForm(request.POST or None) form = ProtocoloForm(request.POST or None)
if form.is_valid(): if form.is_valid():
kwargs = {} if "nova-pesquisa" in request.POST:
return self.render_to_response({})
else:
kwargs = {}
# format = '%Y-%m-%d' # format = '%Y-%m-%d'
if request.POST['tipo_protocolo']: if request.POST['tipo_protocolo']:
kwargs['tipo_protocolo'] = request.POST['tipo_protocolo'] kwargs['tipo_protocolo'] = request.POST['tipo_protocolo']
if request.POST['numero_protocolo']: if request.POST['numero_protocolo']:
kwargs['numero'] = request.POST['numero_protocolo'] kwargs['numero'] = request.POST['numero_protocolo']
if request.POST['ano']: if request.POST['ano']:
kwargs['ano'] = request.POST['ano'] kwargs['ano'] = request.POST['ano']
if request.POST['inicial']: if request.POST['inicial']:
kwargs['data'] = datetime.strptime( kwargs['data'] = datetime.strptime(
request.POST['inicial'], '%d/%m/%Y').strftime('%Y-%m-%d') request.POST['inicial'],
'%d/%m/%Y').strftime('%Y-%m-%d')
# if request.POST['final']: # if request.POST['final']:
# kwargs['final'] = request.POST['final'] # kwargs['final'] = request.POST['final']
if request.POST['tipo_documento']: if request.POST['tipo_documento']:
kwargs['tipo_documento'] = request.POST['tipo_documento'] kwargs['tipo_documento'] = request.POST['tipo_documento']
if request.POST['interessado']: if request.POST['interessado']:
kwargs['interessado'] = request.POST['interessado'] kwargs['interessado'] = request.POST['interessado']
if request.POST['tipo_materia']: if request.POST['tipo_materia']:
kwargs['tipo_materia'] = request.POST['tipo_materia'] kwargs['tipo_materia'] = request.POST['tipo_materia']
if request.POST['autor']: if request.POST['autor']:
kwargs['autor'] = request.POST['autor'] kwargs['autor'] = request.POST['autor']
if request.POST['assunto']: if request.POST['assunto']:
kwargs['assunto'] = request.POST['assunto'] kwargs['assunto'] = request.POST['assunto']
protocolos = Protocolo.objects.filter( protocolos = Protocolo.objects.filter(
**kwargs) **kwargs)
self.extra_context['protocolos'] = protocolos self.extra_context['protocolos'] = protocolos
self.extra_context['form'] = form self.extra_context['form'] = form
return self.form_valid(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)

230
templates/protocoloadm/protocolo_pesquisa.html

@ -3,115 +3,133 @@
{% load crispy_forms_tags %} {% load crispy_forms_tags %}
{% block detail_content %} {% block detail_content %}
<form method="post"> {% if protocolos %}
{% csrf_token %} <form method="POST">
<fieldset> {% csrf_token %}
<legend>Pesquisa Avançada</legend> Total: {{ protocolos|length }}
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Tipo Protocolo</li> <table>
<li> <tr><td>Número de Protocolo</td>
<select name="tipo_protocolo"> <td>Assunto</td>
<option value="">Selecione</option> <td>Tipo de Documento</td>
<option value="0">Enviado</option> <td>Ano</td>
<option value="1">Recebido</option> <td>Data</td>
</select>
</li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Número Protocolo</li>
<li><input type="text" name="numero_protocolo" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Ano</li>
<li><input type="text" name="ano" /></li>
</ul>
<ul class="small-block-grid-1 medium-block-grid-1 large-block-grid-1">
<li><b>Período Protocolo</b></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Inicial</li>
<li><input type="text" name="inicial" class="dateinput" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Final</li>
<li><input type="text" name="final" class="dateinput" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Tipo Documento</li>
<li>
<select name="tipo_documento">
<option value="">Selecione</option>
{% for tipo in view.get_tipo_documento %}
<option value="{{tipo.id}}">{{tipo.sigla}} - {{tipo.descricao}}</option>
{% endfor %}
</select>
</li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Interessado</li>
<li><input type="text" name="interessado" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Tipo Matéria</li>
<li>
<select name="tipo_materia">
<option value="">Selecione</option>
{% for tipo in view.get_tipo_materia %}
<option value="{{tipo.id}}">{{tipo.sigla}} - {{tipo.descricao}}</option>
{% endfor %}
</select>
</li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Autor</li>
<li><input type="text" name="autor" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Assunto</li>
<li><input type="text" name="assunto" /></li>
</ul>
<br />
<input type="submit" value="Pesquisar" class="button primary"/>
</fieldset>
<!--
{% if protocolos %}
<table>
<tr><td>Número de Protocolo</td>
<td>Assunto</td>
<td>Tipo de Documento</td>
<td>Ano</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> </tr>
{% endfor %} {% for p in protocolos %}
</table> <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>
{% if is_paginated %}
<nav class="pagination-centered">
<ul class="pagination">
{% if page_obj.has_previous %}
<li>
<a href="?page={{ page_obj.previous_page_number }}">
<span class="arrow">&laquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&laquo;</a></li>
{% endif %}
{% if is_paginated %} {% for page in paginator.page_range %}
<div class="pagination"> <li {% if page == page_obj.number %}class="active current"{% endif %}>
<span class="page-links"> <a href="?page={{ page }}">{{ page }}</a>
{% if page_obj.has_previous %} </li>
<a href="{% url 'protocolo' %}{?page={{ page_obj.previous_page_number }}"><<</a> {% endfor %}
{% endif %}
<span class="page-current">
Page {{ page_obj.number }} of {{ page_obj.paginator.num_pages }}.
</span>
{% if page_obj.has_next %}
<a href="{% url 'protocolo' %}/?page={{ page_obj.next_page_number }}">>></a>
{% endif %}
</span>
</div>
{% endif %}
Total: {{ protocolos|length }} {% if page_obj.has_next %}
{% endif %} <li>
--> <a href="?page={{ page_obj.next_page_number }}">
</form> <span class="arrow">&raquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
<input type="submit" value="Voltar" name="nova-pesquisa" class="button primary"/>
</form>
{% else %}
<form method="post">
{% csrf_token %}
<fieldset>
<legend>Pesquisa Avançada</legend>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Tipo Protocolo</li>
<li>
<select name="tipo_protocolo">
<option value="">Selecione</option>
<option value="0">Enviado</option>
<option value="1">Recebido</option>
</select>
</li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Número Protocolo</li>
<li><input type="text" name="numero_protocolo" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Ano</li>
<li><input type="text" name="ano" /></li>
</ul>
<ul class="small-block-grid-1 medium-block-grid-1 large-block-grid-1">
<li><b>Período Protocolo</b></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Inicial</li>
<li><input type="text" name="inicial" class="dateinput" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Final</li>
<li><input type="text" name="final" class="dateinput" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Tipo Documento</li>
<li>
<select name="tipo_documento">
<option value="">Selecione</option>
{% for tipo in view.get_tipo_documento %}
<option value="{{tipo.id}}">{{tipo.sigla}} - {{tipo.descricao}}</option>
{% endfor %}
</select>
</li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Interessado</li>
<li><input type="text" name="interessado" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Tipo Matéria</li>
<li>
<select name="tipo_materia">
<option value="">Selecione</option>
{% for tipo in view.get_tipo_materia %}
<option value="{{tipo.id}}">{{tipo.sigla}} - {{tipo.descricao}}</option>
{% endfor %}
</select>
</li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Autor</li>
<li><input type="text" name="autor" /></li>
</ul>
<ul class="small-block-grid-2 medium-block-grid-2 large-block-grid-2">
<li>Assunto</li>
<li><input type="text" name="assunto" /></li>
</ul>
<br />
<input type="submit" value="Pesquisar" name="pesquisa" class="button primary"/>
</fieldset>
</form>
{% endif %}
{% endblock detail_content %} {% endblock detail_content %}
{% block foot_js %} {% block foot_js %}

6
templates/protocoloadm/protocolo_resultados.html

@ -1,6 +0,0 @@
{% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
{% endblock detail_content %}

7
templates/protocoloadm/protocoloadm_detail.html

@ -3,8 +3,9 @@
{% block sections_nav %} {% block sections_nav %}
<dl class="sub-nav left"> <dl class="sub-nav left">
<dd><a href="" class="button secondary">{% trans 'Protocolar Documento' %}</a></dd> <dd><a href="./protocolo" class="button secondary">{% trans 'Inicio' %}</a></dd>
<dd><a href="" class="button secondary">{% trans 'Protocolar Matéria' %}</a></dd> <dd><a href="./protocolo-doc" class="button secondary">{% trans 'Protocolar Documento' %}</a></dd>
<dd><a href="" class="button secondary">{% trans 'Anular Protocolo' %}</a></dd> <dd><a href="./protocolo-mat" class="button secondary">{% trans 'Protocolar Matéria' %}</a></dd>
<dd><a href="./anular-protocolo" class="button secondary">{% trans 'Anular Protocolo' %}</a></dd>
</dl> </dl>
{% endblock sections_nav %} {% endblock sections_nav %}

Loading…
Cancel
Save