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

A working timetable

parent 0abd4740
No related branches found
No related tags found
No related merge requests found
# Generated by Django 2.0.3 on 2018-04-10 09:00
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('timetable', '0001_initial'),
]
operations = [
migrations.RemoveField(
model_name='class',
name='room',
),
migrations.DeleteModel(
name='Teacher',
),
migrations.DeleteModel(
name='Class',
),
migrations.DeleteModel(
name='Room',
),
]
...@@ -3,19 +3,19 @@ from django.db import models ...@@ -3,19 +3,19 @@ from django.db import models
# Create your models here. # Create your models here.
class Teacher(models.Model): # class Teacher(models.Model):
shortcode = models.CharField(max_length=10) # shortcode = models.CharField(max_length=10)
first_name = models.CharField(max_length=100) # first_name = models.CharField(max_length=100)
name = models.CharField(max_length=100) # name = models.CharField(max_length=100)
#
#
class Room(models.Model): # class Room(models.Model):
shortcode = models.CharField(max_length=10) # shortcode = models.CharField(max_length=10)
name = models.CharField(max_length=100) # name = models.CharField(max_length=100)
#
#
class Class(models.Model): # class Class(models.Model):
name = models.CharField(max_length=10) # name = models.CharField(max_length=10)
text1 = models.CharField(max_length=200) # text1 = models.CharField(max_length=200)
text2 = models.CharField(max_length=200) # text2 = models.CharField(max_length=200)
room = models.ForeignKey(Room, on_delete=models.CASCADE) # room = models.ForeignKey(Room, on_delete=models.CASCADE)
from django.conf import settings
class Lesson(object): class Lesson(object):
def __init__(self): def __init__(self):
self.filled = False self.filled = False
...@@ -106,6 +109,24 @@ def parse(): ...@@ -106,6 +109,24 @@ def parse():
raw_lesson_data = raw_lesson.lessonelement1.split(",") raw_lesson_data = raw_lesson.lessonelement1.split(",")
raw_time_data = raw_lesson.lesson_tt.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(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_lesson_data)
# print(raw_time_data) # print(raw_time_data)
...@@ -149,24 +170,6 @@ def parse(): ...@@ -149,24 +170,6 @@ def parse():
lesson_obj.add_element(teacher, subject, rooms, classes) lesson_obj.add_element(teacher, subject, rooms, classes)
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(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("DAY – ", day, "; HOUR – ", hour, "; ROOMS – ", room_ids) # print("DAY – ", day, "; HOUR – ", hour, "; ROOMS – ", room_ids)
lessons.append(lesson_obj) lessons.append(lesson_obj)
...@@ -179,22 +182,53 @@ TYPE_ROOM = 1 ...@@ -179,22 +182,53 @@ TYPE_ROOM = 1
TYPE_CLASS = 2 TYPE_CLASS = 2
class LessonContainer(object):
"""
Needed for Django template because template language does not support dictionaries
Saves the time object and the lesson elements
"""
def __init__(self, ):
self.time = None
self.elements = []
def set_time(self, time):
self.time = time
def append(self, element):
self.elements.append(element)
class LessonElementContainer(object):
"""
Needed for Django template because template language does not support dictionaries
Saves the lesson element object and the room (from time object)
"""
def __init__(self, element, room):
self.element = element
self.room = room
def get_plan(type, id): def get_plan(type, id):
""" Generates a plan for type (TYPE_TEACHE, TYPE_CLASS, TYPE_ROOM) and a id of the teacher (class, room)"""
# Get parsed lessons
lessons = parse() lessons = parse()
plan = [[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []],
[[], [], [], [], []]]
# Init plan array
plan = []
# Fill plan array with LessonContainers (show upside), WIDTH and HEIGHT are defined by Django settings
for hour_idx in range(settings.TIMETABLE_HEIGHT):
plan.append([])
for day_idx in range(settings.TIMETABLE_WIDTH):
plan[hour_idx].append(LessonContainer())
# Fill plan with lessons
for lesson in lessons: for lesson in lessons:
for element in lesson.elements: for i, element in enumerate(lesson.elements):
# Check if the lesson element is important for that plan (look by type and id)
found = False found = False
if type == TYPE_CLASS: if type == TYPE_CLASS:
for lclass in element.classes: for lclass in element.classes:
...@@ -211,12 +245,34 @@ def get_plan(type, id): ...@@ -211,12 +245,34 @@ def get_plan(type, id):
if lroom.id == id: if lroom.id == id:
found = True found = True
# If the lesson element is important then add it to plan array
if found: if found:
for time in lesson.times: for time in lesson.times: # Go for every time the lesson is thought
# print(time.hour, " ", time.day) # print(time.hour, " ", time.day)
# print(element.subject.shortcode) # print(element.subject.shortcode)
plan[time.hour - 1][time.day - 1].append(element)
# Add the time object to the matching LessonContainer on the right position in the plan array
plan[time.hour - 1][time.day - 1].set_time(time)
# Check if there is an room for this time and lesson
try:
room = time.rooms[i]
except IndexError:
room = None
# Create a LessonElementContainer with room and lesson element
element_container = LessonElementContainer(element, room)
# Add this container object to the LessonContainer object in the plan array
plan[time.hour - 1][time.day - 1].append(element_container)
# print(plan) # print(plan)
#
# for hour in plan:
# for day in hour:
# print(day.elements)
# for c in day.elements:
# # print(c.element)
# pass
return plan return plan
...@@ -61,7 +61,7 @@ ...@@ -61,7 +61,7 @@
<div class="card timetable-title-card"> <div class="card timetable-title-card">
<div class="card-content"> <div class="card-content">
<span class="card-title"> <span class="card-title">
0. {{ forloop.counter0|add:"+1" }}.
</span> </span>
</div> </div>
</div> </div>
...@@ -71,24 +71,22 @@ ...@@ -71,24 +71,22 @@
<div class="col s2"> <div class="col s2">
<div class="card lesson-card"> <div class="card lesson-card">
<div class="card-content"> <div class="card-content">
{% for element in col %} {% for element_container in col.elements %}
<p> <p style="background-color: {{ element_container.element.subject.hex_color }};">
{% if type == 0 or type == 1 %} {% if type == 0 or type == 1 %}
{% for class in element.classes %} {% for class in element_container.elements.classes %}
{{ class.name }} {{ class.name }}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
{% if type == 2 or type == 1 %} {% if type == 2 or type == 1 %}
<span data-position="bottom" class="tooltipped" <span data-position="bottom" class="tooltipped"
data-tooltip="{{ element.teacher }}">{{ element.teacher.shortcode }}</span> data-tooltip="{{ element_container.element.teacher }}">{{ element_container.element.teacher.shortcode }}</span>
{% endif %} {% endif %}
<strong>{{ element.subject.shortcode }}</strong> <strong>{{ element_container.element.subject.shortcode }}</strong>
{% if type == 0 or type == 2 %} {% if type == 0 or type == 2 %}
{% for room in element.rooms %} <span class="tooltipped" data-position="bottom"
<span class="tooltipped" data-position="bottom" data-tooltip="{{ element_container.room.name }}">{{ element_container.room.shortcode }}</span>
data-tooltip="{{ room.name }}">{{ room.shortcode }}</span>
{% endfor %}
{% endif %} {% endif %}
</p> </p>
......
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