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()}) 'tipos': TipoDocumento.objects.all()})
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
import ipdb; ipdb.set_trace()
form = DocumentoAcessorioForm(request.POST) form = DocumentoAcessorioForm(request.POST)
materia = MateriaLegislativa.objects.get(id=kwargs['pk']) materia = MateriaLegislativa.objects.get(id=kwargs['pk'])
documento = DocumentoAcessorio.objects.get(id=kwargs['id']) documento = DocumentoAcessorio.objects.get(id=kwargs['id'])
if form.is_valid(): if form.is_valid():
if 'excluir' in request.POST: if 'excluir' in request.POST:
documento.delete() documento.delete()

31
protocoloadm/forms.py

@ -2,7 +2,7 @@ from datetime import date
import sapl import sapl
from crispy_forms.helper import FormHelper 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 import forms
from django.forms import ModelForm from django.forms import ModelForm
from django.utils.safestring import mark_safe from django.utils.safestring import mark_safe
@ -345,18 +345,29 @@ class DocumentoAcessorioAdministrativoForm(ModelForm):
'arquivo', 'arquivo',
'assunto'] '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 = FormHelper()
self.helper.layout = Layout( self.helper.layout = Layout(
Fieldset( Fieldset(
'Incluir Documento Acessório', 'Incluir Documento Acessório',
'tipo', row1, row2, row3, row4,
'nome', form_actions(more=more)
'data',
'autor',
'arquivo',
'assunto',
form_actions()
) )
) )
super(DocumentoAcessorioAdministrativoForm, self).__init__( super(DocumentoAcessorioAdministrativoForm, self).__init__(
@ -497,7 +508,7 @@ class DocumentoAdministrativoForm(ModelForm):
row1, row2, row3, row4, row5), row1, row2, row3, row4, row5),
Fieldset('Outras Informações', Fieldset('Outras Informações',
row6, row7), row6, row7),
form_actions(), form_actions(more=[Submit('Excluir', 'Excluir')]),
), ),
) )
super(DocumentoAdministrativoForm, self).__init__( super(DocumentoAdministrativoForm, self).__init__(

9
protocoloadm/urls.py

@ -1,8 +1,9 @@
from django.conf.urls import include, url from django.conf.urls import include, url
from protocoloadm.views import (AnularProtocoloAdmView, from protocoloadm.views import (AnularProtocoloAdmView,
ComprovanteProtocoloView, ComprovanteProtocoloView,
CriarDocumentoProtocolo,
DetailDocumentoAdministrativo, DetailDocumentoAdministrativo,
DocumentoAcessorioAdministrativoEditView,
DocumentoAcessorioAdministrativoView, DocumentoAcessorioAdministrativoView,
PesquisarDocumentoAdministrativo, PesquisarDocumentoAdministrativo,
ProposicaoDetailView, ProposicaoReceberView, ProposicaoDetailView, ProposicaoReceberView,
@ -20,8 +21,7 @@ from protocoloadm.views import (AnularProtocoloAdmView,
protocolo_materia_crud, protocolo_materia_crud,
status_tramitacao_administrativo_crud, status_tramitacao_administrativo_crud,
tipo_documento_administrativo_crud, tipo_documento_administrativo_crud,
tramitacao_administrativo_crud, tramitacao_administrativo_crud)
CriarDocumentoProtocolo)
urlpatterns = [ urlpatterns = [
url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)), url(r'^protocoloadm/docadm/', include(documento_administrativo_crud.urls)),
@ -55,6 +55,9 @@ urlpatterns = [
DetailDocumentoAdministrativo.as_view(), name='detail_doc_adm'), DetailDocumentoAdministrativo.as_view(), name='detail_doc_adm'),
url(r'^protocoloadm/doc-ace-adm/(?P<pk>\d+)', url(r'^protocoloadm/doc-ace-adm/(?P<pk>\d+)',
DocumentoAcessorioAdministrativoView.as_view(), name='doc_ace_adm'), 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$', url(r'^protocoloadm/(?P<pk>\d+)/tramitacao$',
TramitacaoAdmView.as_view(), name='tramitacao_adm'), TramitacaoAdmView.as_view(), name='tramitacao_adm'),

90
protocoloadm/views.py

@ -574,22 +574,8 @@ class DetailDocumentoAdministrativo(DetailView):
documento = DocumentoAdministrativo.objects.get( documento = DocumentoAdministrativo.objects.get(
id=self.kwargs['pk']) 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( form = DocumentoAdministrativoForm(
initial=doc) instance=documento)
return self.render_to_response({ return self.render_to_response({
'form': form, 'form': form,
'pk': kwargs['pk']}) 'pk': kwargs['pk']})
@ -609,14 +595,65 @@ class DetailDocumentoAdministrativo(DetailView):
elif 'Excluir' in request.POST: elif 'Excluir' in request.POST:
DocumentoAdministrativo.objects.get( DocumentoAdministrativo.objects.get(
id=kwargs['pk']).delete() id=kwargs['pk']).delete()
return HttpResponseRedirect(self.get_success_delete())
return HttpResponseRedirect(self.get_success_url()) return HttpResponseRedirect(self.get_success_url())
def get_success_delete(self):
return reverse('pesq_doc_adm')
def get_success_url(self): def get_success_url(self):
return reverse('detail_doc_adm', kwargs={ return reverse('detail_doc_adm', kwargs={
'pk': self.kwargs['pk']}) '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): class DocumentoAcessorioAdministrativoView(FormMixin, GenericView):
template_name = "protocoloadm/documento_acessorio_administrativo.html" template_name = "protocoloadm/documento_acessorio_administrativo.html"
@ -625,10 +662,9 @@ class DocumentoAcessorioAdministrativoView(FormMixin, GenericView):
doc = DocumentoAdministrativo.objects.get( doc = DocumentoAdministrativo.objects.get(
id=kwargs['pk']) id=kwargs['pk'])
doc_ace_null = '' doc_ace_null = ''
try: doc_acessorio = DocumentoAcessorioAdministrativo.objects.filter(
doc_acessorio = DocumentoAcessorioAdministrativo.objects.filter( documento_id=kwargs['pk'])
documento_id=kwargs['pk']) if not doc_acessorio:
except ObjectDoesNotExist:
doc_ace_null = 'Nenhum documento acessório \ doc_ace_null = 'Nenhum documento acessório \
cadastrado para este processo.' cadastrado para este processo.'
@ -641,17 +677,13 @@ class DocumentoAcessorioAdministrativoView(FormMixin, GenericView):
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
form = DocumentoAcessorioAdministrativoForm(request.POST) form = DocumentoAcessorioAdministrativoForm(request.POST)
if form.is_valid(): if form.is_valid():
doc_acessorio = DocumentoAcessorioAdministrativo() doc_ace = form.save(commit=False)
doc_acessorio.tipo = form.cleaned_data['tipo'] if 'arquivo' in request.FILES:
doc_acessorio.nome = form.cleaned_data['nome'] doc_ace.arquivo = request.FILES['arquivo']
doc_acessorio.data = form.cleaned_data['data'] doc = DocumentoAdministrativo.objects.get(
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(
id=kwargs['pk']) id=kwargs['pk'])
doc_acessorio.save() doc_ace.documento = doc
doc_ace.save()
return self.form_valid(form) return self.form_valid(form)
else: else:
return self.form_invalid(form) return self.form_invalid(form)

4
templates/protocoloadm/detail_doc_adm.html

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

51
templates/protocoloadm/documento_acessorio_administrativo.html

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