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

Work copy

parent b5fb51b3
No related branches found
No related tags found
No related merge requests found
...@@ -25,8 +25,7 @@ def run_default_filter(obj, filter_term=True): ...@@ -25,8 +25,7 @@ def run_default_filter(obj, filter_term=True):
return obj.filter(school_id=SCHOOL_ID, schoolyear_id=SCHOOLYEAR_ID, version_id=VERSION_ID) return obj.filter(school_id=SCHOOL_ID, schoolyear_id=SCHOOLYEAR_ID, version_id=VERSION_ID)
def row_by_row(db_ref, obj, filter_term=True): def row_by_row_helper(db_rows, obj):
db_rows = run_all(db_ref.objects, filter_term=filter_term)
out_rows = [] out_rows = []
for db_row in db_rows: for db_row in db_rows:
o = obj() o = obj()
...@@ -35,6 +34,11 @@ def row_by_row(db_ref, obj, filter_term=True): ...@@ -35,6 +34,11 @@ def row_by_row(db_ref, obj, filter_term=True):
return out_rows return out_rows
def row_by_row(db_ref, obj, filter_term=True):
db_rows = run_all(db_ref.objects, filter_term=filter_term)
return row_by_row_helper(db_rows, obj)
def one_by_id(db_ref, obj): def one_by_id(db_ref, obj):
# print(db_ref) # print(db_ref)
if db_ref != None: if db_ref != None:
......
...@@ -21,7 +21,7 @@ def run_using(obj): ...@@ -21,7 +21,7 @@ def run_using(obj):
def get_term_by_id(term_id): def get_term_by_id(term_id):
data = run_using(models.Terms.objects).get(term_id=term_id) data = run_using(models.Terms.objects).get(term_id=term_id)
print(data.schoolyear_id) # print(data.schoolyear_id)
return data return data
...@@ -47,5 +47,30 @@ def get_terms(): ...@@ -47,5 +47,30 @@ def get_terms():
term = Term() term = Term()
term.create(item) term.create(item)
terms.append(term) terms.append(term)
print(term.name) # print(term.name)
return terms return terms
################
# HELP METHODS #
################
def clean_array(a, conv=None):
b = []
for el in a:
if el != '' and el != "0":
if conv is not None:
el = conv(el)
b.append(el)
return b
def untis_split_first(s, conv=None):
return clean_array(s.split(","), conv=conv)
def untis_split_second(s, conv=None):
return clean_array(s.split("~"), conv=conv)
def untis_split_third(s, conv=None):
return clean_array(s.split(";"), conv=conv)
...@@ -49,20 +49,7 @@ class LessonTime(object): ...@@ -49,20 +49,7 @@ class LessonTime(object):
from .api import * from .api import *
from .api_helper import untis_split_third
def clean_array(a, conv=None):
b = []
for el in a:
if el != '' and el != "0":
if conv is not None:
el = conv(el)
b.append(el)
return b
def untis_split(s, conv=None):
return clean_array(s.split(";"), conv=conv)
def parse(): def parse():
...@@ -113,7 +100,7 @@ def parse(): ...@@ -113,7 +100,7 @@ def parse():
for el in rtd2: for el in rtd2:
day = int(el[1]) day = int(el[1])
hour = int(el[2]) hour = int(el[2])
room_ids = untis_split(el[3], conv=int) room_ids = untis_split_third(el[3], conv=int)
rooms = [] rooms = []
for room_id in room_ids: for room_id in room_ids:
...@@ -135,8 +122,8 @@ def parse(): ...@@ -135,8 +122,8 @@ def parse():
for el in rld2: for el in rld2:
teacher_id = int(el[0]) teacher_id = int(el[0])
subject_id = int(el[2]) subject_id = int(el[2])
room_ids = untis_split(el[4], int) room_ids = untis_split_third(el[4], int)
class_ids = untis_split(el[17], conv=int) class_ids = untis_split_third(el[17], conv=int)
# print("TEACHER – ", teacher_id, "; SUBJECT – ", subject_id, "; ROOMS – ", room_ids, "; CLASSES – ", # print("TEACHER – ", teacher_id, "; SUBJECT – ", subject_id, "; ROOMS – ", room_ids, "; CLASSES – ",
# class_ids) # class_ids)
......
from django.utils import timezone
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
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)
class Substitution(object):
def __init__(self):
self.filled = False
self.id = None
self.lesson_id = None
self.date = None
self.lesson = None
self.type = None
self.text = None
self.teacher_old = None
self.teacher_new = None
self.subject_old = None
self.subject_new = None
self.room_old = None
self.room_new = None
self.corridor = None
self.classes = None
def __str__(self):
if self.filled:
return self.id
else:
return "Unbekannt"
def create(self, db_obj):
self.filled = True
self.id = db_obj.substitution_id
self.lesson_id = db_obj.lesson_idsubst
self.date = untis_date_to_date(db_obj.date)
self.lesson = db_obj.lesson
self.type = list(db_obj.flags)
self.text = db_obj.text
# Teacher
if db_obj.teacher_idlessn != 0:
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)
# Subject
self.subject_old = None
if db_obj.subject_idsubst != 0:
self.subject_new = get_subject_by_id(db_obj.subject_idsubst)
# Room
self.room_old = None
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)
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 = row_by_row_helper(subs_raw, Substitution)
print(subs)
for row in subs:
print(row.classes)
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