From ff8833b8e7920b98e459bbd3529ccae92f361923 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 17 Feb 2016 10:49:21 -0200 Subject: [PATCH 1/8] Cria tela para vincular um documento ao protocolo --- protocoloadm/forms.py | 108 ++++++++++++++++-- protocoloadm/urls.py | 5 +- protocoloadm/views.py | 67 +++++++++-- templates/protocoloadm/criar_documento.html | 7 ++ templates/protocoloadm/protocolo_mostrar.html | 6 +- 5 files changed, 175 insertions(+), 18 deletions(-) create mode 100644 templates/protocoloadm/criar_documento.html diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index f60ce6ed3..e23a0475d 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -1,17 +1,17 @@ from datetime import date +import sapl from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Field, Fieldset, Layout from django import forms from django.forms import ModelForm from django.utils.safestring import mark_safe - -import sapl 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 +19,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 +88,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 +254,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 +265,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, @@ -408,3 +414,91 @@ class TramitacaoAdmForm(ModelForm): ) super(TramitacaoAdmForm, self).__init__( *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) diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index bc6d094d7..f19013a2d 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -20,7 +20,8 @@ from protocoloadm.views import (AnularProtocoloAdmView, protocolo_materia_crud, status_tramitacao_administrativo_crud, tipo_documento_administrativo_crud, - tramitacao_administrativo_crud) + tramitacao_administrativo_crud, + CriarDocumentoProtocolo) urlpatterns = [ url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)), @@ -66,6 +67,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 34156ac95..7f9792e47 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -1,6 +1,7 @@ from datetime import date, datetime from re import sub +import sapl from django import forms from django.core.exceptions import ObjectDoesNotExist 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.base import TemplateView from django.views.generic.edit import FormMixin -from vanilla import GenericView - -import sapl from materia.models import Proposicao, TipoMateriaLegislativa from sapl.crud import build_crud from sapl.utils import create_barcode +from vanilla import GenericView from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, - ProposicaoSimpleForm, ProtocoloDocumentForm, ProtocoloForm, - ProtocoloMateriaForm, TramitacaoAdmForm) + DocumentoAdministrativoForm, ProposicaoSimpleForm, + ProtocoloDocumentForm, ProtocoloForm, ProtocoloMateriaForm, + TramitacaoAdmForm) from .models import (Autor, DocumentoAcessorioAdministrativo, DocumentoAdministrativo, Protocolo, StatusTramitacaoAdministrativo, @@ -303,6 +303,59 @@ 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(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): template_name = "protocoloadm/protocolo_mostrar.html" @@ -331,8 +384,8 @@ class ComprovanteProtocoloView(TemplateView): if not protocolo.anulado: autenticacao = str(protocolo.tipo_processo) + \ - protocolo.data.strftime("%y/%m/%d") + \ - str(protocolo.numero).zfill(6) + protocolo.data.strftime("%y/%m/%d") + \ + str(protocolo.numero).zfill(6) return self.render_to_response({"protocolo": protocolo, "barcode": barcode, diff --git a/templates/protocoloadm/criar_documento.html b/templates/protocoloadm/criar_documento.html new file mode 100644 index 000000000..8deec35e0 --- /dev/null +++ b/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 %} \ 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 From 579c8d1bf158196f046f8d6c205ec1360a4b4930 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 17 Feb 2016 11:24:34 -0200 Subject: [PATCH 2/8] Refatora tela de documento administrativo --- protocoloadm/forms.py | 4 +- protocoloadm/views.py | 76 ++++++++----------- templates/protocoloadm/detail_doc_adm.html | 75 +----------------- templates/protocoloadm/detail_doc_detail.html | 12 +-- 4 files changed, 42 insertions(+), 125 deletions(-) diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index e23a0475d..68329a6c4 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -439,11 +439,11 @@ class DocumentoAdministrativoForm(ModelForm): attrs={'class': 'selector'})) assunto = forms.CharField( - label='Descrição', required=False, + label='Assunto', required=False, widget=forms.Textarea()) observacao = forms.CharField( - label='Descrição', required=False, + label='Observação', required=False, widget=forms.Textarea()) class Meta: diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 7f9792e47..1840da021 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -571,55 +571,42 @@ 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']) + + doc = {} + doc['tipo'] = documento.tipo + doc['ano'] = documento.ano + doc['data'] = documento.data + doc['numero_protocolo'] = documento.numero + doc['assunto'] = documento.assunto + doc['interessado'] = documento.interessado + doc['numero'] = documento.numero + doc['tramitacao'] = documento.tramitacao + doc['texto_integral'] = documento.texto_integral + doc['dias_prazo'] = documento.dias_prazo + doc['data_fim_prazo'] = documento.data_fim_prazo + doc['observacao'] = documento.observacao + + form = DocumentoAdministrativoForm( + initial=doc) 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'] - - if request.POST['ano']: - documento.ano = request.POST['ano'] - - if request.POST['data']: - documento.data = datetime.strptime( - request.POST['data'], "%d/%m/%Y") - - if request.POST['numero_protocolo']: - documento.numero_protocolo = request.POST['numero_protocolo'] - - if request.POST['assunto']: - documento.assunto = request.POST['assunto'] - - if request.POST['interessado']: - documento.interessado = request.POST['interessado'] - - if request.POST['tramitacao']: - documento.tramitacao = request.POST['tramitacao'] + form = DocumentoAdministrativoForm(request.POST) - if request.POST['dias_prazo']: - documento.dias_prazo = request.POST['dias_prazo'] - - if request.POST['data_fim_prazo']: - documento.data_fim_prazo = datetime.strptime( - request.POST['data_fim_prazo'], "%d/%m/%Y") - - if request.POST['observacao']: - documento.observacao = request.POST['observacao'] - - documento.save() + 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() @@ -627,7 +614,8 @@ class DetailDocumentoAdministrativo(DetailView): return HttpResponseRedirect(self.get_success_url()) def get_success_url(self): - return reverse('pesq_doc_adm') + return reverse('detail_doc_adm', kwargs={ + 'pk': self.kwargs['pk']}) class DocumentoAcessorioAdministrativoView(FormMixin, GenericView): diff --git a/templates/protocoloadm/detail_doc_adm.html b/templates/protocoloadm/detail_doc_adm.html index e615cc3e8..8d0dc2906 100644 --- a/templates/protocoloadm/detail_doc_adm.html +++ b/templates/protocoloadm/detail_doc_adm.html @@ -3,77 +3,6 @@ {% 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 %} From d2f8026064c602529954b8c19d33509e7c6d8d3f Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 17 Feb 2016 11:39:24 -0200 Subject: [PATCH 3/8] =?UTF-8?q?Habilita=20bot=C3=A3o=20de=20excluir?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/protocoloadm/detail_doc_adm.html | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/templates/protocoloadm/detail_doc_adm.html b/templates/protocoloadm/detail_doc_adm.html index 8d0dc2906..b073f38a3 100644 --- a/templates/protocoloadm/detail_doc_adm.html +++ b/templates/protocoloadm/detail_doc_adm.html @@ -3,6 +3,9 @@ {% load crispy_forms_tags %} {% block detail_content %} - {% crispy form %} - + {% crispy form %} +
+ {% csrf_token %} + +
{% endblock %} \ No newline at end of file From cca3ce01448b3c812664713d6cf12d868d6005c3 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Wed, 17 Feb 2016 11:45:24 -0200 Subject: [PATCH 4/8] =?UTF-8?q?Muda=20a=20tela=20para=20o=20detail=20ap?= =?UTF-8?q?=C3=B3s=20salvar=20o=20documento=20vinculado=20ao=20protocolo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- protocoloadm/views.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 1840da021..b0f512858 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -351,9 +351,8 @@ class CriarDocumentoProtocolo(FormMixin, GenericView): 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']}) + return reverse('detail_doc_adm', kwargs={ + 'pk': self.kwargs['pk']}) class ProtocoloMostrarView(TemplateView): From e7986a1a33b3e2ea26614429f2a5790ac983047a Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 18 Feb 2016 12:30:36 -0200 Subject: [PATCH 5/8] =?UTF-8?q?Implementa=20tela=20de=20edi=C3=A7=C3=A3o?= =?UTF-8?q?=20de=20um=20documento=20acess=C3=B3rio=20administrativo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- materia/views.py | 2 +- protocoloadm/forms.py | 31 ++++--- protocoloadm/urls.py | 9 +- protocoloadm/views.py | 90 +++++++++++++------ templates/protocoloadm/detail_doc_adm.html | 4 - .../documento_acessorio_administrativo.html | 51 ++++++----- ...cumento_acessorio_administrativo_edit.html | 7 ++ 7 files changed, 123 insertions(+), 71 deletions(-) create mode 100644 templates/protocoloadm/documento_acessorio_administrativo_edit.html diff --git a/materia/views.py b/materia/views.py index 1f63def44..dd907467e 100644 --- a/materia/views.py +++ b/materia/views.py @@ -773,10 +773,10 @@ class DocumentoAcessorioEditView(FormMixin, GenericView): 'tipos': TipoDocumento.objects.all()}) def post(self, request, *args, **kwargs): + import ipdb; ipdb.set_trace() 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 68329a6c4..aec57b907 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -2,7 +2,7 @@ from datetime import date import sapl from crispy_forms.helper import FormHelper -from crispy_forms.layout import HTML, Field, Fieldset, Layout +from crispy_forms.layout import Fieldset, Layout, Submit from django import forms from django.forms import ModelForm from django.utils.safestring import mark_safe @@ -345,18 +345,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__( @@ -497,7 +508,7 @@ class DocumentoAdministrativoForm(ModelForm): row1, row2, row3, row4, row5), Fieldset('Outras Informações', row6, row7), - form_actions(), + form_actions(more=[Submit('Excluir', 'Excluir')]), ), ) super(DocumentoAdministrativoForm, self).__init__( diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index f19013a2d..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, @@ -20,8 +21,7 @@ from protocoloadm.views import (AnularProtocoloAdmView, protocolo_materia_crud, status_tramitacao_administrativo_crud, tipo_documento_administrativo_crud, - tramitacao_administrativo_crud, - CriarDocumentoProtocolo) + tramitacao_administrativo_crud) urlpatterns = [ url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)), @@ -55,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'), diff --git a/protocoloadm/views.py b/protocoloadm/views.py index b0f512858..5dda51f88 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -574,22 +574,8 @@ class DetailDocumentoAdministrativo(DetailView): documento = DocumentoAdministrativo.objects.get( id=self.kwargs['pk']) - doc = {} - doc['tipo'] = documento.tipo - doc['ano'] = documento.ano - doc['data'] = documento.data - doc['numero_protocolo'] = documento.numero - doc['assunto'] = documento.assunto - doc['interessado'] = documento.interessado - doc['numero'] = documento.numero - doc['tramitacao'] = documento.tramitacao - doc['texto_integral'] = documento.texto_integral - doc['dias_prazo'] = documento.dias_prazo - doc['data_fim_prazo'] = documento.data_fim_prazo - doc['observacao'] = documento.observacao - form = DocumentoAdministrativoForm( - initial=doc) + instance=documento) return self.render_to_response({ 'form': form, 'pk': kwargs['pk']}) @@ -609,14 +595,65 @@ class DetailDocumentoAdministrativo(DetailView): elif 'Excluir' in request.POST: DocumentoAdministrativo.objects.get( id=kwargs['pk']).delete() + return HttpResponseRedirect(self.get_success_delete()) return HttpResponseRedirect(self.get_success_url()) + def get_success_delete(self): + return reverse('pesq_doc_adm') + def get_success_url(self): return reverse('detail_doc_adm', kwargs={ 'pk': self.kwargs['pk']}) +class DocumentoAcessorioAdministrativoEditView(FormMixin, GenericView): + template_name = "protocoloadm/documento_acessorio_administrativo_edit.html" + + 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) + + return self.render_to_response({'pk': self.kwargs['pk'], + 'doc': doc, + 'doc_ace': doc_ace, + 'form': form}) + + def post(self, request, *args, **kwargs): + form = DocumentoAcessorioAdministrativoForm(request.POST, excluir=True) + doc_ace = DocumentoAcessorioAdministrativo.objects.get( + id=kwargs['ano']) + + 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): + pk = self.kwargs['pk'] + return reverse('doc_ace_adm', kwargs={'pk': pk}) + + class DocumentoAcessorioAdministrativoView(FormMixin, GenericView): template_name = "protocoloadm/documento_acessorio_administrativo.html" @@ -625,10 +662,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.' @@ -641,17 +677,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 b073f38a3..baf9e5c8c 100644 --- a/templates/protocoloadm/detail_doc_adm.html +++ b/templates/protocoloadm/detail_doc_adm.html @@ -4,8 +4,4 @@ {% block detail_content %} {% crispy form %} -
- {% csrf_token %} - -
{% endblock %} \ No newline at end of file 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 From 719cc870055130ae4762b58ddf02e88d797b018e Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Thu, 18 Feb 2016 14:29:34 -0200 Subject: [PATCH 6/8] Simplifica DocumentoAdministrativoForm --- protocoloadm/forms.py | 60 ++++--------------- .../migrations/0007_auto_20160218_1429.py | 19 ++++++ protocoloadm/models.py | 6 +- protocoloadm/views.py | 2 - 4 files changed, 36 insertions(+), 51 deletions(-) create mode 100644 protocoloadm/migrations/0007_auto_20160218_1429.py diff --git a/protocoloadm/forms.py b/protocoloadm/forms.py index aec57b907..4942a0e71 100644 --- a/protocoloadm/forms.py +++ b/protocoloadm/forms.py @@ -1,11 +1,12 @@ from datetime import date -import sapl from crispy_forms.helper import FormHelper -from crispy_forms.layout import Fieldset, Layout, Submit +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 + +import sapl from materia.models import TipoMateriaLegislativa from sapl.layout import form_actions @@ -429,34 +430,6 @@ class TramitacaoAdmForm(ModelForm): 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='Assunto', required=False, - widget=forms.Textarea()) - - observacao = forms.CharField( - label='Observação', required=False, - widget=forms.Textarea()) - class Meta: model = DocumentoAdministrativo fields = ['tipo', @@ -470,46 +443,39 @@ class DocumentoAdministrativoForm(ModelForm): 'dias_prazo', 'data_fim_prazo', 'observacao', - 'texto_integral' + 'texto_integral', ] def __init__(self, *args, **kwargs): row1 = sapl.layout.to_row( - [('tipo', 4), - ('numero', 4), - ('ano', 4)]) + [('tipo', 4), ('numero', 4), ('ano', 4)]) row2 = sapl.layout.to_row( - [('data', 6), - ('numero_protocolo', 6)]) + [('data', 6), ('numero_protocolo', 6)]) row3 = sapl.layout.to_row( [('assunto', 12)]) row4 = sapl.layout.to_row( - [('interessado', 9), - ('tramitacao', 3)]) + [('interessado', 9), ('tramitacao', 3)]) row5 = sapl.layout.to_row( [('texto_integral', 12)]) row6 = sapl.layout.to_row( - [('dias_prazo', 6), - ('data_fim_prazo', 6)]) + [('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(more=[Submit('Excluir', 'Excluir')]), - ), + 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..97408e787 100644 --- a/protocoloadm/models.py +++ b/protocoloadm/models.py @@ -2,7 +2,7 @@ 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 class TipoDocumentoAdministrativo(models.Model): @@ -40,7 +40,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/views.py b/protocoloadm/views.py index 5dda51f88..c848a6592 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -328,14 +328,12 @@ 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): From cb98a8b2e0d6e270f927c8a3c6e26113513664fc Mon Sep 17 00:00:00 2001 From: Marcio Mazza Date: Thu, 18 Feb 2016 16:23:57 -0200 Subject: [PATCH 7/8] Usa CreateView para CriarDocumentoProtocolo --- protocoloadm/models.py | 7 ++--- protocoloadm/views.py | 32 ++++++--------------- templates/protocoloadm/criar_documento.html | 7 ----- 3 files changed, 11 insertions(+), 35 deletions(-) delete mode 100644 templates/protocoloadm/criar_documento.html diff --git a/protocoloadm/models.py b/protocoloadm/models.py index 97408e787..f660701a6 100644 --- a/protocoloadm/models.py +++ b/protocoloadm/models.py @@ -3,6 +3,7 @@ from django.utils.translation import ugettext_lazy as _ from materia.models import Autor, TipoMateriaLegislativa, UnidadeTramitacao 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): diff --git a/protocoloadm/views.py b/protocoloadm/views.py index c848a6592..dc512f4a0 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -1,7 +1,6 @@ from datetime import date, datetime from re import sub -import sapl from django import forms from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse @@ -10,13 +9,15 @@ 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 + +import sapl from materia.models import Proposicao, TipoMateriaLegislativa from sapl.crud import build_crud from sapl.utils import create_barcode -from vanilla import GenericView from .forms import (AnularProcoloAdmForm, DocumentoAcessorioAdministrativoForm, DocumentoAdministrativoForm, ProposicaoSimpleForm, @@ -324,33 +325,18 @@ def criar_documento(protocolo): return doc -class CriarDocumentoProtocolo(FormMixin, GenericView): +class CriarDocumentoProtocolo(CreateView): template_name = "protocoloadm/criar_documento.html" + form_class = DocumentoAdministrativoForm - def get(self, request, *args, **kwargs): + def get_initial(self): 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({ - '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}) + return criar_documento(protocolo) def get_success_url(self): - return reverse('detail_doc_adm', kwargs={ - 'pk': self.kwargs['pk']}) + return reverse('detail_doc_adm', kwargs={'pk': self.object.pk}) class ProtocoloMostrarView(TemplateView): diff --git a/templates/protocoloadm/criar_documento.html b/templates/protocoloadm/criar_documento.html deleted file mode 100644 index 8deec35e0..000000000 --- a/templates/protocoloadm/criar_documento.html +++ /dev/null @@ -1,7 +0,0 @@ -{% extends "crud/form.html" %} -{% load i18n %} -{% load crispy_forms_tags %} - -{% block detail_content %} - -{% endblock detail_content %} \ No newline at end of file From 156c8f2ab73034b81f4a3474eb457109ba13ecf0 Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Fri, 19 Feb 2016 17:17:42 -0200 Subject: [PATCH 8/8] Retira breakpoint incorreto --- materia/views.py | 1 - 1 file changed, 1 deletion(-) diff --git a/materia/views.py b/materia/views.py index dd907467e..09148e58d 100644 --- a/materia/views.py +++ b/materia/views.py @@ -773,7 +773,6 @@ class DocumentoAcessorioEditView(FormMixin, GenericView): 'tipos': TipoDocumento.objects.all()}) def post(self, request, *args, **kwargs): - import ipdb; ipdb.set_trace() form = DocumentoAcessorioForm(request.POST) materia = MateriaLegislativa.objects.get(id=kwargs['pk']) documento = DocumentoAcessorio.objects.get(id=kwargs['id'])