Browse Source

Método para validar acesso ao texto de proposição

pull/941/head
Eduardo Edson Batista Cordeiro Alves 8 years ago
parent
commit
d166ae4080
  1. 6
      sapl/materia/urls.py
  2. 29
      sapl/materia/views.py
  3. 2
      sapl/templates/materia/proposicao_detail.html

6
sapl/materia/urls.py

@ -20,7 +20,7 @@ from sapl.materia.views import (AcompanhamentoConfirmarView,
TipoFimRelatoriaCrud, TipoMateriaCrud, TipoFimRelatoriaCrud, TipoMateriaCrud,
TipoProposicaoCrud, TramitacaoCrud, TipoProposicaoCrud, TramitacaoCrud,
TramitacaoEmLoteView, UnidadeTramitacaoCrud, TramitacaoEmLoteView, UnidadeTramitacaoCrud,
recuperar_materia) proposicao_texto, recuperar_materia)
from .apps import AppConfig from .apps import AppConfig
@ -90,6 +90,10 @@ urlpatterns_proposicao = [
url(r'^proposicao/(?P<pk>[0-9]+)/ta$', url(r'^proposicao/(?P<pk>[0-9]+)/ta$',
ProposicaoTaView.as_view(), name='proposicao_ta'), ProposicaoTaView.as_view(), name='proposicao_ta'),
url(r'^proposicao/texto/(?P<pk>\d+)$', proposicao_texto,
name='proposicao_texto'),
] ]
urlpatterns_sistema = [ urlpatterns_sistema = [

29
sapl/materia/views.py

@ -10,7 +10,7 @@ from django.contrib.auth.mixins import PermissionRequiredMixin
from django.core.exceptions import ObjectDoesNotExist from django.core.exceptions import ObjectDoesNotExist
from django.core.mail import send_mail from django.core.mail import send_mail
from django.core.urlresolvers import reverse 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.http.response import Http404, HttpResponseRedirect
from django.shortcuts import get_object_or_404, redirect from django.shortcuts import get_object_or_404, redirect
from django.template import Context, loader from django.template import Context, loader
@ -79,6 +79,33 @@ def autores_ja_adicionados(materia_pk):
return pks 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): class AdicionarVariasAutorias(PermissionRequiredForAppCrudMixin, FilterView):
app_label = sapl.materia.apps.AppConfig.label app_label = sapl.materia.apps.AppConfig.label
filterset_class = AdicionarVariasAutoriasFilterSet filterset_class = AdicionarVariasAutoriasFilterSet

2
sapl/templates/materia/proposicao_detail.html

@ -7,7 +7,7 @@
<a class="btn btn-success" href="{% url 'sapl.materia:proposicao_ta' object.pk%}">{% trans "Texto Eletrônico" %}</a> <a class="btn btn-success" href="{% url 'sapl.materia:proposicao_ta' object.pk%}">{% trans "Texto Eletrônico" %}</a>
{% endif %} {% endif %}
{% if object.texto_original %} {% if object.texto_original %}
<a class="btn btn-success" href="{{ object.texto_original.url }}">{% trans "Texto Original" %}</a> <a class="btn btn-success" href="{% url 'sapl.materia:proposicao_texto' object.pk %}">{% trans "Texto Original" %}</a>
{% endif %} {% endif %}
</div> </div>
{% endblock sub_actions%} {% endblock sub_actions%}

Loading…
Cancel
Save