Browse Source

Implementa tela de edição de um documento acessório administrativo

pull/222/head
Eduardo Edson Batista Cordeiro Alves 9 years ago
parent
commit
e7986a1a33
  1. 2
      materia/views.py
  2. 31
      protocoloadm/forms.py
  3. 9
      protocoloadm/urls.py
  4. 90
      protocoloadm/views.py
  5. 4
      templates/protocoloadm/detail_doc_adm.html
  6. 51
      templates/protocoloadm/documento_acessorio_administrativo.html
  7. 7
      templates/protocoloadm/documento_acessorio_administrativo_edit.html

2
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()

31
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__(

9
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<pk>\d+)',
DocumentoAcessorioAdministrativoView.as_view(), name='doc_ace_adm'),
url(r'^protocoloadm/doc-ace-adm/edit/(?P<pk>\d+)/(?P<ano>\d+)',
DocumentoAcessorioAdministrativoEditView.as_view(),
name='doc_ace_adm_edit'),
url(r'^protocoloadm/(?P<pk>\d+)/tramitacao$',
TramitacaoAdmView.as_view(), name='tramitacao_adm'),

90
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)

4
templates/protocoloadm/detail_doc_adm.html

@ -4,8 +4,4 @@
{% block detail_content %}
{% crispy form %}
<form method="post">
{% csrf_token %}
<input type="submit" name="Excluir" value="Excluir" class="btn btn-danger" id="submit-id-excluir" />
</form>
{% endblock %}

51
templates/protocoloadm/documento_acessorio_administrativo.html

@ -5,36 +5,39 @@
{% block detail_content %}
<fieldset>
<legend>Documento Administrativo</legend>
<div class="row">
<div class="col-md-4">Tipo: <b>{{doc.tipo.sigla}}</b></div>
<div class="col-md-4">Número: <b>{{doc.numero}}</b></div>
<div class="col-md-4">Ano: <b>{{doc.ano}}</b></div>
</div>
<div class="row">
<div class="col-md-4">Tipo: <b>{{doc.tipo.sigla}}</b></div>
<div class="col-md-4">Número: <b>{{doc.numero}}</b></div>
<div class="col-md-4">Ano: <b>{{doc.ano}}</b></div>
</div>
Assunto: <b>{{doc.assunto}}</b>
<br/><br/>
<fieldset>
<legend>Documentos Acessórios</legend>
{{ doc_ace_null }}
<table>
<tr>
<th>Documento</th>
<th>Nome</th>
<th>Tipo</th>
<th>Data</th>
<th>Autor</th>
</tr>
{% for d in doc_ace %}
{% if not doc_ace_null %}
<table style="width:100%">
<tr>
<td>{{d.arquivo}}</td>
<td>{{d.nome}}</td>
<td>{{d.tipo.descricao}}</td>
<td>{{d.data|date:"d/m/Y"}}</td>
<td>{{d.autor}}</td>
<th>Documento</th>
<th>Nome</th>
<th>Tipo</th>
<th>Data</th>
<th>Autor</th>
</tr>
{% endfor %}
</table>
{% for d in doc_ace %}
<tr>
<td>{{d.arquivo}}</td>
<td><a href="{% url 'doc_ace_adm_edit' doc.id d.id %}">{{d.nome}}</a></td>
<td>{{d.tipo.descricao}}</td>
<td>{{d.data|date:"d/m/Y"}}</td>
<td>{{d.autor}}</td>
</tr>
{% endfor %}
</table>
{% else %}
{{ doc_ace_null }}
{% endif %}
</fieldset>
<br/><br/>
{% crispy form %}
</fieldset>
{% endblock %}

7
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 %}
Loading…
Cancel
Save