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

Merge branch 'dev' into pwa-optimized

parents a50ac3b5 94e1bfc1
No related branches found
No related tags found
1 merge request!86Merge school-apps
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.7 (school-apps)" project-jdk-type="Python SDK" />
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.6 (school-apps)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
......
......@@ -17,7 +17,7 @@
<sourceFolder url="file://$MODULE_DIR$/schoolapps" isTestSource="false" />
<excludeFolder url="file://$MODULE_DIR$/venv" />
</content>
<orderEntry type="jdk" jdkName="Python 3.7 (SchoolApps)" jdkType="Python SDK" />
<orderEntry type="jdk" jdkName="Python 3.6 (school-apps)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="jquery-3.2.1" level="application" />
<orderEntry type="library" name="react.production" level="application" />
......
......@@ -192,20 +192,19 @@ def sub_pdf(request):
# Get the next weekday
today = timezone.datetime.now()
first_day = get_next_weekday(today)
second_day = get_next_weekday(today + datetime.timedelta(days=1))
print(second_day)
# Get subs and generate table
for i, day in enumerate([first_day, second_day]):
print(i, day)
subs = get_substitutions_by_date(day)
for i, date in enumerate([first_day, second_day]):
# Get subs and generate table
subs = get_substitutions_by_date(date)
sub_table = generate_sub_table(subs)
header_info = get_header_information(subs)
# print(header_info.affected_teachers)
header_info = get_header_information(subs, date)
# Generate LaTeX
tex = generate_class_tex(sub_table, day, header_info)
tex = generate_class_tex(sub_table, date, header_info)
# Generate PDF
generate_pdf(tex, "class{}".format(i))
......
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
......@@ -270,6 +272,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
......@@ -266,54 +254,75 @@ 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
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).order_by("classids",
"lesson")),
run_using(models.Substitution.objects.filter(date=date_to_untis_date(date), deleted=0).exclude(
flags__contains="N").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
......@@ -321,14 +330,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