Skip to content
Snippets Groups Projects
Verified Commit 0f014e1c authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Remove old and unnecessary stuff (e. g. LaTeX stuff)

parent caa001d2
No related branches found
No related tags found
1 merge request!31Biscuit merge. Closes #53.
Showing
with 3 additions and 313 deletions
from django.contrib.auth.decorators import login_required
from django.shortcuts import render
@login_required
def fallback(request, *args, **kwargs):
return render(request, "timetable/fallback.html")
from django import forms
from django.db.models import Count
from django.utils.translation import ugettext_lazy as _
from django_select2.forms import ModelSelect2MultipleWidget
from django_select2.forms import ModelSelect2MultipleWidget, Select2Widget
from aleksis.core.models import Group, Person
from .models import LessonPeriod, LessonSubstitution, Room, Subject
class SelectForm(forms.Form):
group = forms.ModelChoiceField(
queryset=Group.objects.annotate(lessons_count=Count("lessons")).filter(lessons_count__gt=0),
label=_("Group"),
required=False,
widget=Select2Widget,
)
teacher = forms.ModelChoiceField(
queryset=Person.objects.annotate(lessons_count=Count("lessons_as_teacher")).filter(
lessons_count__gt=0
),
label=_("Teacher"),
required=False,
widget=Select2Widget,
)
room = forms.ModelChoiceField(
queryset=Room.objects.annotate(lessons_count=Count("lesson_periods")).filter(
lessons_count__gt=0
),
label=_("Room"),
required=False,
widget=Select2Widget,
)
from .models import LessonSubstitution
class LessonSubstitutionForm(forms.ModelForm):
......
import os
import subprocess
from debug.models import register_log_with_filename
from aleksis.settings import BASE_DIR
# from .models import register_log_with_filename
def convert_markdown_2_latex(s):
try:
# Write markdown file
md_file = open(os.path.join(BASE_DIR, "latex", "m2l.md"), "w", encoding="utf8")
md_file.write(s)
md_file.close()
# Execute pandoc to convert markdown to latex
bash_command = "pandoc --log={} --from markdown --to latex --output {} {}".format(
os.path.join(BASE_DIR, "latex", "m2l.log"),
os.path.join(BASE_DIR, "latex", "m2l.tex"),
os.path.join(BASE_DIR, "latex", "m2l.md"))
process = subprocess.Popen(bash_command.split(), stdout=subprocess.PIPE)
output = process.communicate()[0]
del output
# Register log file in debugging tool
register_log_with_filename("m2l", "m2l", "m2l.log", process.returncode)
# Read converted latex from file
tex_file = open(os.path.join(BASE_DIR, "latex", "m2l.tex"), "r", encoding="utf8")
r = tex_file.read()
tex_file.close()
# Replace some things
r = r.replace("\subparagraph", "\subsubsection")
r = r.replace("\paragraph", "\subsubsection")
r = r.replace("section", "section*")
# Return latex
return r
except Exception as e:
# Print error
print("[MD TO LATEX]", e)
return ""
import os
import subprocess
from django.template.loader import render_to_string
from aleksis.settings import BASE_DIR
from debug.models import register_log_with_filename
LOGO_FILENAME = os.path.join(BASE_DIR, "static", "common", "logo.png")
def generate_pdf(tex, filename):
"""Generate a PDF by LaTeX code"""
# Write LaTeX file
tex_file = open(os.path.join(BASE_DIR, "latex", filename + ".tex"), "w", encoding="utf8")
tex_file.write(tex)
tex_file.close()
# 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))
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_body(subs, date, header_info, hints=None):
"""Generate LaTeX for a PDF by a substitution table"""
context = {
"subs": subs,
"date": date,
"header_info": header_info,
"LOGO_FILENAME": LOGO_FILENAME,
"hints": hints
}
return render_to_string("timetable/latex/substitutions.tex", context)
{% extends 'core/base.html' %}
{% block content %}
<h3>{% blocktrans %}The timetables are currently unavailable.{% endblocktrans %}</h3>
{% endblock %}
\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 martortags %}
{% if hints %}
\subsection*{\hspace{0.7em}Hinweise}
\vspace{-0.7em}
\begin{itemize}
\setlength\itemsep{0.1em}
{% for hint in hints %}
\normalsize
\item \small
{{ hint.classes_formatted }}{% if hint.teachers and hint.classes.all %}, {% endif %}{% if hint.teachers %}Lehrkräfte{% endif %}:
\normalsize
{{ hint.text_as_latex|safe }}
{% endfor %}
\end{itemize}
{% endif %}
{% if not sub.is_event %}{% if sub.sub.type == 3 %}
{{ sub.sub.corridor.name }}
{% elif sub.sub.type == 1 or sub.sub.type == 2 %}
{% elif sub.sub.room_new and sub.sub.room_old %}
\sout{% templatetag openbrace %}{{ sub.sub.room_old.shortcode }}}
$\rightarrow$
{{ sub.sub.room_new.shortcode }}
{% elif sub.sub.room_new and not sub.sub.room_old %}
{{ sub.sub.room_new.shortcode }}
{% elif not sub.sub.room_new and not sub.sub.room_old %}
{% else %}
{{ sub.sub.room_old.shortcode }}
{% endif %}{% else %}
{% for room in sub.rooms %}{{ room.shortcode }}{% if not forloop.last %}, {% endif %}{% endfor %}
{% endif %}
{% if sub.is_event %}
Veranstaltung
{% elif sub.sub.type == 3 %}
Aufsicht
{% elif not sub.sub.subject_new and not sub.sub.subject_old %}
{% elif sub.sub.type == 1 or sub.sub.type == 2 %}
\sout{% templatetag openbrace %}{{ sub.sub.subject_old.shortcode }}}
{% elif sub.sub.subject_new and sub.sub.subject_old %}
\sout{% templatetag openbrace %}{{ sub.sub.subject_old.shortcode }}} $\rightarrow$ \textbf { {{ sub.sub.subject_new.shortcode }} }
{% elif sub.sub.subject_new and not sub.sub.subject_old %}
{{ sub.sub.subject_new.shortcode }}
{% else %}
{{ sub.sub.subject_old.shortcode }}
{% endif %}
{% load common %}
{% load tex %}
\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 %}
{% endif %}
{% set last_classes = sub.classes %}
{# Background color #}
{% 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 %}
{% endfor %}
\end{longtable}
{% if not sub.is_event %}{% if sub.sub.type == 1 %}
\sout{% templatetag openbrace %}{{ sub.sub.teacher_old.shortcode }}}
{% elif sub.sub.teacher_new and sub.sub.teacher_old %}
\sout{% templatetag openbrace %}{{ sub.sub.teacher_old.shortcode }}}
$\rightarrow$
{{ sub.sub.teacher_new.shortcode }}
{% elif sub.sub.teacher_new and not sub.sub.teacher_old %}
{{ sub.sub.teacher_new.shortcode }}
{% elif sub.sub.teacher_old %}
{{ sub.sub.teacher_old.shortcode }}
{% endif %}{% else %}
{% for teacher in sub.teachers %}{{ teacher.shortcode }}{% if not forloop.last %}, {% endif %}{% endfor %}
{% endif %}
......@@ -15,7 +15,7 @@ from aleksis.core.decorators import admin_required
from aleksis.core.models import Person, Group
from aleksis.core.util import messages
from .forms import LessonSubstitutionForm, SelectForm
from .forms import LessonSubstitutionForm
from .models import LessonPeriod, LessonSubstitution, TimePeriod, Room
from .tables import LessonsTable, SubstitutionsTable
from .util import CalendarWeek
......
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