Browse Source

Cria função para recuperação do texto integral de documento

pull/919/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
23ffae0833
  1. 5
      sapl/protocoloadm/urls.py
  2. 40
      sapl/protocoloadm/views.py

5
sapl/protocoloadm/urls.py

@ -16,7 +16,7 @@ from sapl.protocoloadm.views import (AnularProtocoloAdmView,
ProtocoloPesquisaView,
StatusTramitacaoAdministrativoCrud,
TipoDocumentoAdministrativoCrud,
TramitacaoAdmCrud)
TramitacaoAdmCrud, doc_texto_integral)
from .apps import AppConfig
@ -38,6 +38,9 @@ urlpatterns_documento_administrativo = [
url(r'^docadm/doc-ace-adm/edit/(?P<pk>\d+)/(?P<ano>\d+)',
DocumentoAcessorioAdministrativoEditView.as_view(),
name='doc_ace_adm_edit'),
url(r'^doc/texto_integral/(?P<pk>\d+)$', doc_texto_integral,
name='doc_texto_integral'),
]
urlpatterns_protocolo = [

40
sapl/protocoloadm/views.py

@ -6,7 +6,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist
from django.core.urlresolvers import reverse
from django.db.models import Max
from django.http import HttpResponseRedirect
from django.http import Http404, HttpResponse, HttpResponseRedirect
from django.shortcuts import redirect
from django.utils.translation import ugettext_lazy as _
from django.views.generic import CreateView, DetailView, FormView, ListView
@ -40,6 +40,36 @@ DocumentoAcessorioAdministrativoCrud = Crud.build(
DocumentoAcessorioAdministrativo, '')
def doc_texto_integral(request, pk):
can_see = True
if not request.user.is_authenticated():
app_config = sapl.base.models.AppConfig.objects.last()
if app_config and app_config.documentos_administrativos == 'R':
can_see = False
if can_see:
documento = DocumentoAdministrativo.objects.get(pk=pk)
if documento.texto_integral:
arquivo = documento.texto_integral
ext = arquivo.name.split('.')[-1]
mime = ''
if ext == 'odt':
mime = 'application/vnd.oasis.opendocument.text'
else:
mime = "application/%s" % (ext,)
with open(arquivo.path, 'rb') as f:
data = f.read()
response = HttpResponse(data, content_type='%s' % mime)
response['Content-Disposition'] = (
'inline; filename="%s"' % arquivo.name.split('/')[-1])
return response
raise Http404
class DocumentoAdministrativoMixin:
def has_permission(self):
@ -63,7 +93,13 @@ class DocumentoAdministrativoCrud(Crud):
pass
class DetailView(DocumentoAdministrativoMixin, Crud.DetailView):
pass
def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
self.layout_display[0]['rows'][-1][0]['text'] = (
'<a href="%s"></a>' % reverse(
'sapl.protocoloadm:doc_texto_integral',
kwargs={'pk': self.object.pk}))
return context
class StatusTramitacaoAdministrativoCrud(CrudAux):

Loading…
Cancel
Save