Browse Source

Cria tela para vincular um documento ao protocolo

pull/222/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
ff8833b8e7
  1. 100
      protocoloadm/forms.py
  2. 5
      protocoloadm/urls.py
  3. 63
      protocoloadm/views.py
  4. 7
      templates/protocoloadm/criar_documento.html
  5. 6
      templates/protocoloadm/protocolo_mostrar.html

100
protocoloadm/forms.py

@ -1,17 +1,17 @@
from datetime import date from datetime import date
import sapl
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Field, Fieldset, Layout from crispy_forms.layout import HTML, Field, Fieldset, Layout
from django import forms from django import forms
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
import sapl
from materia.models import TipoMateriaLegislativa from materia.models import TipoMateriaLegislativa
from sapl.layout import form_actions from sapl.layout import form_actions
from .models import (Autor, DocumentoAcessorioAdministrativo, from .models import (Autor, DocumentoAcessorioAdministrativo,
TipoDocumentoAdministrativo, TramitacaoAdministrativo) DocumentoAdministrativo, TipoDocumentoAdministrativo,
TramitacaoAdministrativo)
def get_range_anos(): def get_range_anos():
@ -19,6 +19,12 @@ def get_range_anos():
+ [(year, year) for year in range(date.today().year, 1960, -1)] + [(year, year) for year in range(date.today().year, 1960, -1)]
def tramitacao():
return [('', '--------'),
(True, 'Sim'),
(False, 'Não')]
TIPOS_PROTOCOLO = [('', 'Selecione'), TIPOS_PROTOCOLO = [('', 'Selecione'),
('0', 'Enviado'), ('0', 'Enviado'),
('1', 'Recebido')] ('1', 'Recebido')]
@ -408,3 +414,91 @@ class TramitacaoAdmForm(ModelForm):
) )
super(TramitacaoAdmForm, self).__init__( super(TramitacaoAdmForm, self).__init__(
*args, **kwargs) *args, **kwargs)
class DocumentoAdministrativoForm(ModelForm):
data = forms.DateField(label=u'Data',
input_formats=['%d/%m/%Y'],
required=False,
widget=forms.DateInput(
format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
data_fim_prazo = forms.DateField(label=u'Data Fim Prazo',
input_formats=['%d/%m/%Y'],
required=False,
widget=forms.DateInput(
format='%d/%m/%Y',
attrs={'class': 'dateinput'}))
tramitacao = forms.ChoiceField(required=True,
label='Em Tramitação?',
choices=tramitacao(),
widget=forms.Select(
attrs={'class': 'selector'}))
assunto = forms.CharField(
label='Descrição', required=False,
widget=forms.Textarea())
observacao = forms.CharField(
label='Descrição', required=False,
widget=forms.Textarea())
class Meta:
model = DocumentoAdministrativo
fields = ['tipo',
'numero',
'ano',
'data',
'numero_protocolo',
'assunto',
'interessado',
'tramitacao',
'dias_prazo',
'data_fim_prazo',
'observacao',
'texto_integral'
]
def __init__(self, *args, **kwargs):
row1 = sapl.layout.to_row(
[('tipo', 4),
('numero', 4),
('ano', 4)])
row2 = sapl.layout.to_row(
[('data', 6),
('numero_protocolo', 6)])
row3 = sapl.layout.to_row(
[('assunto', 12)])
row4 = sapl.layout.to_row(
[('interessado', 9),
('tramitacao', 3)])
row5 = sapl.layout.to_row(
[('texto_integral', 12)])
row6 = sapl.layout.to_row(
[('dias_prazo', 6),
('data_fim_prazo', 6)])
row7 = sapl.layout.to_row(
[('observacao', 12)])
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset('Formulário de Cadastro',
Fieldset('Identificação Básica',
row1, row2, row3, row4, row5),
Fieldset('Outras Informações',
row6, row7),
form_actions(),
),
)
super(DocumentoAdministrativoForm, self).__init__(
*args, **kwargs)

5
protocoloadm/urls.py

@ -20,7 +20,8 @@ from protocoloadm.views import (AnularProtocoloAdmView,
protocolo_materia_crud, protocolo_materia_crud,
status_tramitacao_administrativo_crud, status_tramitacao_administrativo_crud,
tipo_documento_administrativo_crud, tipo_documento_administrativo_crud,
tramitacao_administrativo_crud) tramitacao_administrativo_crud,
CriarDocumentoProtocolo)
urlpatterns = [ urlpatterns = [
url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)), url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)),
@ -66,6 +67,8 @@ urlpatterns = [
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/comprovante$', url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/comprovante$',
ComprovanteProtocoloView.as_view(), name='comprovante_protocolo'), ComprovanteProtocoloView.as_view(), name='comprovante_protocolo'),
url(r'^protocoloadm/(?P<pk>\d+)/(?P<ano>\d+)/criar_documento$',
CriarDocumentoProtocolo.as_view(), name='criar_documento'),
# TODO: move to Proposicoes app # TODO: move to Proposicoes app

63
protocoloadm/views.py

@ -1,6 +1,7 @@
from datetime import date, datetime from datetime import date, datetime
from re import sub from re import sub
import sapl
from django import forms from django import forms
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse from django.core.urlresolvers import reverse
@ -12,16 +13,15 @@ from django.utils.translation import ugettext_lazy as _
from django.views.generic import DetailView, ListView from django.views.generic import DetailView, ListView
from django.views.generic.base import TemplateView from django.views.generic.base import TemplateView
from django.views.generic.edit import FormMixin from django.views.generic.edit import FormMixin
from vanilla import GenericView
import sapl
from materia.models import Proposicao, TipoMateriaLegislativa from materia.models import Proposicao, TipoMateriaLegislativa
from sapl.crud import build_crud from sapl.crud import build_crud
from sapl.utils import create_barcode from sapl.utils import create_barcode
from vanilla import GenericView
from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm,
ProposicaoSimpleForm, ProtocoloDocumentForm, ProtocoloForm, DocumentoAdministrativoForm, ProposicaoSimpleForm,
ProtocoloMateriaForm, TramitacaoAdmForm) ProtocoloDocumentForm, ProtocoloForm, ProtocoloMateriaForm,
TramitacaoAdmForm)
from .models import (Autor, DocumentoAcessorioAdministrativo, from .models import (Autor, DocumentoAcessorioAdministrativo,
DocumentoAdministrativo, Protocolo, DocumentoAdministrativo, Protocolo,
StatusTramitacaoAdministrativo, StatusTramitacaoAdministrativo,
@ -303,6 +303,59 @@ class ProtocoloDocumentoView(FormMixin, GenericView):
return self.form_invalid(form) return self.form_invalid(form)
def criar_documento(protocolo):
doc = {}
numero = Protocolo.objects.filter(
tipo_documento=protocolo.tipo_documento,
ano=protocolo.ano,
anulado=False).aggregate(Max('numero'))
doc['tipo'] = protocolo.tipo_documento
doc['ano'] = protocolo.ano
doc['data'] = protocolo.data
doc['numero_protocolo'] = protocolo.numero
doc['assunto'] = protocolo.assunto_ementa
doc['interessado'] = protocolo.interessado
doc['numero'] = numero['numero__max']
if doc['numero'] is None:
doc['numero'] = 1
return doc
class CriarDocumentoProtocolo(FormMixin, GenericView):
template_name = "protocoloadm/criar_documento.html"
def get(self, request, *args, **kwargs):
numero = self.kwargs['pk']
ano = self.kwargs['ano']
protocolo = Protocolo.objects.get(ano=ano, numero=numero)
form = DocumentoAdministrativoForm(
initial=criar_documento(protocolo))
return self.render_to_response({
'protocolo': protocolo,
'form': form})
def post(self, request, *args, **kwargs):
form = DocumentoAdministrativoForm(request.POST)
if form.is_valid():
doc = form.save(commit=False)
if 'texto_integral' in request.FILES:
doc.texto_integral = request.FILES['texto_integral']
doc.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form})
def get_success_url(self):
return reverse('criar_documento', kwargs={
'pk': self.kwargs['pk'],
'ano': self.kwargs['ano']})
class ProtocoloMostrarView(TemplateView): class ProtocoloMostrarView(TemplateView):
template_name = "protocoloadm/protocolo_mostrar.html" template_name = "protocoloadm/protocolo_mostrar.html"

7
templates/protocoloadm/criar_documento.html

@ -0,0 +1,7 @@
{% extends "crud/form.html" %}
{% load i18n %}
{% load crispy_forms_tags %}
{% block detail_content %}
{% endblock detail_content %}

6
templates/protocoloadm/protocolo_mostrar.html

@ -16,8 +16,8 @@
<br /> <br />
<strong>Documento Vinculado:</strong></br> <strong>Documento Vinculado:</strong></br>
<a href="" class="secondary button">Criar Documento</a> <a href="{% url 'criar_documento' protocolo.numero protocolo.ano %}" class="btn btn-primary">Criar Documento</a>
<br /> &nbsp;&nbsp;&nbsp;&nbsp;
<a href="{% url 'comprovante_protocolo' protocolo.numero protocolo.ano %}" target="popup" onclick="window.open('{% url 'comprovante_protocolo' protocolo.numero protocolo.ano %}','Comprovante','width=800, height=600')">Comprovante <a href="{% url 'comprovante_protocolo' protocolo.numero protocolo.ano %}" target="popup" class="btn btn-primary" onclick="window.open('{% url 'comprovante_protocolo' protocolo.numero protocolo.ano %}','Comprovante','width=800, height=600')">Comprovante
</a> </a>
{% endblock detail_content %} {% endblock detail_content %}
Loading…
Cancel
Save