Browse Source

Refactor PesquisaProtocolo

pull/11/merge
Edward Ribeiro 9 years ago
parent
commit
3f14e07d66
  1. 5
      protocoloadm/urls.py
  2. 86
      protocoloadm/views.py
  3. 55
      templates/protocoloadm/protocolo_list.html
  4. 66
      templates/protocoloadm/protocolo_pesquisa.html
  5. 2
      templates/protocoloadm/protocoloadm_detail.html

5
protocoloadm/urls.py

@ -1,6 +1,7 @@
from django.conf.urls import include, url
from protocoloadm.views import (AnularProtocoloAdmView, ProtocoloPesquisaView,
ProtocoloListView,
documento_acessorio_administrativo_crud,
documento_administrativo_crud,
protocolo_documento_crud,
@ -25,6 +26,10 @@ urlpatterns = [
url(r'^protocoloadm/protocolo$',
ProtocoloPesquisaView.as_view(), name='protocolo'),
url(r'^protocoloadm/protocolo_list$',
ProtocoloListView.as_view(), name='protocolo_list'),
# url(r'^protocoloadm/anular-protocolo/',
# include(anular_protocolo_crud.urls), name='anular_protocolo'),
url(r'^protocoloadm/anular-protocolo',

86
protocoloadm/views.py

@ -1,11 +1,11 @@
from datetime import datetime
from datetime import date, datetime
from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.shortcuts import render
from django.utils.html import strip_tags
from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView
from django.views.generic.base import TemplateView
from django.views.generic.edit import FormMixin
@ -96,26 +96,74 @@ protocolo_materia_crud = build_crud(
# [('justificativa_anulacao', 12)]],
# ])
def get_tipos_materia():
return [('', 'Selecione')] + [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoMateriaLegislativa.objects.all()]
def get_range_anos():
return [('', 'Selecione')] + [(year, year)
for year in range(date.today().year, 1960, -1)]
def get_tipos_documento():
return [('', 'Selecione')] + [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoDocumentoAdministrativo.objects.all()]
class ProtocoloListView(ListView):
template_name = 'protocoloadm/protocolo_list.html'
context_object_name = 'protocolos'
model = Protocolo
paginate_by = 10
class ProtocoloForm(forms.Form):
tipo_protocolo = forms.CharField(label='Tipo de Protocolo', required=False)
TIPOS_PROTOCOLO = [('', 'Selecione'),
('0', 'Enviado'),
('1', 'Recebido')]
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.CharField(label='Ano', required=False)
inicial = forms.DateField(label='Data Inicial', required=False)
final = forms.DateField(label='Data Final', 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.CharField(
label='Natureza Processo', required=False)
tipo_documento = forms.CharField(label='Tipo de Documento', required=False)
tipo_documento = forms.ChoiceField(required=False,
label='Tipo de Documento',
choices=get_tipos_documento(),
widget=forms.Select(
attrs={'class': 'selector'}))
interessado = forms.CharField(label='Interessado', required=False)
tipo_materia = forms.CharField(label='Tipo de Matéria', required=False)
tipo_materia = forms.ChoiceField(required=False,
label='Tipo Matéria',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
autor = forms.CharField(label='Autor', required=False)
assunto = forms.CharField(label='Assunto', required=False)
class ProtocoloPesquisaView(TemplateView, FormMixin):
template_name = 'protocoloadm/protocolo_pesquisa.html'
form_class = ProtocoloForm
form_class = ProtocoloForm()
context_object_name = 'protocolos'
paginate_by = 10
@ -124,6 +172,10 @@ class ProtocoloPesquisaView(TemplateView, FormMixin):
def get_success_url(self):
return reverse('protocolo')
def get(self, request, *args, **kwargs):
form = ProtocoloForm()
return self.render_to_response({'form': form})
def get_form(self, data=None, files=None, **kwargs):
return ProtocoloForm()
@ -132,19 +184,10 @@ class ProtocoloPesquisaView(TemplateView, FormMixin):
context.update(self.extra_context)
return context
def get_tipo_documento(self):
return TipoDocumentoAdministrativo.objects.all()
def get_tipo_materia(self):
return TipoMateriaLegislativa.objects.all()
def post(self, request, *args, **kwargs):
form = ProtocoloForm(request.POST or None)
if form.is_valid():
if "nova-pesquisa" in request.POST:
return self.render_to_response({})
else:
kwargs = {}
# format = '%Y-%m-%d'
@ -197,13 +240,12 @@ class ProtocoloPesquisaView(TemplateView, FormMixin):
class AnularProcoloAdmForm(forms.Form):
from datetime import date
YEARS = [(year, year) for year in range(date.today().year, 1960, -1)]
YEARS = get_range_anos()
numero_protocolo = forms.CharField(
label='Número de Protocolo', required=True)
ano_protocolo = forms.ChoiceField(required=False,
label="Year",
label='Ano',
choices=YEARS,
widget=forms.Select(
attrs={'class': 'selector'}))

55
templates/protocoloadm/protocolo_list.html

@ -0,0 +1,55 @@
{% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
Total: {{ protocolos|length }}
<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>
{% 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 %}
{% for page in paginator.page_range %}
<li {% if page == page_obj.number %}class="active current"{% endif %}>
<a href="?page={{ page }}">{{ page }}</a>
</li>
{% endfor %}
{% if page_obj.has_next %}
<li>
<a href="?page={{ page_obj.next_page_number }}">
<span class="arrow">&raquo;</span>
</a>
</li>
{% else %}
<li class="arrow unavailable"><a href="">&raquo;</a></li>
{% endif %}
</ul>
</nav>
{% endif %}
{% endblock detail_content %}

66
templates/protocoloadm/protocolo_pesquisa.html

@ -55,77 +55,13 @@
</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 />
{{ form.as_p }}
<input type="submit" value="Pesquisar" name="pesquisa" class="button primary"/>
</fieldset>
</form>

2
templates/protocoloadm/protocoloadm_detail.html

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

Loading…
Cancel
Save