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

Remove bugs in plan | Comment

parent 717b7c74
No related branches found
No related tags found
1 merge request!86Merge school-apps
......@@ -118,9 +118,13 @@
<div class="col s2">
<div class="card timetable-title-card">
<div class="card-content">
<span class="card-title left">
{{ time.number_format }}
</span>
{# Lesson number #}
<span class="card-title left">
{{ time.number_format }}
</span>
{# Time dimension of lesson #}
<div class="right timetable-time grey-text text-darken-2">
<span>{{ time.start|date:"H:i" }}</span><br>
<span>{{ time.end|date:"H:i" }}</span>
......@@ -130,56 +134,85 @@
</div>
{% for col in row %}
{# A lesson #}
<div class="col s2">
<div class="card lesson-card">
<div class="card-content">
{# Every element of the lesson #}
{% for element_container in col.elements %}
<div style="
{# Display background color only if no badge exists and it is not the old room #}
{% if not element_container.substitution.table.badge %}
{% if not element_container.is_old or type != 1 %}
background-color: {{ element_container.element.subject.hex_color }};
{% endif %}
{% endif %}"
{# Add CSS class for sub when it's a sub #}
class="{% if element_container.substitution %}lesson-with-sub{% endif %}">
<p>
{% if element_container.substitution %}
{# SUBSTITUTION #}
{% if type == 1 and element_container.is_old %}
{# When it's the old room, let it empty #}
{% elif element_container.substitution.table.badge %}
{# When a badge (cancellation, etc.) exists, then display it #}
<span class="badge new green darken-2">{{ element_container.substitution.table.badge }}</span>
{% else %}
{# Display sub #}
{# Teacher or room > display classes #}
{% if type == 0 or type == 1 %}
{{ element_container.substitution.table.classes }}
{% endif %}
{# Display teacher with tooltip #}
<span class="tooltipped" data-position="bottom"
data-tooltip="{{ element_container.substitution.table.teacher_full|safe }}">{{ element_container.substitution.table.teacher|safe }}</span>
{# Display subject #}
{{ element_container.substitution.table.subject|safe }}
{# Teacher or class > display room #}
{% if type == 0 or type == 2 %}
<span class="tooltipped" data-position="bottom"
data-tooltip="{{ element_container.substitution.table.room_full|safe }}">{{ element_container.substitution.table.room|safe }}</span>
{% endif %}
{% endif %}<br>
{% if not type == 1 and not element_container.is_old %}
{# When it isn't a room or the old plan, then display the extra text (e. g. work orders)#}
{% if not type == 1 or not element_container.is_old %}
<small>
<em>{{ element_container.substitution.table.text|default:"" }}</em>
</small>
{% endif %}
{% else %}
{# Normal plan #}
{# Teacher or room > Display classes #}
{% if type == 0 or type == 1 %}
{% for class in element_container.element.classes %}
{{ class.name }}
{% endfor %}
{% endif %}
{# Class or room > Display teacher #}
{% if type == 2 or type == 1 %}
<span data-position="bottom" class="tooltipped"
data-tooltip="{{ element_container.element.teacher }}">{{ element_container.element.teacher.shortcode }}</span>
{% endif %}
{# Display subject #}
<strong>{{ element_container.element.subject.shortcode }}</strong>
{# Teacher or class > Display room #}
{% if type == 0 or type == 2 %}
<span class="tooltipped" data-position="bottom"
data-tooltip="{{ element_container.room.name }}">{{ element_container.room.shortcode }}</span>
......
......@@ -113,8 +113,7 @@ def get_plan(type, id, smart=False, monday_of_week=None):
# If the lesson element is important then add it to plan array
if found:
for time in lesson.times: # Go for every time the lesson is thought
# print(time.hour, " ", time.day)
# print(element.subject.shortcode)
# Find matching rooms
room_index = None
for j, lroom in enumerate(time.rooms):
if lroom.id == id:
......@@ -129,65 +128,53 @@ def get_plan(type, id, smart=False, monday_of_week=None):
except IndexError:
room = None
# print(element)
# print(room.name)
# Smart Plan: Check if there substitutions for this lesson
matching_sub = None
if smart:
current_weekday = week_days[time.day - 1]
current_lesson = time.hour
print(current_weekday, current_lesson)
print(lesson.id)
# If a sub with matching lesson id and day exists
if subs_for_weekday[time.day - 1].get(lesson.id, None) is not None:
for sub in subs_for_weekday[time.day - 1][lesson.id]:
# sub = subs_for_weekday[time.day - 1][lesson.id]
if sub["sub"].teacher_old.id == element.teacher.id:
# ... check whether the sub has the right old teacher and the right lesson number
if sub["sub"].teacher_old.id == element.teacher.id and sub["sub"].lesson == time.hour:
matching_sub = sub
# print(sub.keys())
# print(sub["sub"].type)
print("SUB")
if matching_sub:
already_added_subs_as_ids.append(matching_sub["sub"].id)
# If the lesson matches, add it to the list of already added subs
if matching_sub:
already_added_subs_as_ids.append(matching_sub["sub"].id)
# Create a LessonElementContainer with room and lesson element
element_container = LessonElementContainer(element, room, substitution=matching_sub)
# Important for rooms: Check if the current room is the old room
if smart and matching_sub is not None:
print(matching_sub["sub"].teacher_old.name)
print(matching_sub["sub"].room_old)
print(matching_sub["sub"].room_new)
if matching_sub["sub"].room_new is not None:
if matching_sub["sub"].room_old is not None:
if matching_sub["sub"].room_old != matching_sub["sub"].room_new:
element_container.is_old = True
else:
element_container.is_old = True
# The rooms is empty, too, if the lesson is canceled
if matching_sub["sub"].type == TYPE_CANCELLATION:
element_container.is_old = True
print(element_container.is_old)
if type != TYPE_ROOM or i == room_index:
# Add this container object to the LessonContainer object in the plan array
plan[time.hour - 1][0][time.day - 1].append(element_container)
# Now check subs which were not in this plan before
if smart:
for i, week_day in enumerate(week_days):
print(i, week_day)
subs_for_this_weekday = subs_for_weekday[i]
for lesson_id, subs in subs_for_this_weekday.items():
for sub in subs:
print(sub["sub"].id)
# print(sub)
# print(sub["sub"].room_new)
found = False
room = sub["sub"].room_old
if type == TYPE_CLASS:
if sub["sub"].classes:
for _class in sub["sub"].classes:
# print(_class)
if _class.id == id:
# print("Hi")
found = True
elif type == TYPE_TEACHER:
if sub["sub"].teacher_new:
......@@ -201,20 +188,6 @@ def get_plan(type, id, smart=False, monday_of_week=None):
if found:
element_container = LessonElementContainer(sub["sub"].lesson_element, room, substitution=sub)
if sub["sub"].id not in already_added_subs_as_ids:
# if len(plan[sub["sub"].lesson - 1][0][i]) > 0:
# for elc in plan[sub["sub"].lesson - 1][0][i]:
# if elc.substitution is not None:
# if elc.substitution.id == elc.substitutio
plan[sub["sub"].lesson - 1][0][i].append(element_container)
# print(plan[sub["sub"].lesson - 1][0][i].elements)
# print(len(plan[sub["sub"].lesson - 1][0][i].elements))
# print(plan)
#
# for hour in plan:
# for day in hour:
# print(day.elements)
# for c in day.elements:
# # print(c.element)
# pass
return plan
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
from untisconnect.api_helper import run_using, untis_split_first
......@@ -234,7 +235,15 @@ def generate_sub_table(subs):
sub_row.room = generate_room_row(sub)
sub_row.room_full = generate_room_row(sub, full=True)
sub_row.text = sub.text
if DEBUG:
# Add id only if debug mode is on
if sub.text:
sub_row.text = sub.text + " " + str(sub.id)
else:
sub_row.text = str(sub.id)
else:
sub_row.text = sub.text
sub_row.badge = None
if sub.type == 1:
......
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