Skip to content

Commit 8b82e55

Browse files
committed
implement pre_render for coursebook and latex templates
1 parent df41bd9 commit 8b82e55

5 files changed

Lines changed: 49 additions & 13 deletions

File tree

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,15 @@
1-
\textbf{This is an image}
2-
{{content.description}}
1+
{% load cc_export_tags %}
2+
{% autoescape off %}
3+
4+
\textbf{ {{content.description}} }
5+
{{content.imagecontent.image.path|tex_escape}}
6+
7+
\includegraphics{ {{ content.imagecontent.image.path }} }
8+
9+
%\begin{figure}[H]
10+
%\centering
11+
%\includegraphics[width=\textwidth ext=.png]{ {{ content.imagecontent.image.url }} }
12+
%\caption{ {{content.description}} }
13+
%\end{figure}
14+
15+
{% endautoescape %}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
\textbf{This is a YouTube video}
1+
\textbf{This is a YouTube video}
2+
\href{ {{ content.ytvideocontent.url }} }{ {{ content.ytvideocontent.url }} }

content/templates/content/export/base.tex

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66
\usepackage[utf8]{inputenc}
77
\usepackage[T1]{fontenc}
88
\usepackage[ngerman]{babel}
9+
\usepackage{graphicx}
10+
\usepackage{float}
11+
\usepackage{grffile}
12+
\usepackage{hyperref}
913
\usepackage[left=1cm, right=1cm, top=2cm, bottom=2cm]{geometry}
1014

1115
\begin{document}
@@ -14,10 +18,8 @@
1418
\author{ {{user|tex_escape}} }
1519
\maketitle
1620

17-
{% for content in contents %}
18-
\input{ {{ content.type|export_template }} }
19-
{% endfor %}
20-
21-
\end{document}
21+
% {% for content in contents %}
22+
% \input{ {{ content.type|export_template }} }
23+
% {% endfor %}
2224

2325
{% endautoescape %}

export/helper_functions.py

Lines changed: 24 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,27 @@
55

66
from django.template.loader import get_template
77

8+
from export.templatetags.cc_export_tags import export_template
9+
810

911
class LaTeX:
10-
"""
11-
https://github.com/d120/pyophase/blob/master/ophasebase/helper.py
12-
Retrieved 10.08.2020
13-
"""
12+
13+
encoding = 'utf-8'
14+
1415
@staticmethod
1516
def render(context, template_name, assets, app='export', external_assets=None):
17+
"""
18+
https://github.com/d120/pyophase/blob/master/ophasebase/helper.py
19+
Retrieved 10.08.2020
20+
"""
21+
1622
template = get_template(template_name)
17-
rendered_tpl = template.render(context).encode('utf-8')
23+
rendered_tpl = template.render(context).encode(LaTeX.encoding)
24+
# prerender content templates
25+
for content in context['contents']:
26+
rendered_tpl += LaTeX.pre_render(content)
27+
rendered_tpl += "\end{document}".encode(LaTeX.encoding)
28+
1829
with tempfile.TemporaryDirectory() as tempdir:
1930
# for asset in assets:
2031
# shutil.copy(os.path.dirname(os.path.realpath(__file__)) + '/../' + app + '/assets/' + asset, tempdir)
@@ -29,3 +40,11 @@ def render(context, template_name, assets, app='export', external_assets=None):
2940
except FileNotFoundError:
3041
pdf = None
3142
return pdf, pdflatex_output
43+
44+
@staticmethod
45+
def pre_render(content):
46+
template = get_template(export_template(content.type))
47+
context = {'content': content}
48+
print(content.imagecontent.image.url)
49+
return template.render(context).encode(LaTeX.encoding)
50+

frontend/templates/frontend/coursebook/rendering-error.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,5 @@
99
{% block content %}
1010
<h1>Error</h1>
1111
<p>An error occured while generating your coursebook.</p>
12+
<p>{{ content }}</p>
1213
{% endblock %}

0 commit comments

Comments
 (0)