Skip to content
Snippets Groups Projects
Commit 079c9aa4 authored by Frank Poetzsch-Heffter's avatar Frank Poetzsch-Heffter
Browse files

add two funtions equal() and merge_subs() to summarise lessons with same...

add two funtions equal() and merge_subs() to summarise lessons with same attributes, there's some tidying up to do
parent a979248b
No related branches found
No related tags found
1 merge request!86Merge school-apps
import os
import subprocess
import inspect
from django.template.loader import render_to_string
......@@ -30,9 +31,58 @@ def generate_pdf(tex, filename):
register_log_with_filename("latex_{}".format(filename), "latex", "{}.log".format(filename), process.returncode)
def equal(sub1, sub2):
if sub1.classes == sub2.classes and sub1.sub and sub2.sub and \
sub1.sub.teacher_old == sub2.sub.teacher_old and \
sub1.sub.teacher_new == sub2.sub.teacher_new and \
sub1.sub.subject_old == sub2.sub.subject_old and \
sub1.sub.subject_new == sub2.sub.subject_new and \
sub1.sub.room_old == sub2.sub.room_old and \
sub1.sub.room_new == sub2.sub.room_new and \
sub1.sub.text == sub2.sub.text:
print("Treffer:", sub1.classes, '=', sub2.classes, '\n',
sub1.sub.teacher_old, '=', sub2.sub.teacher_old, '\n',
sub1.sub.teacher_new, '=', sub2.sub.teacher_old, '\n',
sub1.sub.subject_old, '=', sub2.sub.subject_old, '\n',
sub1.sub.subject_new, '=', sub2.sub.subject_new, '\n',
sub1.sub.room_old, '=', sub2.sub.room_new, '\n',
sub1.sub.text, '=', sub2.sub.text)
return True
def merge_subs(subs):
new_subs = []
i = 0
print("Länge:",len(subs))
while i < len(subs) - 1:
j = 1
# Hier geht's schon los: Warum ist sub.teacher_old der gesuchte String, aber sub.subject_old ist ein Objekt?
# print('Komplett:',subs[i].classes, subs[i].sub.teacher_old.shortcode, subs[i].sub.subject_old, subs[i].sub.room_old, subs[i].sub.text)
# sub = inspect.getmembers(subs[i])
# for s in sub:
# print('sub:',len(s), s[0], s[1])
while equal(subs[i], subs[i + j]):
j += 1
if i + j > len(subs) - 1:
break
if j > 1:
new_sub = subs[i]
new_sub.lesson = subs[i].lesson + '-' + subs[i + j - 1].lesson
print('lesson',new_sub.lesson)
new_subs.append(new_sub)
else:
new_subs.append(subs[i])
# get last item
if i == len(subs) - 2:
new_subs.append(subs[i+1])
break
i += j
return(new_subs)
def generate_class_tex(subs, date, header_info, hints=None):
"""Generate LaTeX for a PDF by a substitution table"""
subs = merge_subs(subs)
context = {
"subs": subs,
"date": date,
......
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