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

Work copy

parent dd0756ba
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -69,6 +69,31 @@
Leider ist der Vertretungsplan noch nicht in Betrieb. Nutzen Sie solange die <a
href="https://info.katharineum.de/aktuell.pdf">alte Version</a>. Vielen Dank!
</p>
{% for sub in subs %}
<div class="card ">
<div class="card-content">
<span class="card-title">9a</span>
<p>
<strong>{{ sub.lesson }}. Stunde</strong>
{% if sub.teacher_new %}
<s>{{ sub.teacher_old.shortcode }}</s><strong>{{ sub.teacher_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.teacher_old.shortcode }}</strong>
{% endif %}
·
{% if sub.subject_new %}
<s>{{ sub.subject_old.shortcode }}</s><strong>{{ sub.subject_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.subject_old.shortcode }}</strong>
{% endif %}
·
</p>
</div>
</div>
{# {{ sub.date }}#}
{% endfor %}
</main>
{% include 'partials/footer.html' %}
......@@ -2,6 +2,7 @@ from django.contrib.auth.decorators import login_required
from django.http import Http404
from django.shortcuts import render
from untisconnect.parse import *
from untisconnect.sub import get_substitutions_by_date
try:
from schoolapps.untisconnect.api import *
......@@ -62,4 +63,10 @@ def plan(request, plan_type, plan_id):
@login_required
def substitutions(request):
return render(request, 'timetable/substitution.html')
subs = get_substitutions_by_date()
context = {
"subs": subs
}
return render(request, 'timetable/substitution.html', context)
......@@ -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)
def row_by_row(db_ref, obj, filter_term=True):
db_rows = run_all(db_ref.objects, filter_term=filter_term)
def row_by_row_helper(db_rows, obj):
out_rows = []
for db_row in db_rows:
o = obj()
......@@ -35,6 +34,11 @@ def row_by_row(db_ref, obj, filter_term=True):
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):
# print(db_ref)
if db_ref != None:
......
......@@ -21,7 +21,7 @@ def run_using(obj):
def get_term_by_id(term_id):
data = run_using(models.Terms.objects).get(term_id=term_id)
print(data.schoolyear_id)
# print(data.schoolyear_id)
return data
......@@ -47,5 +47,30 @@ def get_terms():
term = Term()
term.create(item)
terms.append(term)
print(term.name)
# print(term.name)
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):
from .api import *
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)
from .api_helper import untis_split_third
def parse():
......@@ -113,7 +100,7 @@ def parse():
for el in rtd2:
day = int(el[1])
hour = int(el[2])
room_ids = untis_split(el[3], conv=int)
room_ids = untis_split_third(el[3], conv=int)
rooms = []
for room_id in room_ids:
......@@ -135,8 +122,8 @@ def parse():
for el in rld2:
teacher_id = int(el[0])
subject_id = int(el[2])
room_ids = untis_split(el[4], int)
class_ids = untis_split(el[17], conv=int)
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)
......
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