diff --git a/schoolapps/timetable/templates/timetable/substitution.html b/schoolapps/timetable/templates/timetable/substitution.html index 46c946c1bc8bc5fff7f60deee020f34bfbd1ec24..fbd06bb53a58c4a2f2bf7b6f2e09e9532cdfd55f 100755 --- a/schoolapps/timetable/templates/timetable/substitution.html +++ b/schoolapps/timetable/templates/timetable/substitution.html @@ -69,6 +69,31 @@ Leider ist der Vertretungsplan noch nicht in Betrieb. Nutzen Sie solange die <a href="https://info.katharineum.de/aktuell.pdf">alte Version</a>. Vielen Dank! </p> + {% for sub in subs %} + <div class="card "> + <div class="card-content"> + <span class="card-title">9a</span> + <p> + <strong>{{ sub.lesson }}. Stunde</strong> + {% if sub.teacher_new %} + <s>{{ sub.teacher_old.shortcode }}</s> → <strong>{{ sub.teacher_new.shortcode }}</strong> + {% else %} + <strong>{{ sub.teacher_old.shortcode }}</strong> + {% endif %} + · + {% if sub.subject_new %} + <s>{{ sub.subject_old.shortcode }}</s> → <strong>{{ sub.subject_new.shortcode }}</strong> + {% else %} + <strong>{{ sub.subject_old.shortcode }}</strong> + {% endif %} + · + + </p> + </div> + + </div> + {# {{ sub.date }}#} + {% endfor %} </main> {% include 'partials/footer.html' %} diff --git a/schoolapps/timetable/views.py b/schoolapps/timetable/views.py index 842d013189c524cbabc920ddfb031e4173ecf89c..f6344d4dfe7eafa50339915f09070bb29186cfe9 100755 --- a/schoolapps/timetable/views.py +++ b/schoolapps/timetable/views.py @@ -2,6 +2,7 @@ from django.contrib.auth.decorators import login_required from django.http import Http404 from django.shortcuts import render from untisconnect.parse import * +from untisconnect.sub import get_substitutions_by_date try: from schoolapps.untisconnect.api import * @@ -62,4 +63,10 @@ def plan(request, plan_type, plan_id): @login_required def substitutions(request): - return render(request, 'timetable/substitution.html') + subs = get_substitutions_by_date() + + context = { + "subs": subs + } + + return render(request, 'timetable/substitution.html', context) diff --git a/schoolapps/untisconnect/api.py b/schoolapps/untisconnect/api.py index b1e8c01bbd1575a9dd5498509ff1f5edbf1a3c06..9460d6e75c950e4106ba3e1b5b6e486b2be5c269 100755 --- a/schoolapps/untisconnect/api.py +++ b/schoolapps/untisconnect/api.py @@ -25,8 +25,7 @@ def run_default_filter(obj, filter_term=True): return obj.filter(school_id=SCHOOL_ID, schoolyear_id=SCHOOLYEAR_ID, version_id=VERSION_ID) -def row_by_row(db_ref, obj, filter_term=True): - db_rows = run_all(db_ref.objects, filter_term=filter_term) +def row_by_row_helper(db_rows, obj): out_rows = [] for db_row in db_rows: o = obj() @@ -35,6 +34,11 @@ def row_by_row(db_ref, obj, filter_term=True): return out_rows +def row_by_row(db_ref, obj, filter_term=True): + db_rows = run_all(db_ref.objects, filter_term=filter_term) + return row_by_row_helper(db_rows, obj) + + def one_by_id(db_ref, obj): # print(db_ref) if db_ref != None: diff --git a/schoolapps/untisconnect/api_helper.py b/schoolapps/untisconnect/api_helper.py index be7b58107c2cb080025aa6f34427b183581684a0..5ec087772424e2f28dd28e45116cb06806b33865 100644 --- a/schoolapps/untisconnect/api_helper.py +++ b/schoolapps/untisconnect/api_helper.py @@ -21,7 +21,7 @@ def run_using(obj): def get_term_by_id(term_id): data = run_using(models.Terms.objects).get(term_id=term_id) - print(data.schoolyear_id) + # print(data.schoolyear_id) return data @@ -47,5 +47,30 @@ def get_terms(): term = Term() term.create(item) terms.append(term) - print(term.name) + # print(term.name) return terms + + +################ +# HELP METHODS # +################ +def clean_array(a, conv=None): + b = [] + for el in a: + if el != '' and el != "0": + if conv is not None: + el = conv(el) + b.append(el) + return b + + +def untis_split_first(s, conv=None): + return clean_array(s.split(","), conv=conv) + + +def untis_split_second(s, conv=None): + return clean_array(s.split("~"), conv=conv) + + +def untis_split_third(s, conv=None): + return clean_array(s.split(";"), conv=conv) diff --git a/schoolapps/untisconnect/parse.py b/schoolapps/untisconnect/parse.py index 9c7b7cd5a3bf4e31fb82af615b8937ca3bf3472e..16672d747a20fddb128abc51de16759dae607128 100755 --- a/schoolapps/untisconnect/parse.py +++ b/schoolapps/untisconnect/parse.py @@ -49,20 +49,7 @@ class LessonTime(object): from .api import * - - -def clean_array(a, conv=None): - b = [] - for el in a: - if el != '' and el != "0": - if conv is not None: - el = conv(el) - b.append(el) - return b - - -def untis_split(s, conv=None): - return clean_array(s.split(";"), conv=conv) +from .api_helper import untis_split_third def parse(): @@ -113,7 +100,7 @@ def parse(): for el in rtd2: day = int(el[1]) hour = int(el[2]) - room_ids = untis_split(el[3], conv=int) + room_ids = untis_split_third(el[3], conv=int) rooms = [] for room_id in room_ids: @@ -135,8 +122,8 @@ def parse(): for el in rld2: teacher_id = int(el[0]) subject_id = int(el[2]) - room_ids = untis_split(el[4], int) - class_ids = untis_split(el[17], conv=int) + room_ids = untis_split_third(el[4], int) + class_ids = untis_split_third(el[17], conv=int) # print("TEACHER – ", teacher_id, "; SUBJECT – ", subject_id, "; ROOMS – ", room_ids, "; CLASSES – ", # class_ids) diff --git a/schoolapps/untisconnect/sub.py b/schoolapps/untisconnect/sub.py new file mode 100644 index 0000000000000000000000000000000000000000..380e92bbb410ea9f07a12a150124c4561969ebaf --- /dev/null +++ b/schoolapps/untisconnect/sub.py @@ -0,0 +1,85 @@ +from django.utils import timezone + +from untisconnect import models +from untisconnect.api import run_default_filter, row_by_row_helper, get_teacher_by_id, get_subject_by_id, \ + get_room_by_id, get_class_by_id +from untisconnect.api_helper import run_using, untis_split_first + +DATE_FORMAT = "%Y%m%d" + + +def untis_date_to_date(untis): + return timezone.datetime.strptime(str(untis), DATE_FORMAT) + + +def date_to_untis_date(date): + return date.strftime(DATE_FORMAT) + + +class Substitution(object): + def __init__(self): + self.filled = False + self.id = None + self.lesson_id = None + self.date = None + self.lesson = None + self.type = None + self.text = None + self.teacher_old = None + self.teacher_new = None + self.subject_old = None + self.subject_new = None + self.room_old = None + self.room_new = None + self.corridor = None + self.classes = None + + def __str__(self): + if self.filled: + return self.id + else: + return "Unbekannt" + + def create(self, db_obj): + self.filled = True + self.id = db_obj.substitution_id + self.lesson_id = db_obj.lesson_idsubst + self.date = untis_date_to_date(db_obj.date) + self.lesson = db_obj.lesson + self.type = list(db_obj.flags) + self.text = db_obj.text + + # Teacher + if db_obj.teacher_idlessn != 0: + self.teacher_old = get_teacher_by_id(db_obj.teacher_idlessn) + if db_obj.teacher_idsubst != 0: + self.teacher_new = get_teacher_by_id(db_obj.teacher_idsubst) + + # Subject + self.subject_old = None + if db_obj.subject_idsubst != 0: + self.subject_new = get_subject_by_id(db_obj.subject_idsubst) + + # Room + self.room_old = None + if db_obj.room_idsubst != 0: + self.room_new = get_room_by_id(db_obj.room_idsubst) + self.corridor = db_obj.corridor_id + + # Classes + self.classes = [] + class_ids = untis_split_first(db_obj.classids, conv=int) + + for id in class_ids: + self.classes.append(get_class_by_id(id)) + + +def get_substitutions_by_date(): + subs_raw = run_default_filter(run_using(models.Substitution.objects.filter(date="20180821")), filter_term=False) + print(subs_raw) + + subs = row_by_row_helper(subs_raw, Substitution) + print(subs) + for row in subs: + print(row.classes) + return subs