fix access to PDF protocol as a non FET user.

This commit is contained in:
2021-06-07 19:03:39 +00:00
parent 9e855cf877
commit 02960099fd
12 changed files with 54 additions and 30 deletions

View File

@@ -10,6 +10,7 @@ from django.utils import timezone
from django.utils.text import slugify
from taggit.models import Tag
from authentications.decorators import authenticated_user
from documents.api import get_pad_link
from documents.etherpadlib import add_ep_cookie
from members.models import Member, JobMember
@@ -191,16 +192,7 @@ def show(request, id=None):
return response
def show_pdf(self, id, filename=None):
p = __get_post_object(id)
# it works but not a nice solution
html = ""
if "agenda" in filename:
html = p.agenda_html
elif "protokoll" in filename:
html = p.protocol_html
def show_pdf(request, html, filename):
rendered = render_to_string(settings.BASE_DIR + "/templates/posts/pdf/template.html")
# get body-content from pdf template
@@ -212,7 +204,31 @@ def show_pdf(self, id, filename=None):
html = html[:idx] + rendered + html[idx:]
pdf = render_to_pdf(html)
return HttpResponse(pdf, content_type='application/pdf')
if not pdf:
raise Http404("can't create pdf file")
response = HttpResponse(pdf, content_type='application/pdf')
content = "inline; filename=%s" % filename
response['Content-Disposition'] = content
return response
def show_pdf_agenda(request, id):
p = __get_post_object(id)
html = p.agenda_html
return show_pdf(request, html, p.slug + "-agenda")
@authenticated_user
def show_pdf_protocol(request, id):
p = __get_post_object(id)
html = p.protocol_html
return show_pdf(request, html, p.slug + "-protokoll")
###########