From 34ab864875c5b4cf29d91627210dffd2869daf73 Mon Sep 17 00:00:00 2001 From: Edward Ribeiro Date: Wed, 4 Nov 2015 11:48:33 -0200 Subject: [PATCH] Add Tramitacao Doc Adm (lacking QA fixes) --- protocoloadm/urls.py | 18 ++- protocoloadm/views.py | 140 +++++++++++++++++- templates/protocoloadm/tramitacao.html | 40 +++++ templates/protocoloadm/tramitacao_edit.html | 28 ++++ .../protocoloadm/tramitacao_incluir.html | 28 ++++ 5 files changed, 251 insertions(+), 3 deletions(-) create mode 100644 templates/protocoloadm/tramitacao.html create mode 100644 templates/protocoloadm/tramitacao_edit.html create mode 100644 templates/protocoloadm/tramitacao_incluir.html diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index cb242c815..d299301d3 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -16,7 +16,11 @@ from protocoloadm.views import (AnularProtocoloAdmView, protocolo_materia_crud, status_tramitacao_administrativo_crud, tipo_documento_administrativo_crud, - tramitacao_administrativo_crud) + tramitacao_administrativo_crud, + TramitacaoAdmView, + TramitacaoAdmEditView, + TramitacaoAdmIncluirView, + TramitacaoAdmDeleteView) urlpatterns = [ url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)), @@ -51,6 +55,16 @@ urlpatterns = [ url(r'^protocoloadm/doc-ace-adm/(?P\d+)', DocumentoAcessorioAdministrativoView.as_view(), name='doc_ace_adm'), + url(r'^protocoloadm/(?P\d+)/tramitacao$', + TramitacaoAdmView.as_view(), name='tramitacao'), + url(r'^protocoloadm/(?P\d+)/tramitacao_incluir', + TramitacaoAdmIncluirView.as_view(), name='tramitacao_incluir'), + url(r'^protocoloadm/(?P\d+)/tramitacao_edit', + TramitacaoAdmEditView.as_view(), name='tramitacao_edit'), + url(r'^protocoloadm/(?P\d+)/tramitacao_delete/(?P\d+)', + TramitacaoAdmDeleteView.as_view(), name='tramitacao_delete'), + + # TODO: move to Proposicoes app url(r'^protocoloadm/proposicao-receber', ProposicaoReceberView.as_view(), name='proposicao_receber'), @@ -64,5 +78,5 @@ urlpatterns = [ ProposicoesIncorporadasView.as_view(), name='proposicoes_incorporadas'), url(r'^protocoloadm/(?P\d+)/proposicao', - ProposicaoView.as_view(), name='proposicao_view') + ProposicaoView.as_view(), name='proposicao_view'), ] diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 4b11468d8..e5146e6bb 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -2,7 +2,7 @@ from datetime import date, datetime from re import sub from crispy_forms.helper import FormHelper -from crispy_forms.layout import ButtonHolder, Fieldset, Layout, Submit +from crispy_forms.layout import ButtonHolder, Fieldset, Field, Layout, Submit from django import forms from django.core.exceptions import ObjectDoesNotExist from django.core.urlresolvers import reverse @@ -10,6 +10,7 @@ from django.db.models import Max from django.forms import ModelForm from django.http import HttpResponseRedirect 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 _ @@ -798,3 +799,140 @@ class DocumentoAcessorioAdministrativoView(FormMixin, GenericView): def get_success_url(self): pk = self.kwargs['pk'] return reverse('doc_ace_adm', kwargs={'pk': pk}) + + +class TramitacaoAdmView(FormMixin, GenericView): + template_name = "protocoloadm/tramitacao.html" + + def get(self, request, *args, **kwargs): + + pk = kwargs['pk'] + documento = DocumentoAdministrativo.objects.get(id=pk) + tramitacoes = TramitacaoAdministrativo.objects.filter( + documento=documento).order_by('-data_tramitacao') + + return self.render_to_response({'documento': documento, 'tramitacoes': tramitacoes}) + + +class TramitacaoAdmForm(ModelForm): + + data_tramitacao = forms.DateField(label=u'Data Tramitação', + input_formats=['%d/%m/%Y'], + required=False, + widget=forms.DateInput(format='%d/%m/%Y', + attrs={'class': 'dateinput'})) + + data_encaminhamento = forms.DateField(label=u'Data Encaminhamento', + 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'})) + + class Meta: + model = TramitacaoAdministrativo + fields = ['data_tramitacao', + 'unidade_tramitacao_local', + 'status', + 'unidade_tramitacao_destino', + 'data_encaminhamento', + 'data_fim_prazo', + 'texto', + 'documento', + ] + + def __init__(self, *args, **kwargs): + self.helper = FormHelper() + self.helper.layout = Layout( + Fieldset('Incluir Tramitação', + 'data_tramitacao', + 'unidade_tramitacao_local', + 'status', + 'unidade_tramitacao_destino', + 'data_encaminhamento', + 'data_fim_prazo', + 'texto'), + Field('documento', type="hidden"), + ButtonHolder( + Submit('submit', 'Salvar', + css_class='button primary') + ) + ) + super(TramitacaoAdmForm, self).__init__( + *args, **kwargs) + + +class TramitacaoAdmIncluirView(FormMixin, GenericView): + template_name = "protocoloadm/tramitacao_incluir.html" + + def get(self, request, *args, **kwargs): + pk = kwargs['pk'] + documento = DocumentoAdministrativo.objects.get(id=pk) + data = {'documento': documento} + form = TramitacaoAdmForm(initial=data) + + return self.render_to_response({'documento': documento, 'form': form}) + + def post(self, request, *args, **kwargs): + pk = kwargs['pk'] + documento = DocumentoAdministrativo.objects.get(id=pk) + form = TramitacaoAdmForm(request.POST or None) + + if form.is_valid(): + tramitacao = form.save(commit=False) + tramitacao.ultima = False + tramitacao.save() + message = "Tramitação criada com sucesso" + return HttpResponseRedirect(reverse('tramitacao', kwargs={'pk': pk})) + else: + return self.form_invalid(form) + + +class TramitacaoAdmEditView(FormMixin, GenericView): + + template_name = "protocoloadm/tramitacao_edit.html" + + def get(self, request, *args, **kwargs): + pk = kwargs['pk'] + tramitacao = TramitacaoAdministrativo.objects.get(id=pk) + documento = tramitacao.documento + form = TramitacaoAdmForm(instance=tramitacao) + + return self.render_to_response({'documento': documento, 'form': form}) + + def post(self, request, *args, **kwargs): + pk = kwargs['pk'] + tramitacao = TramitacaoAdministrativo.objects.get(id=pk) + documento = tramitacao.documento + form = TramitacaoAdmForm(request.POST, instance=tramitacao) + + if form.is_valid(): + tramitacao = form.save(commit=False) + tramitacao.ultima = False + tramitacao.save() + return HttpResponseRedirect(reverse('tramitacao', kwargs={'pk': pk})) + else: + return self.form_invalid(form) + + +class TramitacaoAdmDeleteView(FormMixin, GenericView): + + template_name = "protocoloadm/tramitacao.html" + + def get(self, request, *args, **kwargs): + pk = kwargs['pk'] + oid = kwargs['oid'] + + documento = DocumentoAdministrativo.objects.get(id=pk) + + tramitacao = TramitacaoAdministrativo.objects.get(id=oid) + tramitacao.delete() + tramitacoes = TramitacaoAdministrativo.objects.filter( + documento=documento) + + return self.render_to_response({'documento': documento, 'tramitacoes': tramitacoes}) diff --git a/templates/protocoloadm/tramitacao.html b/templates/protocoloadm/tramitacao.html new file mode 100644 index 000000000..1acd75f64 --- /dev/null +++ b/templates/protocoloadm/tramitacao.html @@ -0,0 +1,40 @@ +{% extends "protocoloadm/protocoloadm_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} + +
+ Tipo: {{documento.tipo.sigla}} Número: {{documento.numero}} Ano: {{documento.ano}}
+ Assunto: {{documento.assunto}} +
+ +
+

Tramitação

+ {% if tramitacoes %} + + + + + + + + + {% for t in tramitacoes %} + + + + + + + + + {% endfor %} +
Data AçãoOrigemDestinoStatusExcluir
{{t.data_encaminhamento|date:"d/m/Y"}}{{t.unidade_tramitacao_local}}{{t.unidade_tramitacao_destino}}{{t.status.sigla}}Excluir
+ {% else %} + Nenhuma tramitação cadastrada para este documento. + {% endif %} +
+ Incluir Tramitação +
+{% endblock detail_content %} \ No newline at end of file diff --git a/templates/protocoloadm/tramitacao_edit.html b/templates/protocoloadm/tramitacao_edit.html new file mode 100644 index 000000000..08d7d052b --- /dev/null +++ b/templates/protocoloadm/tramitacao_edit.html @@ -0,0 +1,28 @@ +{% extends "protocoloadm/protocoloadm_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} + +
+ Tipo: {{documento.tipo.sigla}} Número: {{documento.numero}} Ano: {{documento.ano}}
+ Assunto: {{documento.assunto}} +
+ +

Tramitação Edit

+ {% crispy form %} +{% endblock detail_content %} + +{% block foot_js %} + +{% endblock %} \ No newline at end of file diff --git a/templates/protocoloadm/tramitacao_incluir.html b/templates/protocoloadm/tramitacao_incluir.html new file mode 100644 index 000000000..8640fb142 --- /dev/null +++ b/templates/protocoloadm/tramitacao_incluir.html @@ -0,0 +1,28 @@ +{% extends "protocoloadm/protocoloadm_detail.html" %} +{% load i18n %} +{% load crispy_forms_tags %} + +{% block detail_content %} + +
+ Tipo: {{documento.tipo.sigla}} Número: {{documento.numero}} Ano: {{documento.ano}}
+ Assunto: {{documento.assunto}} +
+ +

Tramitação

+ {% crispy form %} +{% endblock detail_content %} + +{% block foot_js %} + +{% endblock %} \ No newline at end of file