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