diff --git a/materia/views.py b/materia/views.py index f8da6faec..cfce6e8cd 100644 --- a/materia/views.py +++ b/materia/views.py @@ -775,7 +775,6 @@ class DocumentoAcessorioEditView(FormMixin, GenericView): form = DocumentoAcessorioForm(request.POST) materia = MateriaLegislativa.objects.get(id=kwargs['pk']) documento = DocumentoAcessorio.objects.get(id=kwargs['id']) - if form.is_valid(): if 'excluir' in request.POST: documento.delete() diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index f60ce6ed3..4942a0e71 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -1,7 +1,7 @@ from datetime import date from crispy_forms.helper import FormHelper -from crispy_forms.layout import HTML, Field, Fieldset, Layout +from crispy_forms.layout import HTML, Field, Fieldset, Layout, Submit from django import forms from django.forms import ModelForm from django.utils.safestring import mark_safe @@ -11,7 +11,8 @@ from materia.models import TipoMateriaLegislativa from sapl.layout import form_actions from .models import (Autor, DocumentoAcessorioAdministrativo, - TipoDocumentoAdministrativo, TramitacaoAdministrativo) + DocumentoAdministrativo, TipoDocumentoAdministrativo, + TramitacaoAdministrativo) def get_range_anos(): @@ -19,6 +20,12 @@ def get_range_anos(): + [(year, year) for year in range(date.today().year, 1960, -1)] +def tramitacao(): + return [('', '--------'), + (True, 'Sim'), + (False, 'Não')] + + TIPOS_PROTOCOLO = [('', 'Selecione'), ('0', 'Enviado'), ('1', 'Recebido')] @@ -82,14 +89,14 @@ class ProtocoloForm(forms.Form): required=False, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione', - ) + ) autor = forms.ModelChoiceField( label='Autor', required=False, queryset=Autor.objects.all().order_by('tipo'), empty_label='Selecione', - ) + ) assunto = forms.CharField(label='Assunto', required=False) @@ -248,7 +255,7 @@ class ProtocoloMateriaForm(forms.Form): required=False, queryset=TipoMateriaLegislativa.objects.all(), empty_label='Selecione', - ) + ) num_paginas = forms.CharField(label='Núm. Páginas', required=True) ementa = forms.CharField( @@ -259,7 +266,7 @@ class ProtocoloMateriaForm(forms.Form): required=False, queryset=Autor.objects.all().order_by('tipo'), empty_label='Selecione', - ) + ) observacao = forms.CharField(required=True, widget=forms.Textarea, @@ -339,18 +346,29 @@ class DocumentoAcessorioAdministrativoForm(ModelForm): 'arquivo', 'assunto'] - def __init__(self, *args, **kwargs): + def __init__(self, excluir=False, *args, **kwargs): + + row1 = sapl.layout.to_row( + [('tipo', 4), + ('nome', 4), + ('data', 4)]) + row2 = sapl.layout.to_row( + [('autor', 12)]) + row3 = sapl.layout.to_row( + [('arquivo', 12)]) + row4 = sapl.layout.to_row( + [('assunto', 12)]) + + more = [] + if excluir: + more = [Submit('Excluir', 'Excluir')] + self.helper = FormHelper() self.helper.layout = Layout( Fieldset( 'Incluir Documento Acessório', - 'tipo', - 'nome', - 'data', - 'autor', - 'arquivo', - 'assunto', - form_actions() + row1, row2, row3, row4, + form_actions(more=more) ) ) super(DocumentoAcessorioAdministrativoForm, self).__init__( @@ -408,3 +426,56 @@ class TramitacaoAdmForm(ModelForm): ) super(TramitacaoAdmForm, self).__init__( *args, **kwargs) + + +class DocumentoAdministrativoForm(ModelForm): + + 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('Identificação Básica', + row1, row2, row3, row4, row5), + Fieldset('Outras Informações', + row6, row7), + form_actions(more=[Submit('Excluir', 'Excluir')]), + ) + super(DocumentoAdministrativoForm, self).__init__( + *args, **kwargs) diff --git a/protocoloadm/migrations/0007_auto_20160218_1429.py b/protocoloadm/migrations/0007_auto_20160218_1429.py new file mode 100644 index 000000000..51f753b83 --- /dev/null +++ b/protocoloadm/migrations/0007_auto_20160218_1429.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('protocoloadm', '0006_auto_20160216_1015'), + ] + + operations = [ + migrations.AlterField( + model_name='documentoadministrativo', + name='tramitacao', + field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], verbose_name='Em Tramitação?'), + ), + ] diff --git a/protocoloadm/models.py b/protocoloadm/models.py index 6dfe0733f..f660701a6 100644 --- a/protocoloadm/models.py +++ b/protocoloadm/models.py @@ -2,7 +2,8 @@ from django.db import models from django.utils.translation import ugettext_lazy as _ from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao -from sapl.utils import make_choices +from sapl.utils import YES_NO_CHOICES, make_choices +from uuid import uuid4 class TipoDocumentoAdministrativo(models.Model): @@ -17,12 +18,8 @@ class TipoDocumentoAdministrativo(models.Model): return self.descricao -def get_docadm_media_path(instance, subpath, filename): - return './docadm/%s/%s/%s' % (instance, subpath, filename) - - def texto_upload_path(instance, filename): - return get_docadm_media_path(instance, 'DocAdm', filename) + return '/'.join([instance._meta.model_name, str(uuid4()), filename]) class DocumentoAdministrativo(models.Model): @@ -40,7 +37,9 @@ class DocumentoAdministrativo(models.Model): blank=True, null=True, verbose_name=_('Dias Prazo')) data_fim_prazo = models.DateField( blank=True, null=True, verbose_name=_('Data Fim Prazo')) - tramitacao = models.BooleanField(verbose_name=_('Em Tramitação?')) + tramitacao = models.BooleanField( + verbose_name=_('Em Tramitação?'), + choices=YES_NO_CHOICES) assunto = models.TextField(verbose_name=_('Assunto')) observacao = models.TextField( blank=True, verbose_name=_('Observação')) diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index bc6d094d7..ac5c6b269 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -1,8 +1,9 @@ from django.conf.urls import include, url - from protocoloadm.views import (AnularProtocoloAdmView, ComprovanteProtocoloView, + CriarDocumentoProtocolo, DetailDocumentoAdministrativo, + DocumentoAcessorioAdministrativoEditView, DocumentoAcessorioAdministrativoView, PesquisarDocumentoAdministrativo, ProposicaoDetailView, ProposicaoReceberView, @@ -54,6 +55,9 @@ urlpatterns = [ DetailDocumentoAdministrativo.as_view(), name='detail_doc_adm'), url(r'^protocoloadm/doc-ace-adm/(?P\d+)', DocumentoAcessorioAdministrativoView.as_view(), name='doc_ace_adm'), + url(r'^protocoloadm/doc-ace-adm/edit/(?P\d+)/(?P\d+)', + DocumentoAcessorioAdministrativoEditView.as_view(), + name='doc_ace_adm_edit'), url(r'^protocoloadm/(?P\d+)/tramitacao$', TramitacaoAdmView.as_view(), name='tramitacao_adm'), @@ -66,6 +70,8 @@ urlpatterns = [ url(r'^protocoloadm/(?P\d+)/(?P\d+)/comprovante$', ComprovanteProtocoloView.as_view(), name='comprovante_protocolo'), + url(r'^protocoloadm/(?P\d+)/(?P\d+)/criar_documento$', + CriarDocumentoProtocolo.as_view(), name='criar_documento'), # TODO: move to Proposicoes app diff --git a/protocoloadm/views.py b/protocoloadm/views.py index ec973d092..70c2836cd 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -9,7 +9,7 @@ from django.http import HttpResponseRedirect from django.shortcuts import redirect from django.utils.html import strip_tags from django.utils.translation import ugettext_lazy as _ -from django.views.generic import DetailView, ListView +from django.views.generic import CreateView, DetailView, ListView from django.views.generic.base import TemplateView from django.views.generic.edit import FormMixin from vanilla import GenericView @@ -19,8 +19,9 @@ from materia.models import Proposicao, TipoMateriaLegislativa from sapl.utils import create_barcode from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, - ProposicaoSimpleForm, ProtocoloDocumentForm, ProtocoloForm, - ProtocoloMateriaForm, TramitacaoAdmForm) + DocumentoAdministrativoForm, ProposicaoSimpleForm, + ProtocoloDocumentForm, ProtocoloForm, ProtocoloMateriaForm, + TramitacaoAdmForm) from .models import (Autor, DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, StatusTramitacaoAdministrativo, @@ -302,6 +303,41 @@ class ProtocoloDocumentoView(FormMixin, GenericView): 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(CreateView): + template_name = "protocoloadm/criar_documento.html" + form_class = DocumentoAdministrativoForm + + def get_initial(self): + numero = self.kwargs['pk'] + ano = self.kwargs['ano'] + protocolo = Protocolo.objects.get(ano=ano, numero=numero) + return criar_documento(protocolo) + + def get_success_url(self): + return reverse('detail_doc_adm', kwargs={'pk': self.object.pk}) + + class ProtocoloMostrarView(TemplateView): template_name = "protocoloadm/protocolo_mostrar.html" @@ -516,63 +552,88 @@ class PesquisarDocumentoAdministrativo(TemplateView): class DetailDocumentoAdministrativo(DetailView): template_name = "protocoloadm/detail_doc_adm.html" - def get_tipos_doc(self): - return TipoDocumentoAdministrativo.objects.all() - def get(self, request, *args, **kwargs): - doc = DocumentoAdministrativo.objects.get(id=kwargs['pk']) + documento = DocumentoAdministrativo.objects.get( + id=self.kwargs['pk']) + + form = DocumentoAdministrativoForm( + instance=documento) return self.render_to_response({ - 'pk': kwargs['pk'], - 'doc': doc, - 'tipos_doc': TipoDocumentoAdministrativo.objects.all() - }) + 'form': form, + 'pk': kwargs['pk']}) def post(self, request, *args, **kwargs): - if 'Salvar' in request.POST: - documento = DocumentoAdministrativo.objects.get(id=kwargs['pk']) - - if request.POST['numero']: - documento.numero = request.POST['numero'] + form = DocumentoAdministrativoForm(request.POST) - if request.POST['ano']: - documento.ano = request.POST['ano'] - - if request.POST['data']: - documento.data = datetime.strptime( - request.POST['data'], "%d/%m/%Y") + 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}) + elif 'Excluir' in request.POST: + DocumentoAdministrativo.objects.get( + id=kwargs['pk']).delete() + return HttpResponseRedirect(self.get_success_delete()) - if request.POST['numero_protocolo']: - documento.numero_protocolo = request.POST['numero_protocolo'] + return HttpResponseRedirect(self.get_success_url()) - if request.POST['assunto']: - documento.assunto = request.POST['assunto'] + def get_success_delete(self): + return reverse('pesq_doc_adm') - if request.POST['interessado']: - documento.interessado = request.POST['interessado'] + def get_success_url(self): + return reverse('detail_doc_adm', kwargs={ + 'pk': self.kwargs['pk']}) - if request.POST['tramitacao']: - documento.tramitacao = request.POST['tramitacao'] - if request.POST['dias_prazo']: - documento.dias_prazo = request.POST['dias_prazo'] +class DocumentoAcessorioAdministrativoEditView(FormMixin, GenericView): + template_name = "protocoloadm/documento_acessorio_administrativo_edit.html" - if request.POST['data_fim_prazo']: - documento.data_fim_prazo = datetime.strptime( - request.POST['data_fim_prazo'], "%d/%m/%Y") + def get(self, request, *args, **kwargs): + doc = DocumentoAdministrativo.objects.get( + id=kwargs['pk']) + doc_ace = DocumentoAcessorioAdministrativo.objects.get( + id=kwargs['ano']) + form = DocumentoAcessorioAdministrativoForm(instance=doc_ace, + excluir=True) - if request.POST['observacao']: - documento.observacao = request.POST['observacao'] + return self.render_to_response({'pk': self.kwargs['pk'], + 'doc': doc, + 'doc_ace': doc_ace, + 'form': form}) - documento.save() - elif 'Excluir' in request.POST: - DocumentoAdministrativo.objects.get( - id=kwargs['pk']).delete() + def post(self, request, *args, **kwargs): + form = DocumentoAcessorioAdministrativoForm(request.POST, excluir=True) + doc_ace = DocumentoAcessorioAdministrativo.objects.get( + id=kwargs['ano']) - return HttpResponseRedirect(self.get_success_url()) + if form.is_valid(): + if 'Salvar' in request.POST: + if 'arquivo' in request.FILES: + doc_ace.arquivo = request.FILES['arquivo'] + doc_ace.documento = DocumentoAdministrativo.objects.get( + id=kwargs['pk']) + doc_ace.tipo = TipoDocumentoAdministrativo.objects.get( + id=form.data['tipo']) + doc_ace.nome = form.data['nome'] + doc_ace.autor = form.data['autor'] + doc_ace.data = datetime.strptime( + form.data['data'], '%d/%m/%Y') + doc_ace.assunto = form.data['assunto'] + + doc_ace.save() + elif 'Excluir' in request.POST: + doc_ace.delete() + return self.form_valid(form) + else: + return self.form_invalid(form) def get_success_url(self): - return reverse('pesq_doc_adm') + pk = self.kwargs['pk'] + return reverse('doc_ace_adm', kwargs={'pk': pk}) class DocumentoAcessorioAdministrativoView(FormMixin, GenericView): @@ -583,10 +644,9 @@ class DocumentoAcessorioAdministrativoView(FormMixin, GenericView): doc = DocumentoAdministrativo.objects.get( id=kwargs['pk']) doc_ace_null = '' - try: - doc_acessorio = DocumentoAcessorioAdministrativo.objects.filter( - documento_id=kwargs['pk']) - except ObjectDoesNotExist: + doc_acessorio = DocumentoAcessorioAdministrativo.objects.filter( + documento_id=kwargs['pk']) + if not doc_acessorio: doc_ace_null = 'Nenhum documento acessório \ cadastrado para este processo.' @@ -599,17 +659,13 @@ class DocumentoAcessorioAdministrativoView(FormMixin, GenericView): def post(self, request, *args, **kwargs): form = DocumentoAcessorioAdministrativoForm(request.POST) if form.is_valid(): - doc_acessorio = DocumentoAcessorioAdministrativo() - doc_acessorio.tipo = form.cleaned_data['tipo'] - doc_acessorio.nome = form.cleaned_data['nome'] - doc_acessorio.data = form.cleaned_data['data'] - doc_acessorio.autor = form.cleaned_data['autor'] - doc_acessorio.assunto = form.cleaned_data['assunto'] - doc_acessorio.arquivo = request.FILES['arquivo'] - doc_acessorio.documento = DocumentoAdministrativo.objects.get( + doc_ace = form.save(commit=False) + if 'arquivo' in request.FILES: + doc_ace.arquivo = request.FILES['arquivo'] + doc = DocumentoAdministrativo.objects.get( id=kwargs['pk']) - doc_acessorio.save() - + doc_ace.documento = doc + doc_ace.save() return self.form_valid(form) else: return self.form_invalid(form) diff --git a/templates/protocoloadm/detail_doc_adm.html b/templates/protocoloadm/detail_doc_adm.html index e615cc3e8..baf9e5c8c 100644 --- a/templates/protocoloadm/detail_doc_adm.html +++ b/templates/protocoloadm/detail_doc_adm.html @@ -3,77 +3,5 @@ {% load crispy_forms_tags %} {% block detail_content %} -
- Formulário de Cadastro -
- {% csrf_token %} -
- Identificação Básica -
-
Tipo Documento
-
Número
-
Ano
-
-
-
- -
-
-
-
-
-
Data
-
Núm. Protocolo
-
-
-
-
-
-
-
Assunto
-
-
-
-
-
-
Interessado
-
Em Tramitação?
-
-
-
-
- -
-
-
-
- Outras Informações -
-
Dias Prazo
-
Data Fim Prazo
-
-
-
-
-
-
-
Obervação
-
-
-
-
-
- - -
-
+ {% crispy form %} {% endblock %} \ No newline at end of file diff --git a/templates/protocoloadm/detail_doc_detail.html b/templates/protocoloadm/detail_doc_detail.html index 59c9ac660..daa96a778 100644 --- a/templates/protocoloadm/detail_doc_detail.html +++ b/templates/protocoloadm/detail_doc_detail.html @@ -1,10 +1,10 @@ {% extends "crud/detail.html" %} {% load i18n %} - +{% block actions %} {% endblock %} {% block sections_nav %} - + {% endblock sections_nav %} diff --git a/templates/protocoloadm/documento_acessorio_administrativo.html b/templates/protocoloadm/documento_acessorio_administrativo.html index d143ac8af..2b1f9010e 100644 --- a/templates/protocoloadm/documento_acessorio_administrativo.html +++ b/templates/protocoloadm/documento_acessorio_administrativo.html @@ -5,36 +5,39 @@ {% block detail_content %}
Documento Administrativo -
-
Tipo: {{doc.tipo.sigla}}
-
Número: {{doc.numero}}
-
Ano: {{doc.ano}}
-
+
+
Tipo: {{doc.tipo.sigla}}
+
Número: {{doc.numero}}
+
Ano: {{doc.ano}}
+
Assunto: {{doc.assunto}} - +

Documentos Acessórios - {{ doc_ace_null }} - - - - - - - - - {% for d in doc_ace %} + {% if not doc_ace_null %} +
DocumentoNomeTipoDataAutor
- - - - - + + + + + - {% endfor %} -
{{d.arquivo}}{{d.nome}}{{d.tipo.descricao}}{{d.data|date:"d/m/Y"}}{{d.autor}}DocumentoNomeTipoDataAutor
+ {% for d in doc_ace %} + + {{d.arquivo}} + {{d.nome}} + {{d.tipo.descricao}} + {{d.data|date:"d/m/Y"}} + {{d.autor}} + + {% endfor %} + + {% else %} + {{ doc_ace_null }} + {% endif %}
- +

{% crispy form %}
{% endblock %} \ No newline at end of file diff --git a/templates/protocoloadm/documento_acessorio_administrativo_edit.html b/templates/protocoloadm/documento_acessorio_administrativo_edit.html new file mode 100644 index 000000000..5583cd34c --- /dev/null +++ b/templates/protocoloadm/documento_acessorio_administrativo_edit.html @@ -0,0 +1,7 @@ +{% extends "protocoloadm/detail_doc_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} + {% crispy form %} +{% endblock %} \ No newline at end of file diff --git a/templates/protocoloadm/protocolo_mostrar.html b/templates/protocoloadm/protocolo_mostrar.html index 284ed988d..4a01bfc7e 100644 --- a/templates/protocoloadm/protocolo_mostrar.html +++ b/templates/protocoloadm/protocolo_mostrar.html @@ -16,8 +16,8 @@
Documento Vinculado:
- Criar Documento -
- Comprovante + Criar Documento +      + Comprovante {% endblock detail_content %} \ No newline at end of file