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

Merge branch 'feature/performance-cache-timetable' into merge/dashboard-cache

# Conflicts:
#	requirements.txt
#	schoolapps/dashboard/urls.py
#	schoolapps/dashboard/views.py
#	schoolapps/helper.py
#	schoolapps/timetable/views.py
#	schoolapps/untisconnect/parse.py
#	schoolapps/untisconnect/plan.py
parents cd5e8d35 ccd96902
No related branches found
No related tags found
No related merge requests found
# Generated by Django 2.2.1 on 2019-08-25 10:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('timetable', '0009_hint_classes_formatted'),
]
operations = [
migrations.AlterField(
model_name='hintclass',
name='class_id',
field=models.IntegerField(),
),
]
# Generated by Django 2.2.6 on 2019-11-13 15:55
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('timetable', '0010_auto_20190818_0910'),
('timetable', '0010_auto_20190825_1238'),
]
operations = [
]
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")
......
from django.db import ProgrammingError, OperationalError
from django.urls import path
from untisconnect.models import Terms, Schoolyear
......@@ -26,7 +27,7 @@ try:
path('<str:plan_date>-aktuell.pdf', views.sub_pdf, name="timetable_substitutions_pdf_date")
]
except (Terms.DoesNotExist, Schoolyear.DoesNotExist):
except (Terms.DoesNotExist, Schoolyear.DoesNotExist, ProgrammingError, OperationalError):
from . import fallback_view
urlpatterns = [
......
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
from django.http import Http404, FileResponse
from django.shortcuts import render, redirect, get_object_or_404
from django.utils import timezone
from django.views.decorators.cache import cache_page
from dashboard.caches import SUBS_VIEW_CACHE, MY_PLAN_VIEW_CACHE, PLAN_VIEW_CACHE
from debug.models import register_traceback, register_return_0
from schoolapps.settings import BASE_DIR
from schoolapps.settings import SHORT_WEEK_DAYS, LONG_WEEK_DAYS
......@@ -18,6 +23,9 @@ from untisconnect.utils import get_type_and_object_of_user, overview_dict
from timetable.hints import get_all_hints_by_time_period, get_all_hints_by_class_and_time_period, \
get_all_hints_for_teachers_by_time_period, get_all_hints_not_for_teachers_by_time_period
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, SubRow
from untisconnect.api import *
from untisconnect.events import get_all_events_by_date
from untisconnect.plan import get_plan, parse_lesson_times
......@@ -61,6 +69,7 @@ def quicklaunch(request):
@login_required
@permission_required("timetable.show_plan")
@cache_page(PLAN_VIEW_CACHE.expiration_time)
def plan(request, plan_type, plan_id, regular="", year=None, calendar_week=None):
"""
[DJANGO VIEW]
......@@ -145,6 +154,7 @@ def plan(request, plan_type, plan_id, regular="", year=None, calendar_week=None)
@login_required
@permission_required("timetable.show_plan")
@cache_page(MY_PLAN_VIEW_CACHE.expiration_time)
def my_plan(request, year=None, month=None, day=None):
date, time = find_out_what_is_today(year, month, day)
......@@ -170,7 +180,6 @@ def my_plan(request, year=None, month=None, day=None):
elif _type == TYPE_CLASS:
# Student
plan_id = el.id
raw_type = "class"
......@@ -213,6 +222,55 @@ def my_plan(request, year=None, month=None, day=None):
# 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)"""
......@@ -236,6 +294,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)
......@@ -275,6 +334,7 @@ def sub_pdf(request, plan_date=None):
@login_required
@permission_required("timetable.show_plan")
@cache_page(SUBS_VIEW_CACHE.expiration_time)
def substitutions(request, year=None, month=None, day=None):
"""Show substitutions in a classic view"""
......@@ -291,6 +351,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))
......
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