From 293bb8272232c58e201c76a5a6aa3026fbb71f0c Mon Sep 17 00:00:00 2001 From: Eduardo Edson Batista Cordeiro Alves Date: Thu, 22 Oct 2015 15:58:36 -0200 Subject: [PATCH] Add edit/remove DocumentoAdministrativo --- protocoloadm/urls.py | 5 +- protocoloadm/views.py | 84 ++++++++++++++++- templates/protocoloadm/detail_doc_adm.html | 93 +++++++++++++++++++ templates/protocoloadm/detail_doc_detail.html | 8 ++ templates/protocoloadm/pesquisa_doc_adm.html | 14 ++- ...il.html => pesquisa_documento_detail.html} | 0 6 files changed, 192 insertions(+), 12 deletions(-) create mode 100644 templates/protocoloadm/detail_doc_adm.html create mode 100644 templates/protocoloadm/detail_doc_detail.html rename templates/protocoloadm/{documento_detail.html => pesquisa_documento_detail.html} (100%) diff --git a/protocoloadm/urls.py b/protocoloadm/urls.py index 4b06db787..058ed6a32 100644 --- a/protocoloadm/urls.py +++ b/protocoloadm/urls.py @@ -1,6 +1,6 @@ from django.conf.urls import include, url - from protocoloadm.views import (AnularProtocoloAdmView, + DetailDocumentoAdministrativo, PesquisarDocumentoAdministrativo, ProposicaoReceberView, ProposicoesIncorporadasView, @@ -44,7 +44,8 @@ urlpatterns = [ ProtocoloMateriaView.as_view(), name='protocolar_mat'), url(r'^protocoloadm/pesq-doc-adm', PesquisarDocumentoAdministrativo.as_view(), name='pesq_doc_adm'), - + url(r'^protocoloadm/doc-adm/(?P\d+)', + DetailDocumentoAdministrativo.as_view(), name='detail_doc_adm'), # TODO: move to Proposicoes app url(r'^protocoloadm/proposicao-receber', diff --git a/protocoloadm/views.py b/protocoloadm/views.py index 82b040751..0b296dbb1 100644 --- a/protocoloadm/views.py +++ b/protocoloadm/views.py @@ -3,13 +3,14 @@ from re import sub from django import forms from django.core.exceptions import ObjectDoesNotExist +from django.http import HttpResponseRedirect 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 import ListView, DetailView from django.views.generic.base import TemplateView from django.views.generic.edit import FormMixin from vanilla import GenericView @@ -546,10 +547,15 @@ class PesquisarDocumentoAdministrativo(TemplateView): def get_tipos_doc(self): return TipoDocumentoAdministrativo.objects.all() + def get(self, request, *args, **kwargs): + return self.render_to_response( + {"tipos_doc": TipoDocumentoAdministrativo.objects.all()} + ) + def post(self, request, *args, **kwargs): if request.POST['tipo_documento']: - kwargs['tipo_documento'] = request.POST['tipo_documento'] + kwargs['tipo_id'] = request.POST['tipo_documento'] if request.POST['numero']: kwargs['numero'] = request.POST['numero'] @@ -580,6 +586,7 @@ class PesquisarDocumentoAdministrativo(TemplateView): else: kwargs['tramitacao'] = request.POST['tramitacao'] + # TODO # if request.POST['localizacao']: # kwargs['localizacao'] = request.POST['localizacao'] @@ -588,6 +595,73 @@ class PesquisarDocumentoAdministrativo(TemplateView): doc = DocumentoAdministrativo.objects.filter(**kwargs) - return self.render_to_response( - {'documentos': doc} - ) + if len(doc) == 0: + return self.render_to_response( + {'error': 'Nenhum resultado encontrado!', + "tipos_doc": TipoDocumentoAdministrativo.objects.all()} + ) + else: + return self.render_to_response( + {'documentos': doc} + ) + + +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']) + return self.render_to_response({ + 'doc': doc, + 'tipos_doc': TipoDocumentoAdministrativo.objects.all() + }) + + 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'] + + 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() + elif 'Excluir' in request.POST: + DocumentoAdministrativo.objects.get( + id=kwargs['pk']).delete() + + return HttpResponseRedirect(self.get_success_url()) + + def get_success_url(self): + return reverse('pesq_doc_adm') diff --git a/templates/protocoloadm/detail_doc_adm.html b/templates/protocoloadm/detail_doc_adm.html new file mode 100644 index 000000000..11e243ad2 --- /dev/null +++ b/templates/protocoloadm/detail_doc_adm.html @@ -0,0 +1,93 @@ +{% extends "protocoloadm/detail_doc_detail.html" %} +{% load i18n %} +{% 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
  • +
+
    +
  • +
+
+ + +
+
+{% endblock %} + +{% block foot_js %} + +{% endblock %} \ No newline at end of file diff --git a/templates/protocoloadm/detail_doc_detail.html b/templates/protocoloadm/detail_doc_detail.html new file mode 100644 index 000000000..02739b020 --- /dev/null +++ b/templates/protocoloadm/detail_doc_detail.html @@ -0,0 +1,8 @@ +{% extends "crud/detail.html" %} +{% load i18n %} + +{% block sections_nav %} +