Skip to content
Snippets Groups Projects
Commit 3a3745ce authored by Jonathan Weth's avatar Jonathan Weth :keyboard: Committed by root
Browse files

Merge pull request #293 from Katharineum/feature/summarize-hour-blocks-#287

Feature/summarize hour blocks #287
parents 9d22b693 491c6376
No related branches found
No related tags found
1 merge request!86Merge school-apps
import os
import subprocess
import inspect # delete this line
from django.template.loader import render_to_string
from schoolapps.settings import BASE_DIR
from debug.models import register_log_with_filename
LOGO_FILENAME = os.path.join(BASE_DIR, "static", "common", "logo.png")
......
import datetime
import os
import time
import traceback
from typing import List
from PyPDF2 import PdfFileMerger
from django.contrib.auth.decorators import login_required, permission_required
......@@ -17,7 +19,7 @@ from timetable.hints import get_all_hints_by_time_period, get_all_hints_by_class
from timetable.pdf import generate_class_tex, 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
from untisconnect.sub import get_substitutions_by_date, generate_sub_table, get_header_information, SubRow
from untisconnect.api import *
from untisconnect.events import get_all_events_by_date
from userinformation import UserInformation
......@@ -302,6 +304,55 @@ def get_next_weekday_with_time(date, time):
# SUBSTITUTIONS #
#################
# TODO: Move to own helper file later
def equal(sub_row_1: SubRow, sub_row_2: SubRow) -> bool:
"""
Checks the equality of two sub rows
:param sub_row_1: SubRow 1
:param sub_row_2: SubRow 2
:return: Equality
"""
return sub_row_1.classes == sub_row_2.classes and sub_row_1.sub and sub_row_2.sub and \
sub_row_1.sub.teacher_old == sub_row_2.sub.teacher_old and \
sub_row_1.sub.teacher_new == sub_row_2.sub.teacher_new and \
sub_row_1.sub.subject_old == sub_row_2.sub.subject_old and \
sub_row_1.sub.subject_new == sub_row_2.sub.subject_new and \
sub_row_1.sub.room_old == sub_row_2.sub.room_old and \
sub_row_1.sub.room_new == sub_row_2.sub.room_new and \
sub_row_1.sub.text == sub_row_2.sub.text
def merge_sub_rows(sub_table: List[SubRow]) -> List[SubRow]:
"""
Merge equal sub rows with different lesson numbers to one
:param sub_table:
:return:
"""
new_sub_table = []
i = 0
while i < len(sub_table) - 1:
j = 1
while equal(sub_table[i], sub_table[i + j]):
j += 1
if i + j > len(sub_table) - 1:
break
if j > 1:
new_sub_row = sub_table[i]
new_sub_row.lesson = sub_table[i].lesson + '-' + sub_table[i + j - 1].lesson
new_sub_table.append(new_sub_row)
else:
new_sub_table.append(sub_table[i])
# get last item
if i == len(sub_table) - 2:
new_sub_table.append(sub_table[i + 1])
break
i += j
return new_sub_table
def sub_pdf(request, plan_date=None):
"""Show substitutions as PDF for the next weekday (specially for monitors)"""
......@@ -325,6 +376,7 @@ def sub_pdf(request, plan_date=None):
subs = get_substitutions_by_date(date)
sub_table = generate_sub_table(subs, events)
sub_table = merge_sub_rows(sub_table)
# Get header information and hints
header_info = get_header_information(subs, date, events)
......@@ -385,6 +437,9 @@ def substitutions(request, year=None, month=None, day=None):
sub_table = generate_sub_table(subs, events)
# Merge Subs
sub_table = merge_sub_rows(sub_table)
# Get header information and hints
header_info = get_header_information(subs, date, events)
hints = list(get_all_hints_by_time_period(date, date))
......
......@@ -10,6 +10,7 @@ TYPE_CLASS = 2
from datetime import date
def run_all(obj, filter_term=True):
return run_default_filter(run_using(obj).all(), filter_term=filter_term)
......@@ -74,6 +75,13 @@ class Teacher(object):
else:
return "Unbekannt"
def __eq__(self, other):
if not isinstance(other, Teacher):
# don't attempt to compare against unrelated types
return NotImplemented
return self.id == other.id
def create(self, db_obj):
self.filled = True
self.id = db_obj.teacher_id
......@@ -116,6 +124,13 @@ class Class(object):
else:
return "Unbekannt"
def __eq__(self, other):
if not isinstance(other, Class):
# don't attempt to compare against unrelated types
return NotImplemented
return self.id == other.id
def create(self, db_obj):
self.filled = True
self.id = db_obj.class_id
......@@ -187,6 +202,13 @@ class Room(object):
else:
return "Unbekannt"
def __eq__(self, other):
if not isinstance(other, Room):
# don't attempt to compare against unrelated types
return NotImplemented
return self.id == other.id
def create(self, db_obj):
self.filled = True
self.id = db_obj.room_id
......@@ -219,6 +241,13 @@ class Corridor(object):
else:
return "Unbekannt"
def __eq__(self, other):
if not isinstance(other, Corridor):
# don't attempt to compare against unrelated types
return NotImplemented
return self.id == other.id
def create(self, db_obj):
self.filled = True
self.id = db_obj.corridor_id
......@@ -248,6 +277,19 @@ class Subject(object):
self.color = None
self.hex_color = None
def __str__(self):
if self.filled:
return self.shortcode or "Unbekannt"
else:
return "Unbekannt"
def __eq__(self, other):
if not isinstance(other, Teacher):
# don't attempt to compare against unrelated types
return NotImplemented
return self.id == other.id
def create(self, db_obj):
self.filled = True
self.id = db_obj.subject_id
......@@ -384,6 +426,7 @@ def get_all_events_by_date(date):
def get_raw_lessons():
return run_all(models.Lesson.objects)
###########
# HOLIDAY #
###########
......@@ -408,7 +451,7 @@ class Holiday(object):
def get_today_holidays(date):
#db_holidays = row_by_row(models.Holiday, Holiday)
# db_holidays = row_by_row(models.Holiday, Holiday)
d_i = int(date_to_untis_date(date))
db_rows = run_all(models.Holiday.objects.filter(dateto__gte=d_i, datefrom__lte=d_i), filter_term=False)
return row_by_row_helper(db_rows, Holiday)
\ No newline at end of file
return row_by_row_helper(db_rows, Holiday)
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