Skip to content
Snippets Groups Projects
Commit 90b246c4 authored by Julian's avatar Julian
Browse files

Merge branch 'feature/holidays' into dev

# Conflicts:
#	.idea/dataSources.local.xml
#	schoolapps/static/common/style.css
#	schoolapps/timetable/templates/timetable/plan.html
#	schoolapps/timetable/views.py
#	schoolapps/untisconnect/plan.py
parents 32b7e2d7 c5ab7f09
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,7 @@ TYPE_TEACHER = 0
TYPE_ROOM = 1
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)
......@@ -380,3 +381,32 @@ def get_all_events_by_date(date):
##########
def get_raw_lessons():
return run_all(models.Lesson.objects)
###########
# HOLIDAY #
###########
class Holiday(object):
def __init__(self):
self.filled = False
self.name = None
self.datefrom = None
self.dateto = None
def __str__(self):
if self.filled:
return self.name or "Unbekannt"
else:
return "Unbekannt"
def create(self, db_obj):
self.filled = True
self.name = db_obj.name
self.datefrom = db_obj.datefrom
self.dateto = db_obj.dateto
def get_today_holidays(date):
#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
......@@ -6,6 +6,7 @@ from schoolapps import settings
from schoolapps.settings import LESSONS
from untisconnect.api import format_classes, TYPE_CLASS, TYPE_TEACHER, TYPE_ROOM
from untisconnect.events import get_all_events_by_date
from untisconnect.api import format_classes, get_today_holidays
from untisconnect.parse import parse
from untisconnect.sub import get_substitutions_by_date_as_dict, TYPE_CANCELLATION, generate_event_table
......@@ -66,6 +67,8 @@ def get_plan(type, id, smart=False, monday_of_week=None):
lessons = parse()
times_parsed = parse_lesson_times()
hols_for_weekday = []
if smart:
week_days = [monday_of_week + datetime.timedelta(days=i) for i in range(5)]
subs_for_weekday = []
......@@ -73,6 +76,11 @@ def get_plan(type, id, smart=False, monday_of_week=None):
subs = get_substitutions_by_date_as_dict(week_day)
subs_for_weekday.append(subs)
hols = get_today_holidays(week_day)
hols_for_weekday.append(hols)
# print(subs)
# print(len(subs))
# Init plan array
plan = []
already_added_subs_as_ids = []
......@@ -155,6 +163,12 @@ def get_plan(type, id, smart=False, monday_of_week=None):
if matching_sub["sub"].type == TYPE_CANCELLATION:
element_container.is_old = True
# Check for holidays
if smart and hols_for_weekday[time.day - 1]:
element_container.is_hol = True
element_container.element.holiday_reason = hols_for_weekday[time.day - 1][0].name
if type != TYPE_ROOM or i == room_index:
# Add this container object to the LessonContainer object in the plan array
plan[time.hour - 1][0][time.day - 1].append(element_container)
......@@ -219,4 +233,4 @@ def get_plan(type, id, smart=False, monday_of_week=None):
for j in range(event.event.from_lesson - 1, event.event.to_lesson):
plan[j][0][i].append(element_container)
return plan
return plan, hols_for_weekday
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