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

Render substitutions

parent 50bb6a5f
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -2,6 +2,20 @@ function formatDate(date) {
return date.getDate() + "." + (date.getMonth() + 1) + "." + date.getFullYear();
}
function addZeros(i) {
if (i < 10) {
return "0" + i;
} else {
return "" + i;
}
}
function formatDateForDjango(date) {
return "" + date.getFullYear() + "/" + addZeros(date.getMonth() + 1) + "/" + addZeros(date.getDate()) + "/";
}
function getNow() {
return new Date();
}
......@@ -10,6 +24,7 @@ function getNowFormatted() {
return formatDate(getNow());
}
$(document).ready(function () {
// Initialize sidenav [MAT]
$(".sidenav").sidenav();
......
......@@ -11,17 +11,23 @@
updateDatepicker();
}
function loadNew() {
window.location.href = "/timetable/substitutions/" + formatDateForDjango(activeDate);
}
function onDateBeforeClick() {
activeDate.setDate(activeDate.getDate() - 1);
update();
loadNew();
}
function onDateNextClick() {
activeDate.setDate(activeDate.getDate() + 1);
update();
loadNew();
}
var activeDate = getNow();
var activeDate = new Date({{ date_js }});
$(document).ready(function () {
$("#date-before").click(onDateBeforeClick);
......@@ -65,71 +71,78 @@
</div>
</div>
<p class="flow-text">
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>
<div class="row">
<div class="col s12 m6">
<table>
<thead>
<tr>
<th><i class="material-icons">access_time</i></th>
<th><i class="material-icons">people</i></th>
<th>Lehrer</th>
<th>Fach</th>
<th>Raum</th>
<th><i class="material-icons">info</i></th>
<th>i</th>
</tr>
</thead>
<tbody>
{% for sub in subs %}
<tr>
<td>
<strong>{{ sub.lesson }}.</strong>
</td>
<td>
{% for class_ in sub.classes %}
{{ class_.name }}
{% endfor %}
</td>
<td>
{% if sub.teacher_new %}
<s>{{ sub.teacher_old.shortcode }}</s>
<strong>{{ sub.teacher_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.teacher_old.shortcode }}</strong>
{% endif %}
</td>
<td>
{% if sub.subject_new %}
<s>{{ sub.subject_old.shortcode }}</s>
<strong>{{ sub.subject_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.subject_old.shortcode }}</strong>
{% endif %}
</td>
<td>
{% if sub.room_new %}
<s>{{ sub.room_old.shortcode }}</s><strong>{{ sub.room_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.room_old.shortcode }}</strong>
{% endif %}
</td>
<td>
<em>{{ sub.text|default:"" }}</em>
</td>
<td>
<small>{{ sub.id }} {{ sub.lesson_id }}</small>
</td>
</tr>
{# {{ sub.date }}#}
{% endfor %}
</tbody>
</table>
</div>
</div>
<h5>{{ date|date:"l, j. F Y" }}</h5>
<table>
<thead>
<tr>
<th><i class="material-icons">access_time</i></th>
<th><i class="material-icons">people</i></th>
<th>Lehrer</th>
<th>Fach</th>
<th>Raum</th>
<th><i class="material-icons">info</i></th>
<th>i</th>
</tr>
</thead>
<tbody>
{% for sub in subs %}
<tr>
<td>
<strong>{{ sub.lesson }}.</strong>
</td>
<td>
{% for class_ in sub.classes %}
{{ class_.name }}
{% endfor %}
</td>
<td>
{% if sub.teacher_new and sub.teacher_old %}
<s>{{ sub.teacher_old.shortcode }}</s>
<strong>{{ sub.teacher_new.shortcode }}</strong>
{% elif sub.teacher_new and not sub.teacher_old %}
<strong>{{ sub.teacher_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.teacher_old.shortcode }}</strong>
{% endif %}
</td>
<td>
{% if sub.subject_new and sub.subject_old %}
<s>{{ sub.subject_old.shortcode }}</s>
<strong>{{ sub.subject_new.shortcode }}</strong>
{% elif sub.subject_new and not sub.subject_old %}
<strong>{{ sub.subject_new.shortcode }}</strong>
{% else %}
<strong>{{ sub.subject_old.shortcode }}</strong>
{% endif %}
</td>
<td>
{% if sub.room_new and sub.room_old %}
<s>
{{ sub.room_old.shortcode }}
</s><strong>{{ sub.room_new.shortcode }}</strong>
{% elif sub.room_new and not sub.room_old %}
<strong>
{{ sub.room_new.shortcode }}
</strong>
{% else %}
<strong>
{{ sub.room_old.shortcode }}
</strong>
{% endif %}
</td>
<td>
<em>{{ sub.text|default:"" }}</em>
</td>
<td>
<small>{{ sub.id }} {{ sub.lesson_id }}</small>
</td>
</tr>
{# {{ sub.date }}#}
{% endfor %}
</tbody>
</table>
</main>
{% include 'partials/footer.html' %}
......@@ -3,7 +3,8 @@ from . import views
urlpatterns = [
path('', views.all, name='timetable_admin_all'),
path('quick', views.quicklaunch, name='timetable_quicklaunch'),
path('<str:plan_type>/<int:plan_id>', views.plan, name='timetable_plan'),
path('substitutions', views.substitutions, name='timetable_substitutions'),
path('quick/', views.quicklaunch, name='timetable_quicklaunch'),
path('<str:plan_type>/<int:plan_id>/', views.plan, name='timetable_plan'),
path('substitutions/', views.substitutions, name='timetable_substitutions'),
path('substitutions/<int:year>/<int:month>/<int:day>/', views.substitutions, name='timetable_substitutions'),
]
......@@ -2,7 +2,8 @@ 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
from untisconnect.sub import get_substitutions_by_date, date_to_untis_date, untis_date_to_date
from django.utils import timezone
try:
from schoolapps.untisconnect.api import *
......@@ -62,11 +63,19 @@ def plan(request, plan_type, plan_id):
@login_required
def substitutions(request):
subs = get_substitutions_by_date()
def substitutions(request, year=None, day=None, month=None):
date = timezone.datetime.now()
if year is not None and day is not None and month is not None:
date = timezone.datetime(year=year, month=month, day=day)
print(date)
subs = get_substitutions_by_date(date)
context = {
"subs": subs
"subs": subs,
"date": date,
"date_js": int(date.timestamp()) * 1000
}
return render(request, 'timetable/substitution.html', context)
......@@ -54,10 +54,15 @@ class Substitution(object):
# Lesson
# Teacher
self.teacher_old = get_teacher_by_id(db_obj.teacher_idlessn)
print(db_obj.teacher_idlessn)
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)
if self.teacher_old is not None and self.teacher_new.id == self.teacher_old.id:
self.teacher_new = None
self.lesson_element = get_lesson_element_by_id_and_teacher(self.lesson_id, self.teacher_old)
print(self.lesson)
......@@ -66,10 +71,22 @@ class Substitution(object):
if db_obj.subject_idsubst != 0:
self.subject_new = get_subject_by_id(db_obj.subject_idsubst)
if self.subject_old is not None and self.subject_old.id == self.subject_new.id:
self.subject_new = None
# Room
self.rooms_old = self.lesson_element.rooms if self.lesson_element is not None else []
if len(self.rooms_old) >= 1:
self.room_old = self.rooms_old[0]
if db_obj.room_idsubst != 0:
self.room_new = get_room_by_id(db_obj.room_idsubst)
if self.room_old is not None and self.room_old.id == self.room_new.id:
self.room_new = None
# if self.rooms_old
print(self.room_new)
self.corridor = db_obj.corridor_id
# Classes
......@@ -81,9 +98,23 @@ class Substitution(object):
self.classes.append(get_class_by_id(id))
def get_substitutions_by_date():
def substitutions_sorter(sub):
# First, sort by class
sort_by = "".join(class_.name for class_ in sub.classes)
# If the sub hasn't got a class, then put it to the bottom
if sort_by == "":
sort_by = "Z"
# Second, sort by lesson number
sort_by += str(sub.lesson)
return sort_by
def get_substitutions_by_date(date):
subs_raw = run_default_filter(
run_using(models.Substitution.objects.filter(date="20180901").order_by("classids", "lesson")),
run_using(models.Substitution.objects.filter(date=date_to_untis_date(date)).order_by("classids", "lesson")),
filter_term=False)
# print(subs_raw)
......@@ -93,4 +124,5 @@ def get_substitutions_by_date():
print(row.classes)
for class_ in row.classes:
print(class_.name)
subs.sort(key=substitutions_sorter)
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