Browse Source

Fix #1087

pull/1135/head
Eduardo Calil 8 years ago
parent
commit
a0e1b83443
  1. 28
      sapl/protocoloadm/forms.py
  2. 16
      sapl/protocoloadm/urls.py
  3. 162
      sapl/protocoloadm/views.py
  4. 3
      sapl/templates/protocoloadm/layouts.yaml
  5. 2
      sapl/templates/protocoloadm/subnav.yaml

28
sapl/protocoloadm/forms.py

@ -409,34 +409,6 @@ class DocumentoAcessorioAdministrativoForm(ModelForm):
'data': forms.DateInput(format='%d/%m/%Y') 'data': forms.DateInput(format='%d/%m/%Y')
} }
def __init__(self, excluir=False, *args, **kwargs):
row1 = to_row(
[('tipo', 4),
('nome', 4),
('data', 4)])
row2 = to_row(
[('autor', 12)])
row3 = to_row(
[('arquivo', 12)])
row4 = to_row(
[('assunto', 12)])
more = []
if excluir:
more = [Submit('Excluir', 'Excluir')]
self.helper = FormHelper()
self.helper.layout = Layout(
Fieldset(
_('Incluir Documento Acessório'),
row1, row2, row3, row4,
form_actions(more=more)
)
)
super(DocumentoAcessorioAdministrativoForm, self).__init__(
*args, **kwargs)
class TramitacaoAdmForm(ModelForm): class TramitacaoAdmForm(ModelForm):

16
sapl/protocoloadm/urls.py

@ -3,10 +3,7 @@ from django.conf.urls import include, url
from sapl.protocoloadm.views import (AnularProtocoloAdmView, from sapl.protocoloadm.views import (AnularProtocoloAdmView,
ComprovanteProtocoloView, ComprovanteProtocoloView,
CriarDocumentoProtocolo, CriarDocumentoProtocolo,
DetailDocumentoAdministrativo,
DocumentoAcessorioAdministrativoCrud, DocumentoAcessorioAdministrativoCrud,
DocumentoAcessorioAdministrativoEditView,
DocumentoAcessorioAdministrativoView,
DocumentoAdministrativoCrud, DocumentoAdministrativoCrud,
PesquisarDocumentoAdministrativoView, PesquisarDocumentoAdministrativoView,
ProtocoloDocumentoView, ProtocoloDocumentoView,
@ -27,18 +24,11 @@ app_name = AppConfig.name
urlpatterns_documento_administrativo = [ urlpatterns_documento_administrativo = [
url(r'^docadm/', url(r'^docadm/',
include(DocumentoAdministrativoCrud.get_urls() + include(DocumentoAdministrativoCrud.get_urls() +
TramitacaoAdmCrud.get_urls())), TramitacaoAdmCrud.get_urls() +
url(r'^docadm/doc-acessorio/', DocumentoAcessorioAdministrativoCrud.get_urls())),
include(DocumentoAcessorioAdministrativoCrud.get_urls())),
url(r'^docadm/pesq-doc-adm', url(r'^docadm/pesq-doc-adm',
PesquisarDocumentoAdministrativoView.as_view(), name='pesq_doc_adm'), PesquisarDocumentoAdministrativoView.as_view(), name='pesq_doc_adm'),
url(r'^docadm/doc-adm/(?P<pk>\d+)$',
DetailDocumentoAdministrativo.as_view(), name='detail_doc_adm'),
url(r'^docadm/doc-ace-adm/(?P<pk>\d+)',
DocumentoAcessorioAdministrativoView.as_view(), name='doc_ace_adm'),
url(r'^docadm/doc-ace-adm/edit/(?P<pk>\d+)/(?P<ano>\d+)',
DocumentoAcessorioAdministrativoEditView.as_view(),
name='doc_ace_adm_edit'),
url(r'^docadm/texto_integral/(?P<pk>\d+)$', doc_texto_integral, url(r'^docadm/texto_integral/(?P<pk>\d+)$', doc_texto_integral,
name='doc_texto_integral'), name='doc_texto_integral'),

162
sapl/protocoloadm/views.py

@ -37,10 +37,6 @@ TipoDocumentoAdministrativoCrud = CrudAux.build(
# ProtocoloMateriaCrud = Crud.build(Protocolo, '') # ProtocoloMateriaCrud = Crud.build(Protocolo, '')
DocumentoAcessorioAdministrativoCrud = Crud.build(
DocumentoAcessorioAdministrativo, '')
def doc_texto_integral(request, pk): def doc_texto_integral(request, pk):
can_see = True can_see = True
@ -519,159 +515,55 @@ class PesquisarDocumentoAdministrativoView(DocumentoAdministrativoMixin,
return self.render_to_response(context) return self.render_to_response(context)
class DetailDocumentoAdministrativo(PermissionRequiredMixin, DetailView): class TramitacaoAdmCrud(MasterDetailCrud):
template_name = "protocoloadm/detail_doc_adm.html" model = TramitacaoAdministrativo
permission_required = ('protocoloadm.detail_documentoadministrativo', ) parent_field = 'documento'
help_path = ''
def get(self, request, *args, **kwargs):
documento = DocumentoAdministrativo.objects.get(
id=self.kwargs['pk'])
form = DocumentoAdministrativoForm(
instance=documento)
return self.render_to_response({
'form': form,
'pk': kwargs['pk']})
def post(self, request, *args, **kwargs):
if 'Salvar' in request.POST:
form = DocumentoAdministrativoForm(request.POST)
if form.is_valid():
doc = form.save(commit=False)
if 'texto_integral' in request.FILES:
doc.texto_integral = request.FILES['texto_integral']
doc.save()
return self.form_valid(form)
else:
return self.render_to_response({'form': form})
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('sapl.protocoloadm:pesq_doc_adm')
def get_success_url(self):
return reverse('sapl.protocoloadm:detail_doc_adm', kwargs={
'pk': self.kwargs['pk']})
class DocumentoAcessorioAdministrativoEditView(PermissionRequiredMixin,
FormView):
template_name = "protocoloadm/documento_acessorio_administrativo_edit.html"
permission_required = (
'protocoloadm.change_documentoacessorioadministrativo', )
def get(self, request, *args, **kwargs): class BaseMixin(MasterDetailCrud.BaseMixin):
doc = DocumentoAdministrativo.objects.get( list_field_names = ['data_tramitacao', 'unidade_tramitacao_local',
id=kwargs['pk']) 'unidade_tramitacao_destino', 'status']
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): class CreateView(MasterDetailCrud.CreateView):
pk = self.kwargs['pk'] form_class = TramitacaoAdmForm
return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk})
class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoAdmEditForm
class DocumentoAcessorioAdministrativoView(PermissionRequiredMixin, FormView): class ListView(DocumentoAdministrativoMixin, MasterDetailCrud.ListView):
template_name = "protocoloadm/documento_acessorio_administrativo.html"
permission_required = (
'protocoloadm.add_documentoacessorioadministrativo', )
def get(self, request, *args, **kwargs): def get_queryset(self):
form = DocumentoAcessorioAdministrativoForm() qs = super(MasterDetailCrud.ListView, self).get_queryset()
doc = DocumentoAdministrativo.objects.get( kwargs = {self.crud.parent_field: self.kwargs['pk']}
id=kwargs['pk']) return qs.filter(**kwargs).order_by('-data_tramitacao', '-id')
doc_ace_null = ''
doc_acessorio = DocumentoAcessorioAdministrativo.objects.filter(
documento_id=kwargs['pk'])
if not doc_acessorio:
doc_ace_null = _('Nenhum documento acessório' +
'cadastrado para este processo.')
return self.render_to_response({'pk': kwargs['pk'],
'doc': doc,
'doc_ace': doc_acessorio,
'doc_ace_null': doc_ace_null,
'form': form})
def post(self, request, *args, **kwargs):
form = DocumentoAcessorioAdministrativoForm(request.POST)
if form.is_valid():
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_ace.documento = doc
doc_ace.save()
return self.form_valid(form)
else:
return self.form_invalid(form)
def get_success_url(self): class DetailView(DocumentoAdministrativoMixin,
pk = self.kwargs['pk'] MasterDetailCrud.DetailView):
return reverse('sapl.protocoloadm:doc_ace_adm', kwargs={'pk': pk}) pass
class TramitacaoAdmCrud(MasterDetailCrud): class DocumentoAcessorioAdministrativoCrud(MasterDetailCrud):
model = TramitacaoAdministrativo model = DocumentoAcessorioAdministrativo
parent_field = 'documento' parent_field = 'documento'
help_path = '' help_path = ''
class BaseMixin(MasterDetailCrud.BaseMixin): class BaseMixin(MasterDetailCrud.BaseMixin):
list_field_names = ['data_tramitacao', 'unidade_tramitacao_local', list_field_names = ['nome', 'tipo',
'unidade_tramitacao_destino', 'status'] 'data', 'autor',
'assunto']
class CreateView(MasterDetailCrud.CreateView): class CreateView(MasterDetailCrud.CreateView):
form_class = TramitacaoAdmForm form_class = DocumentoAcessorioAdministrativoForm
class UpdateView(MasterDetailCrud.UpdateView): class UpdateView(MasterDetailCrud.UpdateView):
form_class = TramitacaoAdmEditForm form_class = DocumentoAcessorioAdministrativoForm
class ListView(DocumentoAdministrativoMixin, MasterDetailCrud.ListView): class ListView(DocumentoAdministrativoMixin, MasterDetailCrud.ListView):
def get_queryset(self): def get_queryset(self):
qs = super(MasterDetailCrud.ListView, self).get_queryset() qs = super(MasterDetailCrud.ListView, self).get_queryset()
kwargs = {self.crud.parent_field: self.kwargs['pk']} kwargs = {self.crud.parent_field: self.kwargs['pk']}
return qs.filter(**kwargs).order_by('-data_tramitacao', '-id') return qs.filter(**kwargs).order_by('-data', '-id')
class DetailView(DocumentoAdministrativoMixin, class DetailView(DocumentoAdministrativoMixin,
MasterDetailCrud.DetailView): MasterDetailCrud.DetailView):

3
sapl/templates/protocoloadm/layouts.yaml

@ -16,9 +16,8 @@ DocumentoAdministrativo:
DocumentoAcessorioAdministrativo: DocumentoAcessorioAdministrativo:
{% trans 'Documento Acessório' %}: {% trans 'Documento Acessório' %}:
- documento tipo - tipo autor
- nome data - nome data
- autor
- arquivo - arquivo
- assunto - assunto

2
sapl/templates/protocoloadm/subnav.yaml

@ -3,3 +3,5 @@
url: documentoadministrativo_detail url: documentoadministrativo_detail
- title: {% trans 'Tramitação' %} - title: {% trans 'Tramitação' %}
url: tramitacaoadministrativo_list url: tramitacaoadministrativo_list
- title: {% trans 'Documento Acessório' %}
url: documentoacessorioadministrativo_list

Loading…
Cancel
Save