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

Show missing teachers (absences) in the header PDF

parent 69465229
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -185,16 +185,24 @@ def sub_pdf(request):
# Get the next weekday
today = timezone.datetime.now()
first_day = get_next_weekday(today)
date = get_next_weekday(today)
# Get subs and generate table
subs = get_substitutions_by_date(first_day)
subs = get_substitutions_by_date(date)
sub_table = generate_sub_table(subs)
header_info = get_header_information(subs)
header_info = get_header_information(subs, date)
print(header_info.affected_teachers)
# print("HI")
# print(absences, len(absences))
# for absence in absences:
# print(absence.from_date)
# print(absence.to_date)
# print(absence.teacher, "\n")
#
# Generate LaTeX
tex = generate_class_tex(sub_table, first_day, header_info)
tex = generate_class_tex(sub_table, date, header_info)
# Generate PDF
generate_pdf(tex, "class")
......
from untisconnect.api_helper import get_term_by_id, run_using
from django.conf import settings
from untisconnect.api_helper import get_term_by_id, run_using, untis_date_to_date, date_to_untis_date
from . import models
from timetable import models as models2
......@@ -260,6 +262,33 @@ def get_subject_by_id(id):
return one_by_id(subject, Subject)
class Absence(object):
def __init__(self):
self.filled = None
self.teacher = None
self.from_date = None
self.to_date = None
self.from_lesson = None
self.to_lesson = None
self.is_whole_day = None
def create(self, db_obj):
self.filled = True
print(db_obj.ida)
self.teacher = get_teacher_by_id(db_obj.ida)
self.from_date = untis_date_to_date(db_obj.datefrom)
self.to_date = untis_date_to_date(db_obj.dateto)
self.from_lesson = db_obj.lessonfrom
self.to_lesson = db_obj.lessonto
self.is_whole_day = self.from_lesson == 1 and self.to_lesson >= settings.TIMETABLE_HEIGHT
def get_all_absences_by_date(date):
d_i = int(date_to_untis_date(date))
db_rows = run_all(models.Absence.objects.filter(dateto__gte=d_i, datefrom__lte=d_i, deleted=0), filter_term=False)
return row_by_row_helper(db_rows, Absence)
##########
# LESSON #
##########
......
from django.utils import timezone
from . import models
DB_NAME = 'untis'
......@@ -74,3 +76,14 @@ def untis_split_second(s, conv=None):
def untis_split_third(s, conv=None):
return clean_array(s.split(";"), conv=conv)
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)
from django.utils import timezone
from schoolapps.settings import DEBUG
from untisconnect import models
from untisconnect.api import run_default_filter, row_by_row_helper, format_classes
from untisconnect.api_helper import run_using, untis_split_first
from untisconnect.api import run_default_filter, row_by_row_helper, format_classes, get_all_absences_by_date
from untisconnect.api_helper import run_using, untis_split_first, untis_date_to_date, date_to_untis_date
from untisconnect.parse import get_lesson_element_by_id_and_teacher, build_drive
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)
TYPE_SUBSTITUTION = 0
TYPE_CANCELLATION = 1
TYPE_TEACHER_CANCELLATION = 2
......@@ -259,38 +247,65 @@ def generate_sub_table(subs):
class HeaderInformation:
def __init__(self):
self.missing_teachers = []
self.absences = []
self.missing_classes = []
self.affected_teachers = []
self.affected_classes = []
self.rows = []
def is_box_needed(self):
return len(self.missing_teachers) > 0 or len(self.missing_classes) > 0 or len(
return len(self.absences) > 0 or len(self.missing_classes) > 0 or len(
self.affected_teachers) > 0 or len(self.affected_classes) > 0
def get_header_information(subs):
def get_header_information(subs, date):
"""
Get header information like affected teachers/classes and missing teachers/classes for a given date
:param date: The date as datetime object
:param subs: All subs for the given date
:return: HeaderInformation object with all kind of information
"""
info = HeaderInformation()
# Get all affected teachers and classes
for sub in subs:
if sub.teacher_old and sub.teacher_old not in info.affected_teachers:
info.affected_teachers.append(sub.teacher_old)
if sub.teacher_new and sub.teacher_new not in info.affected_teachers:
info.affected_teachers.append(sub.teacher_new)
print(sub.teacher_old)
for _class in sub.classes:
if _class not in info.affected_classes:
info.affected_classes.append(_class)
# Get all absences that are relevant for this day
info.absences = get_all_absences_by_date(date)
# Format list of affected teachers
if info.affected_teachers:
joined = ", ".join(sorted([x.shortcode for x in info.affected_teachers]))
print(joined)
info.rows.append(("Betroffene Lehrkräfte", joined))
# Format list of affected classes
if info.affected_classes:
joined = ", ".join(sorted([x.name for x in info.affected_classes]))
info.rows.append(("Betroffene Klassen", joined))
# Format list of missing teachers (absences)
if info.absences:
elements = []
for absence in info.absences:
if absence.is_whole_day:
# Teacher is missing the whole day
elements.append("{}".format(absence.teacher.shortcode))
else:
# Teacher is only missing a part of day
elements.append("{} ({}-{})".format(absence.teacher.shortcode, absence.from_lesson, absence.to_lesson))
joined = ", ".join(elements)
info.rows.append(("Abwesende Lehrkräfte", joined))
return info
......@@ -299,14 +314,8 @@ def get_substitutions_by_date(date):
run_using(models.Substitution.objects.filter(date=date_to_untis_date(date), deleted=0).order_by("classids",
"lesson")),
filter_term=False)
# print(subs_raw)
subs = row_by_row_helper(subs_raw, Substitution)
# print(subs)
# for row in subs:
# print(row.classes)
# for class_ in row.classes:
# print(class_.name)
subs.sort(key=substitutions_sorter)
return subs
......@@ -314,14 +323,10 @@ def get_substitutions_by_date(date):
def get_substitutions_by_date_as_dict(date):
subs_raw = get_substitutions_by_date(date)
sub_table = generate_sub_table(subs_raw)
print("SUB RAW LEN", len(sub_table))
subs = {}
for i, sub_raw in enumerate(subs_raw):
print(i)
if sub_raw.lesson_id not in subs.keys():
subs[sub_raw.lesson_id] = []
subs[sub_raw.lesson_id].append({"sub": sub_raw, "table": sub_table[i]})
# print(sub_raw.teacher_old)
# print(sub_table[i].teacher)
print(len(subs))
return subs
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