Skip to content
Snippets Groups Projects

Resolve "PDF export for timetables"

Merged Julian requested to merge 51-pdf-export-for-timetables into master
1 file
+ 5
12
Compare changes
  • Side-by-side
  • Inline
@@ -17,9 +17,9 @@ from django_tables2 import RequestConfig
from rules.contrib.views import permission_required
from aleksis.core.models import Announcement, Group, Person
from aleksis.core.settings import STATIC_ROOT
from aleksis.core.util import messages
from aleksis.core.util.core_helpers import get_site_preferences, has_person
from aleksis.core.util.pdf import render_pdf
from .forms import LessonSubstitutionForm
from .managers import TimetableType
@@ -196,17 +196,10 @@ def timetable(
if is_print:
template_name = "chronos/timetable_print.html"
template = get_template(template_name)
html_template = render_to_string(template_name, context).replace("/static", STATIC_ROOT)
f, path = mkstemp(".html")
print(path)
with open(path, "w") as f:
f.write(html_template)
f2, path2 = mkstemp(".pdf")
subprocess.run(["electron-pdf", path, path2])
file = open(path2, "rb")
return FileResponse(file, content_type="application/pdf")
context["back_url"] = reverse(
"timetable_by_week", args=[type_.value, pk, wanted_week.year, wanted_week.week],
)
return render_pdf(request, template_name, context)
else:
template_name = "chronos/timetable.html"
Loading