fix access to PDF protocol as a non FET user.
This commit is contained in:
@@ -204,7 +204,7 @@ class Post(models.Model):
|
||||
|
||||
@property
|
||||
def url(self):
|
||||
return reverse("posts.show", kwargs={"id": self.slug})
|
||||
return reverse("posts:posts.show", kwargs={"id": self.slug})
|
||||
|
||||
def get_absolute_url(self):
|
||||
return self.url
|
||||
|
||||
@@ -1,7 +1,10 @@
|
||||
from django.urls import path
|
||||
from django.urls import path, re_path
|
||||
from . import apps
|
||||
from . import views
|
||||
|
||||
|
||||
app_name = apps.PostsConfig.name
|
||||
|
||||
urlpatterns = [
|
||||
path("func/tag_complete", views.tag_complete),
|
||||
path("func/slug_calc", views.slug_calc),
|
||||
@@ -9,5 +12,6 @@ urlpatterns = [
|
||||
path("", views.index, name="posts.index"),
|
||||
path("fet_calendar.ics", views.calendar, name="posts.calendar"),
|
||||
path("<str:id>", views.show, name="posts.show"),
|
||||
path("<str:id>/<str:filename>", views.show_pdf, name="posts.show_pdf"),
|
||||
re_path(r"^(?P<id>[-\w]+)/agenda.pdf$", views.show_pdf_agenda, name="show_pdf_agenda"),
|
||||
re_path(r"^(?P<id>[-\w]+)/protokoll.pdf$", views.show_pdf_protocol, name="show_pdf_protocol"),
|
||||
]
|
||||
|
||||
@@ -4,10 +4,12 @@ from xhtml2pdf import pisa
|
||||
|
||||
|
||||
def render_to_pdf(html):
|
||||
result = BytesIO()
|
||||
pdf = pisa.pisaDocument(BytesIO(html.encode("ISO-8859-1")), result)
|
||||
src = BytesIO(html.encode("ISO-8859-1"))
|
||||
dest = BytesIO()
|
||||
|
||||
pdf = pisa.pisaDocument(src, dest)
|
||||
|
||||
if not pdf.err:
|
||||
return HttpResponse(result.getvalue(), content_type='application/pdf')
|
||||
return HttpResponse(dest.getvalue(), content_type='application/pdf')
|
||||
|
||||
return None
|
||||
|
||||
@@ -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")
|
||||
|
||||
|
||||
###########
|
||||
|
||||
@@ -86,7 +86,7 @@
|
||||
{% include 'posts/partials/_date_box.html' %}
|
||||
{% endfor %}
|
||||
|
||||
<a href="{% url 'posts.calendar' %}">
|
||||
<a href="{% url 'posts:posts.calendar' %}">
|
||||
<div class="social-media-box">
|
||||
<span class="social-media-badge badge">
|
||||
<span class="social-media-badge-symbol">
|
||||
@@ -100,7 +100,7 @@
|
||||
|
||||
</div>
|
||||
|
||||
<a class="button" href="{% url 'posts.index' %}" style="background: gray">Mehr anzeigen</a>
|
||||
<a class="button" href="{% url 'posts:posts.index' %}" style="background: gray">Mehr anzeigen</a>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
@@ -55,7 +55,7 @@
|
||||
<li><a class="button header-intern-btn header-intern-link" href="{% url 'tasks' %}">Tasks</a></li>
|
||||
<li><a class="button header-intern-btn header-intern-link" href="https://legacy.fet.at/home/intern">Intern</a></li>
|
||||
{% endif %}
|
||||
<li><a class="button header-btn header-link" href="{% url 'posts.index' %}">News</a></li>
|
||||
<li><a class="button header-btn header-link" href="{% url 'posts:posts.index' %}">News</a></li>
|
||||
<!-- show active members first -->
|
||||
<li><a class="button header-btn header-link" href="{% url 'members' %}A">Fachschaft</a></li>
|
||||
<li><a class="button header-btn header-link" href="/fotos/">Fotos</a></li>
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
<a href ="/posts/{{post.slug}}">
|
||||
<a href="{{ post.url }}">
|
||||
<div class="date-box">
|
||||
<span>
|
||||
<span class="date-badge badge primary" style="">
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<a href="{% url 'posts.show' post.slug %}">
|
||||
<a href="{{ post.url }}">
|
||||
<div class="news-hero padding-bottom-1" style="background-image:url('{{ post.imageurl }}')">
|
||||
<div class="news-hero-text">
|
||||
<h1>{{ post.title | safe }}</h1>
|
||||
<h2>{{ post.subtitle|default_if_none:" " }}</h2>
|
||||
|
||||
{% if post.post_type != 'N' %}
|
||||
<p>{{ post.event_start|date:"d. F Y" }}</p>
|
||||
{% else %}
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
<a href="{% url 'posts.show' post.slug %}">
|
||||
<a href="{{ post.url }}">
|
||||
<div class="news-hero-compact">
|
||||
<div class="news-hero-compact-text">
|
||||
<p style="margin-bottom: 0rem;">{{ post.title | safe }}</p>
|
||||
</div>
|
||||
|
||||
<div class="news-hero-compact-right">
|
||||
{% if post.post_type != 'N' %}
|
||||
<p style="margin-bottom: 0rem;">{{ post.event_start|date:"d. F Y" }}</p>
|
||||
|
||||
@@ -78,7 +78,7 @@
|
||||
|
||||
</div>
|
||||
<div class="cell medium-4">
|
||||
<a href="{% url 'posts.show' next %}">Nächster Artikel <span class="nav fa fa-chevron-right fa-1x"></span></a><br>
|
||||
<a href="{% url 'posts:posts.show' next %}">Nächster Artikel <span class="nav fa fa-chevron-right fa-1x"></span></a><br>
|
||||
|
||||
{% if request.user.is_authenticated %}
|
||||
<hr>
|
||||
@@ -86,7 +86,7 @@
|
||||
{% if post.has_agenda %}
|
||||
<a href="{{ ep_agenda_link }}">Agenda</a>
|
||||
{% if filename_agenda %}
|
||||
<a href="{% url 'posts.show_pdf' post.slug filename_agenda %}">
|
||||
<a href="{% url 'posts:show_pdf_agenda' post.slug %}">
|
||||
<i class="far fa-file-pdf"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
@@ -96,7 +96,7 @@
|
||||
{% if post.has_protocol %}
|
||||
<a href="{{ ep_protocol_link }}">Protokoll</a>
|
||||
{% if filename_protocol %}
|
||||
<a href="{% url 'posts.show_pdf' post.slug filename_protocol %}">
|
||||
<a href="{% url 'posts:show_pdf_protocol' post.slug %}">
|
||||
<i class="far fa-file-pdf"></i>
|
||||
</a>
|
||||
{% endif %}
|
||||
|
||||
Reference in New Issue
Block a user