diff --git a/sapl/materia/urls.py b/sapl/materia/urls.py index 9bd03278d..9f774a3d3 100644 --- a/sapl/materia/urls.py +++ b/sapl/materia/urls.py @@ -20,7 +20,7 @@ from sapl.materia.views import (AcompanhamentoConfirmarView, TipoFimRelatoriaCrud, TipoMateriaCrud, TipoProposicaoCrud, TramitacaoCrud, TramitacaoEmLoteView, UnidadeTramitacaoCrud, - recuperar_materia) + proposicao_texto, recuperar_materia) from .apps import AppConfig @@ -90,6 +90,10 @@ urlpatterns_proposicao = [ url(r'^proposicao/(?P[0-9]+)/ta$', ProposicaoTaView.as_view(), name='proposicao_ta'), + + + url(r'^proposicao/texto/(?P\d+)$', proposicao_texto, + name='proposicao_texto'), ] urlpatterns_sistema = [ diff --git a/sapl/materia/views.py b/sapl/materia/views.py index 75f4ee4bb..594ae1a56 100644 --- a/sapl/materia/views.py +++ b/sapl/materia/views.py @@ -10,7 +10,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin from django.core.exceptions import ObjectDoesNotExist from django.core.mail import send_mail from django.core.urlresolvers import reverse -from django.http import JsonResponse +from django.http import HttpResponse, JsonResponse from django.http.response import Http404, HttpResponseRedirect from django.shortcuts import get_object_or_404, redirect from django.template import Context, loader @@ -79,6 +79,33 @@ def autores_ja_adicionados(materia_pk): return pks +def proposicao_texto(request, pk): + proposicao = Proposicao.objects.get(pk=pk) + + if proposicao.texto_original: + if not proposicao.data_recebimento: + if proposicao.autor.user_id != request.user.id: + raise Http404 + + arquivo = proposicao.texto_original + + 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 AdicionarVariasAutorias(PermissionRequiredForAppCrudMixin, FilterView): app_label = sapl.materia.apps.AppConfig.label filterset_class = AdicionarVariasAutoriasFilterSet diff --git a/sapl/templates/materia/proposicao_detail.html b/sapl/templates/materia/proposicao_detail.html index 61669d168..007b63b6b 100644 --- a/sapl/templates/materia/proposicao_detail.html +++ b/sapl/templates/materia/proposicao_detail.html @@ -7,7 +7,7 @@ {% trans "Texto EletrĂ´nico" %} {% endif %} {% if object.texto_original %} - {% trans "Texto Original" %} + {% trans "Texto Original" %} {% endif %} {% endblock sub_actions%}