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

Merge branch 'dev-1.1' into feature/performance-cache-timetable

# Conflicts:
#	schoolapps/dashboard/views.py
#	schoolapps/timetable/views.py
#	schoolapps/untisconnect/api.py
#	schoolapps/untisconnect/plan.py
parents 9c271816 21339a4f
No related branches found
No related tags found
No related merge requests found
......@@ -8,6 +8,8 @@ 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)
......@@ -73,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
......@@ -115,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
......@@ -186,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
......@@ -218,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
......@@ -247,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
......@@ -382,3 +425,33 @@ def get_all_events_by_date(date):
##########
def get_raw_lessons():
return run_all(models.Lesson.objects.filter(deleted=0))
###########
# 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)
......@@ -7,6 +7,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
......@@ -75,6 +76,8 @@ def get_plan(type, id, smart=False, monday_of_week=None, force_update=False):
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 = []
......@@ -82,6 +85,9 @@ def get_plan(type, id, smart=False, monday_of_week=None, force_update=False):
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)
# Init plan array
plan = []
already_added_subs_as_ids = []
......@@ -165,6 +171,12 @@ def get_plan(type, id, smart=False, monday_of_week=None, force_update=False):
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)
......@@ -231,4 +243,4 @@ def get_plan(type, id, smart=False, monday_of_week=None, force_update=False):
# print("Refresh plan cache for", cache.id)
cache.update(plan)
return plan
return plan, hols_for_weekday
from django.utils import timezone
from django.db.models import Q
from untisconnect import models
from untisconnect.api import run_default_filter, row_by_row_helper, format_classes, get_all_absences_by_date, \
......@@ -312,7 +313,10 @@ def get_header_information(subs, date, events=[]):
def get_substitutions_by_date(date):
subs_raw = run_default_filter(
run_using(models.Substitution.objects.filter(date=date_to_untis_date(date), deleted=0).exclude(
flags__contains="N").order_by("classids", "lesson")),
Q(flags__contains="N") |
Q(flags__contains="b") |
Q(flags__contains="F") |
Q(flags__exact="g")).order_by("classids", "lesson")),
filter_term=False)
subs = row_by_row_helper(subs_raw, Substitution)
......
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