diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index dfe0de4ce..c886b54f0 100644 --- a/protocoloadm/urls.py +++ b/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') ] diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 26decd5a5..56878e85e 100644 --- a/protocoloadm/views.py +++ b/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) diff --git a/templates/protocoloadm/protocolar_documento.html b/templates/protocoloadm/protocolar_documento.html new file mode 100644 index 000000000..196bce254 --- /dev/null +++ b/templates/protocoloadm/protocolar_documento.html @@ -0,0 +1,16 @@ +{% extends "protocoloadm/protocoloadm_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} +
+ +{% endblock detail_content %} \ No newline at end of file diff --git a/templates/protocoloadm/protocolar_materia.html b/templates/protocoloadm/protocolar_materia.html new file mode 100644 index 000000000..c2fd0daf0 --- /dev/null +++ b/templates/protocoloadm/protocolar_materia.html @@ -0,0 +1,16 @@ +{% extends "protocoloadm/protocoloadm_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} + + +{% endblock detail_content %} \ No newline at end of file diff --git a/templates/protocoloadm/protocoloadm_detail.html b/templates/protocoloadm/protocoloadm_detail.html index 82b12e6bd..4ce1cab38 100644 --- a/templates/protocoloadm/protocoloadm_detail.html +++ b/templates/protocoloadm/protocoloadm_detail.html @@ -3,9 +3,9 @@ {% block sections_nav %}