Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
AlekSIS-App-Untis
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
AlekSIS®
Official
AlekSIS-App-Untis
Commits
3f5e6e65
Unverified
Commit
3f5e6e65
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add import code for lessons.
parent
c9e6cf70
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
biscuit/apps/untis/util.py
+43
-3
43 additions, 3 deletions
biscuit/apps/untis/util.py
with
43 additions
and
3 deletions
biscuit/apps/untis/util.py
+
43
−
3
View file @
3f5e6e65
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
})
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment