Browse Source

First pass at protocolo doc adm & materia

pull/11/merge
Edward Ribeiro 9 years ago
parent
commit
0b44e07067
  1. 17
      protocoloadm/urls.py
  2. 201
      protocoloadm/views.py
  3. 16
      templates/protocoloadm/protocolar_documento.html
  4. 16
      templates/protocoloadm/protocolar_materia.html
  5. 6
      templates/protocoloadm/protocoloadm_detail.html

17
protocoloadm/urls.py

@ -1,6 +1,7 @@
from django.conf.urls import include, url
from protocoloadm.views import (AnularProtocoloAdmView, ProtocoloListView,
from protocoloadm.views import (AnularProtocoloAdmView, ProtocoloDocumentoView,
ProtocoloListView, ProtocoloMateriaView,
ProtocoloPesquisaView,
documento_acessorio_administrativo_crud,
documento_administrativo_crud,
@ -22,16 +23,18 @@ urlpatterns = [
include(tramitacao_administrativo_crud.urls)),
url(r'^protocoloadm/protocolo-doc/',
include(protocolo_documento_crud.urls)),
url(r'^protocoloadm/protocolo-mat/', include(protocolo_materia_crud.urls)),
url(r'^protocoloadm/protocolo-mat/',
include(protocolo_materia_crud.urls), name='protocolomat'),
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/protocolo_list$',
ProtocoloListView.as_view(), name='protocolo_list'),
url(r'^protocoloadm/anular-protocolo',
AnularProtocoloAdmView.as_view(), name='anular_protocolo'),
url(r'^protocoloadm/protocolar-doc',
ProtocoloDocumentoView.as_view(), name='protocolar_doc'),
url(r'^protocoloadm/protocolar-mat',
ProtocoloMateriaView.as_view(), name='protocolar_mat')
]

201
protocoloadm/views.py

@ -1,10 +1,13 @@
from datetime import date, datetime
from re import sub
from django import forms
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Max
from django.shortcuts import render
from django.utils.html import strip_tags
from django.utils.safestring import mark_safe
from django.utils.translation import ugettext_lazy as _
from django.views.generic import ListView
from django.views.generic.base import TemplateView
@ -13,8 +16,9 @@ from django.views.generic.edit import FormMixin
from materia.models import TipoMateriaLegislativa
from sapl.crud import build_crud
from .models import (DocumentoAcessorioAdministrativo, DocumentoAdministrativo,
Protocolo, StatusTramitacaoAdministrativo,
from .models import (Autor, DocumentoAcessorioAdministrativo,
DocumentoAdministrativo, Protocolo,
StatusTramitacaoAdministrativo,
TipoDocumentoAdministrativo, TramitacaoAdministrativo)
tipo_documento_administrativo_crud = build_crud(
@ -100,19 +104,23 @@ protocolo_materia_crud = build_crud(
def get_tipos_materia():
return [('', 'Selecione')] \
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoMateriaLegislativa.objects.all()]
+ [(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)]
+ [(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()]
+ [(t.id, t.sigla + ' - ' + t.descricao)
for t in TipoDocumentoAdministrativo.objects.all()]
TIPOS_PROTOCOLO = [('', 'Selecione'),
('0', 'Enviado'),
('1', 'Recebido')]
class ProtocoloListView(ListView):
@ -124,10 +132,6 @@ class ProtocoloListView(ListView):
class ProtocoloForm(forms.Form):
TIPOS_PROTOCOLO = [('', 'Selecione'),
('0', 'Enviado'),
('1', 'Recebido')]
YEARS = get_range_anos()
tipo_protocolo = forms.ChoiceField(required=False,
@ -147,7 +151,7 @@ class ProtocoloForm(forms.Form):
inicial = forms.DateField(label='Data Inicial',
required=False,
widget=forms.TextInput(
attrs={'class': 'dateinput'}))
attrs={'class': 'dateinput'}))
final = forms.DateField(label='Data Final', required=False,
widget=forms.TextInput(
@ -291,8 +295,8 @@ class AnularProtocoloAdmView(FormMixin, TemplateView):
numero = request.POST['numero_protocolo']
ano = request.POST['ano_protocolo']
justificativa_anulacao = strip_tags(
request.POST['justificativa_anulacao'])
justificativa_anulacao = sub(' ', ' ', strip_tags(
request.POST['justificativa_anulacao']))
user_anulacao = "NOUSER" # TODO get user from session
ip_addr = get_client_ip(request)
@ -324,3 +328,172 @@ class AnularProtocoloAdmView(FormMixin, TemplateView):
return self.form_invalid(form)
else:
return self.form_invalid(form)
class HorizontalRadioRenderer(forms.RadioSelect.renderer):
def render(self):
return mark_safe(u' '.join([u'%s ' % w for w in self]))
class ProtocoloDocumentForm(forms.Form):
NUMERACAO_CHOICES = [('1', 'Sequencial por Ano'),
('2', 'Sequencial Único')]
numeracao = forms.ChoiceField(required=True,
choices=NUMERACAO_CHOICES,
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer),
label='')
tipo_protocolo = forms.ChoiceField(required=True,
label='Tipo de Protocolo',
choices=TIPOS_PROTOCOLO[1:],
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer))
tipo_documento = forms.ChoiceField(required=True,
label='Tipo de Documento',
choices=get_tipos_documento(),
widget=forms.Select(
attrs={'class': 'selector'}))
num_paginas = forms.CharField(label='Núm. Páginas', required=True)
assunto = forms.CharField(
widget=forms.Textarea, label='Assunto', required=True)
interessado = forms.CharField(required=True,
label='Interessado')
observacao = forms.CharField(required=True,
widget=forms.Textarea, label='Observação')
class ProtocoloDocumentoView(FormMixin, TemplateView):
template_name = "protocoloadm/protocolar_documento.html"
model = Protocolo
def get_success_url(self):
return reverse('protocolar_doc')
def get(self, request, *args, **kwargs):
form = ProtocoloDocumentForm()
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = ProtocoloDocumentForm(request.POST)
if form.is_valid():
if request.POST['numeracao'] == '1':
numeracao = Protocolo.objects.filter(
ano=date.today().year).aggregate(Max('numero'))
else:
numeracao = Protocolo.objects.all().aggregate(Max('numero'))
protocolo = Protocolo()
protocolo.numero = numeracao['numero__max'] + 1
protocolo.ano = datetime.now().year
protocolo.data = datetime.now().strftime("%Y-%m-%d")
protocolo.hora = datetime.now().strftime("%H:%M")
protocolo.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
protocolo.tipo_protocolo = request.POST['tipo_protocolo']
protocolo.tipo_processo = '0' # TODO validar o significado
protocolo.interessado = request.POST['interessado']
protocolo.anulado = False
protocolo.tipo_documento = TipoDocumentoAdministrativo.objects.get(
id=request.POST['tipo_documento'])
protocolo.assunto_ementa = sub(
' ', ' ', strip_tags(request.POST['assunto']))
protocolo.numero_paginas = request.POST['num_paginas']
protocolo.observacao = sub(
' ', ' ', strip_tags(request.POST['observacao']))
protocolo.save()
message = "Protocolo criado com sucesso"
return render(request,
reverse('protocolo'),
{'form': form, 'message': message})
else:
return self.form_invalid(form)
class ProtocoloMateriaForm(forms.Form):
NUMERACAO_CHOICES = [('1', 'Sequencial por Ano'),
('2', 'Sequencial Único')]
numeracao = forms.ChoiceField(required=True,
choices=NUMERACAO_CHOICES,
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer),
label='')
tipo_protocolo = forms.ChoiceField(required=True,
label='Tipo de Protocolo',
choices=TIPOS_PROTOCOLO[1:],
widget=forms.RadioSelect(
renderer=HorizontalRadioRenderer))
tipo_materia = forms.ChoiceField(required=False,
label='Tipo Matéria',
choices=get_tipos_materia(),
widget=forms.Select(
attrs={'class': 'selector'}))
num_paginas = forms.CharField(label='Núm. Páginas', required=True)
ementa = forms.CharField(
widget=forms.Textarea, label='Ementa', required=True)
autor = forms.CharField(label='Autor', required=True)
observacao = forms.CharField(required=True,
widget=forms.Textarea, label='Observação')
class ProtocoloMateriaView(FormMixin, TemplateView):
template_name = "protocoloadm/protocolar_materia.html"
model = Protocolo
def get(self, request, *args, **kwargs):
form = ProtocoloMateriaForm()
return self.render_to_response({'form': form})
def post(self, request, *args, **kwargs):
form = ProtocoloMateriaForm(request.POST)
if form.is_valid():
if request.POST['numeracao'] == '1':
numeracao = Protocolo.objects.filter(
ano=date.today().year).aggregate(Max('numero'))
else:
numeracao = Protocolo.objects.all().aggregate(Max('numero'))
protocolo = Protocolo()
protocolo.numero = numeracao['numero__max'] + 1
protocolo.ano = datetime.now().year
protocolo.data = datetime.now().strftime("%Y-%m-%d")
protocolo.hora = datetime.now().strftime("%H:%M")
protocolo.timestamp = datetime.now().strftime("%Y-%m-%d %H:%M")
protocolo.tipo_protocolo = request.POST['tipo_protocolo']
protocolo.tipo_processo = '0' # TODO validar o significado
protocolo.autor = Autor.objects.get(id=request.POST['autor'])
protocolo.anulado = False
protocolo.tipo_materia = TipoMateriaLegislativa.objects.get(
id=request.POST['tipo_materia'])
protocolo.numero_paginas = request.POST['num_paginas']
protocolo.observacao = sub(
' ', ' ', strip_tags(request.POST['observacao']))
protocolo.save()
message = "Protocolo criado com sucesso"
return render(request,
reverse('protocolo'),
{'form': form, 'message': message})
else:
return self.form_invalid(form)

16
templates/protocoloadm/protocolar_documento.html

@ -0,0 +1,16 @@
{% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
<form method="POST">
<fieldset>
Protocolo: Opção de Numeração
<br/>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Protocolar Documento" class="button primary" />
</fieldset>
</form>
{% endblock detail_content %}

16
templates/protocoloadm/protocolar_materia.html

@ -0,0 +1,16 @@
{% extends "protocoloadm/protocoloadm_detail.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
<form method="POST">
<fieldset>
Protocolo: Opção de Numeração
<br/>
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Protocolar Matéria" class="button primary" />
</fieldset>
</form>
{% endblock detail_content %}

6
templates/protocoloadm/protocoloadm_detail.html

@ -3,9 +3,9 @@
{% block sections_nav %}
<dl class="sub-nav left">
<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 'protocolo' %}" class="button secondary">{% trans 'Pesquisa Protocolo' %}</a></dd>
<dd><a href="{% url 'protocolar_doc' %}" class="button secondary">{% trans 'Protocolar Documento' %}</a></dd>
<dd><a href="{% url 'protocolar_mat' %}" class="button secondary">{% trans 'Protocolar Matéria' %}</a></dd>
<dd><a href="{% url 'anular_protocolo' %}" class="button secondary">{% trans 'Anular Protocolo' %}</a></dd>
</dl>
{% endblock sections_nav %}

Loading…
Cancel
Save