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

Current status

parent 4eb53a28
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -72,7 +72,9 @@
{% for sub in subs %}
<div class="card ">
<div class="card-content">
<span class="card-title">9a</span>
<span class="card-title">{% for class_ in sub.classes %}
{{ class_.name }}
{% endfor %}</span>
<p>
<strong>{{ sub.lesson }}. Stunde</strong>
{% if sub.teacher_new %}
......@@ -87,8 +89,18 @@
<strong>{{ sub.subject_old.shortcode }}</strong>
{% endif %}
·
{% if sub.room_new %}
<s>{{ sub.room_old.shortcode }}</s><strong>{{ sub.room_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.room_old.shortcode }}</strong>
{% endif %}
·
<em>{{ sub.text|default:"" }}</em>
</p>
<p>
<small>{{ sub.id }} {{ sub.lesson_id }}</small>
</p>
</div>
</div>
......
......@@ -18,9 +18,75 @@ class Lesson(object):
el.create(day, hour, rooms)
self.times.append(el)
def create(self, db_obj):
def create(self, raw_lesson, drive):
self.filled = True
# Split data (,)
lesson_id = raw_lesson.lesson_id
raw_lesson_data = raw_lesson.lessonelement1.split(",")
raw_time_data = raw_lesson.lesson_tt.split(",")
rtd2 = []
for el in raw_time_data:
rtd2.append(el.split("~"))
# print(rtd2)
for el in rtd2:
day = int(el[1])
hour = int(el[2])
room_ids = untis_split_third(el[3], conv=int)
rooms = []
for room_id in room_ids:
r = drive["rooms"][room_id]
rooms.append(r)
self.add_time(day, hour, rooms)
# print(raw_lesson_data)
# print(raw_time_data)
# Split data more (~)
rld2 = []
for el in raw_lesson_data:
rld2.append(el.split("~"))
# print(rld2)
for el in rld2:
teacher_id = int(el[0])
subject_id = int(el[2])
room_ids = untis_split_third(el[4], int)
class_ids = untis_split_third(el[17], conv=int)
# print("TEACHER – ", teacher_id, "; SUBJECT – ", subject_id, "; ROOMS – ", room_ids, "; CLASSES – ",
# class_ids)
if teacher_id != 0:
teacher = drive["teachers"][teacher_id]
else:
teacher = None
if subject_id != 0:
subject = drive["subjects"][subject_id]
else:
subject = None
rooms = []
for room_id in room_ids:
r = drive["rooms"][room_id]
rooms.append(r)
classes = []
for class_id in class_ids:
c = drive["classes"][class_id]
classes.append(c)
# print("TEACHER – ", teacher, "; SUBJECT – ", subject, "; ROOMS – ", rooms,
# "; CLASSES – ", classes)
self.add_element(teacher, subject, rooms, classes)
class LessonElement(object):
def __init__(self):
......@@ -52,7 +118,7 @@ from .api import *
from .api_helper import untis_split_third
def parse():
def build_drive():
odrive = {
"teachers": get_all_teachers(),
"rooms": get_all_rooms(),
......@@ -72,7 +138,14 @@ def parse():
drive[key][id] = el
print(drive)
return drive
drive = build_drive()
def parse():
global drive
lessons = []
raw_lessons = get_raw_lessons()
......@@ -85,74 +158,9 @@ def parse():
if raw_lesson.lesson_tt and raw_lesson.lessonelement1:
# Create object
lesson_obj = Lesson()
lesson_obj.create(raw_lesson, drive)
# Split data (,)
lesson_id = raw_lesson.lesson_id
raw_lesson_data = raw_lesson.lessonelement1.split(",")
raw_time_data = raw_lesson.lesson_tt.split(",")
rtd2 = []
for el in raw_time_data:
rtd2.append(el.split("~"))
# print(rtd2)
for el in rtd2:
day = int(el[1])
hour = int(el[2])
room_ids = untis_split_third(el[3], conv=int)
rooms = []
for room_id in room_ids:
r = drive["rooms"][room_id]
rooms.append(r)
lesson_obj.add_time(day, hour, rooms)
# print(raw_lesson_data)
# print(raw_time_data)
# Split data more (~)
rld2 = []
for el in raw_lesson_data:
rld2.append(el.split("~"))
# print(rld2)
for el in rld2:
teacher_id = int(el[0])
subject_id = int(el[2])
room_ids = untis_split_third(el[4], int)
class_ids = untis_split_third(el[17], conv=int)
# print("TEACHER – ", teacher_id, "; SUBJECT – ", subject_id, "; ROOMS – ", room_ids, "; CLASSES – ",
# class_ids)
if teacher_id != 0:
teacher = drive["teachers"][teacher_id]
else:
teacher = None
if subject_id != 0:
subject = drive["subjects"][subject_id]
else:
subject = None
rooms = []
for room_id in room_ids:
r = drive["rooms"][room_id]
rooms.append(r)
classes = []
for class_id in class_ids:
c = drive["classes"][class_id]
classes.append(c)
# print("TEACHER – ", teacher, "; SUBJECT – ", subject, "; ROOMS – ", rooms,
# "; CLASSES – ", classes)
lesson_obj.add_element(teacher, subject, rooms, classes)
# print("DAY – ", day, "; HOUR – ", hour, "; ROOMS – ", room_ids)
# print("DAY – ", day, "; HOUR – ", hour, "; ROOMS – ", room_ids)
lessons.append(lesson_obj)
......@@ -192,6 +200,27 @@ class LessonElementContainer(object):
self.room = room
def get_lesson_by_id(id):
global drive
lesson = Lesson()
raw_lesson = run_one(models.Lesson.objects, filter_term=True).get(lesson_id=id)
lesson.create(raw_lesson, drive)
return lesson
def get_lesson_element_by_id_and_teacher(lesson_id, teacher):
print(lesson_id)
try:
lesson = get_lesson_by_id(lesson_id)
except Exception:
return None
for element in lesson.elements:
print(element.teacher.shortcode)
if element.teacher.id == teacher.id:
return element
return None
def get_plan(type, id):
""" Generates a plan for type (TYPE_TEACHE, TYPE_CLASS, TYPE_ROOM) and a id of the teacher (class, room)"""
......
......@@ -4,6 +4,7 @@ from untisconnect import models
from untisconnect.api import run_default_filter, row_by_row_helper, get_teacher_by_id, get_subject_by_id, \
get_room_by_id, get_class_by_id
from untisconnect.api_helper import run_using, untis_split_first
from untisconnect.parse import get_lesson_by_id, get_lesson_element_by_id_and_teacher
DATE_FORMAT = "%Y%m%d"
......@@ -33,6 +34,7 @@ class Substitution(object):
self.room_new = None
self.corridor = None
self.classes = None
self.lesson_element = None
def __str__(self):
if self.filled:
......@@ -49,37 +51,46 @@ class Substitution(object):
self.type = list(db_obj.flags)
self.text = db_obj.text
# Lesson
# Teacher
if db_obj.teacher_idlessn != 0:
self.teacher_old = get_teacher_by_id(db_obj.teacher_idlessn)
self.teacher_old = get_teacher_by_id(db_obj.teacher_idlessn)
if db_obj.teacher_idsubst != 0:
self.teacher_new = get_teacher_by_id(db_obj.teacher_idsubst)
self.lesson_element = get_lesson_element_by_id_and_teacher(self.lesson_id, self.teacher_old)
print(self.lesson)
# Subject
self.subject_old = None
self.subject_old = self.lesson_element.subject if self.lesson_element is not None else None
if db_obj.subject_idsubst != 0:
self.subject_new = get_subject_by_id(db_obj.subject_idsubst)
# Room
self.room_old = None
self.rooms_old = self.lesson_element.rooms if self.lesson_element is not None else []
if db_obj.room_idsubst != 0:
self.room_new = get_room_by_id(db_obj.room_idsubst)
self.corridor = db_obj.corridor_id
# Classes
self.classes = []
class_ids = untis_split_first(db_obj.classids, conv=int)
print(class_ids)
for id in class_ids:
self.classes.append(get_class_by_id(id))
def get_substitutions_by_date():
subs_raw = run_default_filter(run_using(models.Substitution.objects.filter(date="20180821")), filter_term=False)
print(subs_raw)
subs_raw = run_default_filter(
run_using(models.Substitution.objects.filter(date="20180821").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)
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