Skip to content
Snippets Groups Projects
Commit 256a88b8 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch 'dev' into merge/dashboard-cache

# Conflicts:
#	.idea/misc.xml
#	requirements.txt
#	schoolapps/dashboard/urls.py
#	schoolapps/dashboard/views.py
#	schoolapps/schoolapps/settings.py
#	schoolapps/schoolapps/urls.py
#	schoolapps/templates/partials/header.html
#	schoolapps/timetable/views.py
parents 5c075838 cd238b86
No related branches found
No related tags found
No related merge requests found
......@@ -21,16 +21,26 @@ def generate_pdf(tex, filename):
# Execute pdflatex to generate the PDF
bash_command = "pdflatex -halt-on-error -output-directory {} {}.tex".format(os.path.join(BASE_DIR, "latex"),
os.path.join(BASE_DIR, "latex",
filename))
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
del output
filename))
run_args = list(bash_command.split())
# Execute two times to get number of last page
subprocess.run(run_args, stdout=None)
process = subprocess.run(run_args, stdout=None)
# Register log file in debugging tool
register_log_with_filename("latex_{}".format(filename), "latex", "{}.log".format(filename), process.returncode)
def generate_class_tex_header():
"""Generate LaTeX for a PDF by a substitution table"""
context = {
"LOGO_FILENAME": LOGO_FILENAME,
}
return render_to_string("timetable/latex/header.tex", context)
def generate_class_tex(subs, date, header_info, hints=None):
def generate_class_tex_body(subs, date, header_info, hints=None):
"""Generate LaTeX for a PDF by a substitution table"""
context = {
......@@ -40,4 +50,4 @@ def generate_class_tex(subs, date, header_info, hints=None):
"LOGO_FILENAME": LOGO_FILENAME,
"hints": hints
}
return render_to_string("timetable/latex/substitutions.tex", context)
return render_to_string("timetable/latex/substitutions.tex", context)
\ No newline at end of file
\documentclass[11pt]{article}
\usepackage[ngerman]{babel}
\usepackage[sfdefault]{cabin}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,left=1cm,right=1cm,top=2cm,bottom=2.8cm,bindingoffset=0mm]{geometry}
% Packages
\usepackage{fancyhdr}
\usepackage{lastpage}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{color, colortbl}
\usepackage[colorlinks, linkcolor = black, citecolor = black, filecolor = black, urlcolor = black]{hyperref}
\usepackage{ulem, xpatch}
\xpatchcmd{\sout}
{\bgroup}
{\bgroup\def\ULthickness{1.5pt}}
{}{}
% Badge box
\usepackage{tcolorbox}
\newtcbox{\badge}{nobeforeafter,colframe=green,colback=green,boxrule=0.5pt,arc=4pt,
boxsep=0pt,left=4pt,right=4pt,top=4pt,bottom=4pt,tcbox raise base,
grow to left by=0pt,
grow to right by=-3pt,
enlarge top by=3pt,
enlarge bottom by=3pt,coltext=white}
% Define colors
\definecolor{ grey }{RGB}{208, 208, 208}
\definecolor{ darkgrey }{rgb}{0.6,0.6,0.6}
\definecolor{ white }{rgb}{1,1,1}
\definecolor{ green }{RGB}{76,175,80}
\definecolor{green}{RGB}{76,175,80}
\definecolor{ blue }{RGB}{41,7,249}
\definecolor{ black }{RGB}{0,0,0}
\definecolor{ purple }{RGB}{156, 39, 176}
% Define header
\pagestyle{fancy}
% Left header: logo
\lhead{\includegraphics[width=5cm]{% templatetag openbrace %}{{LOGO_FILENAME}}{% templatetag closebrace %}}
% Define footer
\lfoot{Katharineum zu Lübeck}
\cfoot{\thepage}%\ von \pageref{LastPage}}
\rfoot{\small Umsetzung: © 2018--2019 by Computer-AG}
\rhead{\textbf{
Vertretungen }\\
Stand: {% now "j. F Y H:i" %}\\
}
% Define own commands
%% tightlist from pandoc is missing in default.latex
%% see https://tex.stackexchange.com/questions/257418/error-tightlist-converting-md-file-into-pdf-using-pandoc
\providecommand{\tightlist}{%
\setlength{\itemsep}{0pt}\setlength{\parskip}{0pt}}
\begin{document}
{% load common %}
{% load tex %}
\documentclass[11pt]{article}
\usepackage[ngerman]{babel}
\usepackage[sfdefault]{cabin}
\usepackage[utf8]{inputenc}
\usepackage[a4paper,left=1cm,right=1cm,top=1.5cm,bottom=1.5cm,bindingoffset=0mm]{geometry}
% Packages
\usepackage{fancyhdr}
\usepackage{graphicx}
\usepackage{longtable}
\usepackage{booktabs}
\usepackage{multirow}
\usepackage{color, colortbl}
\usepackage[colorlinks, linkcolor = black, citecolor = black, filecolor = black, urlcolor = black]{hyperref}
\usepackage{ulem, xpatch}
\xpatchcmd{\sout}
{\bgroup}
{\bgroup\def\ULthickness{1.5pt}}
{}{}
% Badge box
\usepackage{tcolorbox}
\newtcbox{\badge}{nobeforeafter,colframe=green,colback=green,boxrule=0pt,arc=2pt,
boxsep=0pt,left=4pt,right=4pt,top=2pt,bottom=3pt,tcbox raise base,
grow to left by=0pt,
grow to right by=-3pt,
enlarge top by=1pt,
enlarge bottom by=1pt,coltext=white}
% Define colors
\definecolor{grey}{RGB}{208, 208, 208}
\definecolor{darkgrey}{rgb}{0.6,0.6,0.6}
\definecolor{white}{rgb}{1,1,1}
\definecolor{ green }{RGB}{76,175,80}
\definecolor{green}{RGB}{76,175,80}
\definecolor{ black }{RGB}{0,0,0}
\definecolor{purple}{RGB}{156, 39, 176}
% Define header
\pagestyle{fancy}
% Left header: logo
\lhead{\includegraphics[width=5cm]{% templatetag openbrace %}{{LOGO_FILENAME}}{% templatetag closebrace %}}
% Define footer
\lfoot{Katharineum zu Lübeck}
\cfoot{}
\rfoot{\small Umsetzung: © 2018--2019 by Computer-AG}
\rhead{\textbf{
Vertretungen {{ date|date:"j. F Y, \\K\\W W"}}}\\
Stand: {% now "j. F Y H:i" %}\\
}
\begin{document}
\large
\subsubsection*{}
\section*{\Huge Vertretungen {{ date|date:"l, j. F Y"}}}
{% include "timetable/latex/hints.tex" %}
{% if header_info.is_box_needed %}
\begin{tabular}{@{\hspace{-1em}}p{0.22\linewidth}p{0.73\linewidth}}
{% for row in header_info.rows %}
\textbf{ {{ row.0 }} } & {{ row.1 }} \\
{% endfor %}
\end{tabular}
{% endif %}
% Init table
{% set color_background = 1 %}
{% set last_classes = "" %}
\def\arraystretch{1.1}
\begin{longtable}{p{20mm}p{10mm}p{30mm}p{25mm}p{30mm}p{45mm}}
\textbf{Klassen} &
\textbf{Std.} &
\textbf{Lehrer} &
\textbf{Fach} &
\textbf{Raum} &
\textbf{Hinweis}\\
\hline
\endhead
{% for sub in subs %}
{# ------------------------------ #}
\large
\subsubsection*{}
\section*{\Huge Vertretungen {{ date|date:"l, j. F Y"}}}
{% include "timetable/latex/hints.tex" %}
{% if header_info.is_box_needed %}
\begin{tabular}{@{\hspace{-1em}}p{0.22\linewidth}p{0.73\linewidth}}
{% for row in header_info.rows %}
\textbf{ {{ row.0 }} } & {{ row.1 }} \\
{% endfor %}
\end{tabular}
{% endif %}
% Init table
{% set color_background = 1 %}
{% set last_classes = "" %}
\def\arraystretch{1.1}
\begin{longtable}{p{20mm}p{10mm}p{30mm}p{25mm}p{30mm}p{45mm}}
\textbf{Klassen} & \textbf{Std.} & \textbf{Lehrer} & \textbf{Fach} & \textbf{Raum} & \textbf{Hinweis}\\\hline
\endhead
{% for sub in subs %}
{# Color groups of classes in grey/white #}
{% if last_classes != sub.classes %}
{% if color_background %}
{% set color_background = 0 %}
{% else %}
{% set color_background = 1 %}
{% endif %}
{% if color_background %}{% set color_background = 0 %}
{% else %}{% set color_background = 1 %}
{% endif %}
{% endif %}
{% set last_classes = sub.classes %}
{# Background color #}
{% if color_background %}
\rowcolor{grey}
{% endif %}
{# ------------------------------ #}
{% if color_background %}\rowcolor{ grey }{% endif %}
{% with c=sub.color %}
{# Display classes #}
\color{ {{c}}}
\textbf{ {{ sub.classes }} } &
{# Display lesson number #}
\color{ {{c}}}
{{ sub.lesson }} &
\color{ {{c}}} {% include "timetable/latex/teacher.tex" %} &
\color{ {{c}}} {% include "timetable/latex/subject.tex" %} &
\color{ {{c}}} {% include "timetable/latex/room.tex" %} &
{# Display badge (for cancellations) #} {# Display notice and new line #}
{% if sub.badge %}
\footnotesize\badge{ {{ sub.badge }} }
{% endif %} \color{ {{c}}} \large\textit{ {{sub.text|default:""|safe|texify|safe}} } \\
{% endwith %}
{# Display classes #}
\color{ {{c}} }\textbf{ {{ sub.classes }} } &
{# Display lesson number #}
\color{ {{c}} } {{ sub.lesson }} &
\color{ {{c}} } {% include "timetable/latex/teacher.tex" %} &
\color{ {{c}} } {% include "timetable/latex/subject.tex" %} &
\color{ {{c}} } {% include "timetable/latex/room.tex" %} &
{# Display badge (for cancellations) #} {# Display notice and new line #}
{% if sub.badge %} \footnotesize\badge{ {{ sub.badge }} } {% endif %}
\color{ {{c}} } \large\textit{ {{sub.text|default:""|safe|texify|safe}} } \\
{% endwith %}
{% endfor %}
\end{longtable}
\end{longtable}
\end{document}
......@@ -200,6 +200,10 @@
<span class="card-title">
{{ day.0.0 }}
</span>
{% if day.1 %}
<span class="badge new blue center-align holiday-badge">{{ day.1.0 }}</span>
{% endif %}
&nbsp;
</div>
</div>
{% for row, time in plan|deepcopy %}
......
......@@ -18,6 +18,10 @@ from timetable.forms import HintForm
from timetable.hints import get_all_hints_by_time_period, get_all_hints_by_class_and_time_period, \
get_all_hints_for_teachers_by_time_period, get_all_hints_not_for_teachers_by_time_period
from timetable.pdf import generate_class_tex, generate_pdf
from timetable.pdf import generate_class_tex_header, generate_class_tex_body, generate_pdf
from untisconnect.plan import get_plan, TYPE_TEACHER, TYPE_CLASS, TYPE_ROOM, parse_lesson_times
from untisconnect.sub import get_substitutions_by_date, generate_sub_table, get_header_information, SubRow
from untisconnect.api import *
from untisconnect.datetimeutils import get_calendar_week, get_calendar_weeks, get_next_weekday, find_out_what_is_today, \
get_next_weekday_with_time
......@@ -137,8 +141,8 @@ def plan(request, plan_type, plan_id, regular="", year=None, calendar_week=None)
"weeks": get_calendar_weeks(year=year),
"selected_week": calendar_week,
"selected_year": year,
"short_week_days": zip(SHORT_WEEK_DAYS, holidays),
"long_week_days": zip(LONG_WEEK_DAYS, holidays),
"short_week_days": zip(SHORT_WEEK_DAYS, holidays) if smart else zip(SHORT_WEEK_DAYS),
"long_week_days": zip(LONG_WEEK_DAYS, holidays) if smart else zip(LONG_WEEK_DAYS),
"holidays": holidays,
"hints": hints,
"hints_b": hints_b,
......@@ -283,6 +287,7 @@ def sub_pdf(request, plan_date=None):
first_day = get_next_weekday_with_time(today, today.time())
second_day = get_next_weekday(first_day + datetime.timedelta(days=1))
tex = generate_class_tex_header()
# Get subs and generate table
for i, date in enumerate([first_day, second_day]):
# Get subs and generate table
......@@ -299,29 +304,30 @@ def sub_pdf(request, plan_date=None):
# latex = convert_markdown_2_latex(hints[0].text)
# print(latex)
# Generate LaTeX
tex = generate_class_tex(sub_table, date, header_info, hints)
# Generate PDF
generate_pdf(tex, "aktuell{}".format(i))
# Merge PDFs
try:
merger = PdfFileMerger()
class0 = open(os.path.join(BASE_DIR, "latex", "aktuell0.pdf"), "rb")
class1 = open(os.path.join(BASE_DIR, "latex", "aktuell1.pdf"), "rb")
merger.append(fileobj=class0)
merger.append(fileobj=class1)
# Write merged PDF to aktuell.pdf
output = open(os.path.join(BASE_DIR, "latex", "aktuell.pdf"), "wb")
merger.write(output)
output.close()
# Register successful merge in debugging tool
register_return_0("merge_class", "pypdf2")
except Exception:
# Register exception in debugging tool
register_traceback("merge_class", "pypdf2")
tex += generate_class_tex_body(sub_table, date, header_info, hints)
tex += "\end{document}"
# Generate PDF
generate_pdf(tex, "aktuell")
# # Merge PDFs
# try:
# merger = PdfFileMerger()
# class0 = open(os.path.join(BASE_DIR, "latex", "aktuell0.pdf"), "rb")
# class1 = open(os.path.join(BASE_DIR, "latex", "aktuell1.pdf"), "rb")
# merger.append(fileobj=class0)
# merger.append(fileobj=class1)
#
# # Write merged PDF to aktuell.pdf
# output = open(os.path.join(BASE_DIR, "latex", "aktuell.pdf"), "wb")
# merger.write(output)
# output.close()
#
# # Register successful merge in debugging tool
# register_return_0("merge_class", "pypdf2")
# except Exception:
# # Register exception in debugging tool
# register_traceback("merge_class", "pypdf2")
# Read and response PDF
file = open(os.path.join(BASE_DIR, "latex", "aktuell.pdf"), "rb")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment