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
9d87dc1c
Unverified
Commit
9d87dc1c
authored
5 years ago
by
Nik | Klampfradler
Browse files
Options
Downloads
Patches
Plain Diff
Add import code for rooms, periods and subjects.
parent
9d93ba52
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
biscuit/apps/untis/util.py
+50
-0
50 additions, 0 deletions
biscuit/apps/untis/util.py
with
50 additions
and
0 deletions
biscuit/apps/untis/util.py
0 → 100644
+
50
−
0
View file @
9d87dc1c
from
datetime
import
time
from
xml.dom
import
minidom
from
biscuit.apps.cambro.models
import
Room
from
biscuit.apps.chronos.models
import
Subject
,
TimePeriod
from
biscuit.core.models
import
Group
def
get_child_node_text
(
node
,
tag
):
tag_nodes
=
node
.
getElementsByTagName
(
'
longname
'
)
if
len
(
tag_nodes
)
==
1
:
return
tag_nodes
[
0
].
firstChild
.
nodeValue
else
:
return
None
def
untis_import_xml
(
request
,
untis_xml
):
dom
=
minidom
.
parse
(
untis_xml
)
subjects
=
dom
.
getElementsByTagName
(
'
subject
'
)
for
subject_node
in
subjects
:
abbrev
=
subject_node
.
attributes
[
'
id
'
].
value
[
3
:]
name
=
get_child_node_text
(
subject_node
,
'
longname
'
)
colour_fg
=
get_child_node_text
(
subject_node
,
'
forecolor
'
)
colour_bg
=
get_child_node_text
(
subject_node
,
'
backcolor
'
)
subject
,
created
=
Subject
.
objects
.
get_or_create
(
abbrev
=
abbrev
,
defaults
=
{
'
name
'
:
name
,
'
colour_fg
'
:
colour_fg
,
'
colour_bg
'
:
colour_bg
})
periods
=
dom
.
getElementsByTagName
(
'
timeperiod
'
)
for
period_node
in
periods
:
weekday
=
int
(
get_child_node_text
(
period_node
,
'
day
'
))
period
=
int
(
get_child_node_text
(
subject_node
,
'
period
'
))
starttime
=
get_child_node_text
(
subject_node
,
'
starttime
'
)
endtime
=
get_child_node_text
(
subject_node
,
'
endtime
'
)
time_start
=
time
(
int
(
starttime
[:
2
]),
int
(
starttime
[
2
:]))
time_end
=
time
(
int
(
endtime
[:
2
]),
int
(
endtime
[
2
:]))
period
,
created
=
TimePeriod
.
objects
.
get_or_create
(
weekday
=
weekday
,
period
=
period
,
defaults
=
{
'
time_start
'
:
time_start
,
'
time_end
'
:
time_end
})
rooms
=
dom
.
getElementsByTagName
(
'
room
'
)
for
room_node
in
rooms
:
short_name
=
subject_node
.
attributes
[
'
id
'
].
value
[
3
:]
name
=
get_child_node_text
(
subject_node
,
'
longname
'
)
room
,
created
=
Room
.
objects
.
get_or_create
(
short_name
=
short_name
,
defaults
=
{
'
name
'
:
name
})
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