Skip to content
Snippets Groups Projects
Unverified Commit 3f5e6e65 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Add import code for lessons.

parent c9e6cf70
No related branches found
No related tags found
No related merge requests found
from datetime import time from datetime import date, time
from xml.dom import minidom from xml.dom import minidom
from biscuit.apps.cambro.models import Room from biscuit.apps.cambro.models import Room
from biscuit.apps.chronos.models import Subject, TimePeriod from biscuit.apps.chronos.models import Subject, TimePeriod, Lesson
from biscuit.core.models import Group from biscuit.core.models import Group, Person
def get_child_node_text(node, tag): def get_child_node_text(node, tag):
...@@ -15,6 +15,15 @@ def get_child_node_text(node, tag): ...@@ -15,6 +15,15 @@ def get_child_node_text(node, tag):
return None return None
def get_child_node_id(node, tag):
tag_nodes = node.getElementsByTagName(tag)
if len(tag_nodes) == 1:
return tag_nodes[0].attributes['id'].value
else:
return None
def untis_import_xml(request, untis_xml): def untis_import_xml(request, untis_xml):
dom = minidom.parse(untis_xml) dom = minidom.parse(untis_xml)
...@@ -48,3 +57,34 @@ def untis_import_xml(request, untis_xml): ...@@ -48,3 +57,34 @@ def untis_import_xml(request, untis_xml):
room, created = Room.objects.get_or_create(short_name=short_name, defaults={ room, created = Room.objects.get_or_create(short_name=short_name, defaults={
'name': name}) 'name': name})
lessons = dom.getElementsByTagName('lesson')
for lesson_node in lessons:
subject_abbrev = get_child_node_id(lesson_node, 'lesson_subject')[3:]
teacher_short_name = get_child_node_id(
lesson_node, 'lesson_teacher')[3:]
group_short_names = [v[:3] for v in get_child_node_id(
lesson_node, 'lesson_classes').split(' ')]
effectivebegindate = get_child_node_text(
lesson_node, 'effectivebegindate')
effectiveenddate = get_child_node_text(lesson_node, 'effectiveenddate')
times = lesson_node.getElementsByTagName('time')
time_periods = []
for time_node in times:
day = get_child_node_text(time_node, 'assigned_day')
period = get_child_node_text(time_node, 'assigned_period')
time_periods.append((day, period))
subject = Subject.objects.get(abbrev=subject_abbrev)
teachers = [Person.objects.get(short_name=teacher_short_name)]
groups = [Group.objects.get(short_name=v) for v in group_short_names]
periods = [TimePeriod.objects.get(
weekday=v[0], period=v[1]) for v in time_periods]
date_start = date(int(effectivebegindate[:4]), int(effectivebegindate[4:6]), int(
effectivebegindate[6:])) if effectivebegindate else None
date_end = date(int(effectiveenddate[:4]), int(effectiveenddate[4:6]), int(
effectiveenddate[6:])) if effectiveenddate else None
lesson, created = Lesson.objects.get_or_create(groups=groups, periods=periods, defaults={
'subject': subject, 'teachers': teachers, 'date_start': date_start, 'date_end': date_end})
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