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
4db39687
Verified
Commit
4db39687
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Improve import process for supervision areas
parent
d07e75d9
No related branches found
No related tags found
1 merge request
!13
Resolve "Support import from MySQL"
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/untis/settings.py
+5
-0
5 additions, 0 deletions
aleksis/apps/untis/settings.py
aleksis/apps/untis/util/mysql/importers/common_data.py
+40
-9
40 additions, 9 deletions
aleksis/apps/untis/util/mysql/importers/common_data.py
with
45 additions
and
9 deletions
aleksis/apps/untis/settings.py
+
5
−
0
View file @
4db39687
...
@@ -53,6 +53,10 @@ CONSTANCE_CONFIG = {
...
@@ -53,6 +53,10 @@ CONSTANCE_CONFIG = {
_
(
"
Update name of existing rooms?
"
),
_
(
"
Update name of existing rooms?
"
),
bool
,
bool
,
),
),
"
UNTIS_IMPORT_MYSQL_UPDATE_SUPERVISION_AREAS
"
:
(
True
,
_
(
"
Update values of existing supervision areas?
"
)
)
}
}
CONSTANCE_CONFIG_FIELDSETS
=
{
CONSTANCE_CONFIG_FIELDSETS
=
{
...
@@ -71,5 +75,6 @@ CONSTANCE_CONFIG_FIELDSETS = {
...
@@ -71,5 +75,6 @@ CONSTANCE_CONFIG_FIELDSETS = {
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_OVERWRITE_OWNERS
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_OVERWRITE_OWNERS
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_ROOMS_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_ROOMS_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_SUPERVISION_AREAS
"
,
),
),
}
}
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/importers/common_data.py
+
40
−
9
View file @
4db39687
...
@@ -274,32 +274,63 @@ def import_rooms() -> Dict[int, chronos_models.Room]:
...
@@ -274,32 +274,63 @@ def import_rooms() -> Dict[int, chronos_models.Room]:
def
import_supervision_areas
()
->
Dict
[
int
,
chronos_models
.
SupervisionArea
]:
def
import_supervision_areas
()
->
Dict
[
int
,
chronos_models
.
SupervisionArea
]:
"""
Import supervision areas
"""
"""
Import supervision areas
"""
supervision_areas_ref
=
{}
ref
=
{}
# Get supervision areas
areas
=
run_default_filter
(
mysql_models
.
Corridor
.
objects
,
filter_term
=
False
)
areas
=
run_default_filter
(
mysql_models
.
Corridor
.
objects
,
filter_term
=
False
)
for
area
in
areas
:
for
area
in
areas
:
if
not
area
.
name
:
if
not
area
.
name
:
raise
Exception
(
"
Short name needed.
"
)
logger
.
error
(
"
Supervision area ID {}: Cannot import supervision area without short name.
"
.
format
(
area
.
corridor_id
)
)
continue
short_name
=
area
.
name
[:
10
]
short_name
=
area
.
name
[:
10
]
name
=
area
.
longname
[:
50
]
if
area
.
longname
else
short_name
name
=
area
.
longname
[:
50
]
if
area
.
longname
else
short_name
colour_fg
=
untis_colour_to_hex
(
area
.
forecolor
)
colour_fg
=
untis_colour_to_hex
(
area
.
forecolor
)
colour_bg
=
untis_colour_to_hex
(
area
.
backcolor
)
colour_bg
=
untis_colour_to_hex
(
area
.
backcolor
)
import_ref
=
area
.
corridor_id
logger
.
info
(
"
Import supervision area {} …
"
.
format
(
short_name
))
new_area
,
created
=
chronos_models
.
SupervisionArea
.
objects
.
get_or_create
(
new_area
,
created
=
chronos_models
.
SupervisionArea
.
objects
.
get_or_create
(
short_name
=
short_name
,
short_name
=
short_name
,
defaults
=
{
"
name
"
:
name
,
"
colour_fg
"
:
colour_fg
,
"
colour_bg
"
:
colour_bg
},
defaults
=
{
"
name
"
:
name
,
"
colour_fg
"
:
colour_fg
,
"
colour_bg
"
:
colour_bg
,
"
import_ref_untis
"
:
import_ref
},
)
)
new_area
.
name
=
name
if
created
:
new_area
.
colour_fg
=
colour_fg
logger
.
info
(
"
New supervision area created
"
)
new_area
.
colour_bg
=
colour_bg
new_area
.
save
()
changed
=
False
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_SUPERVISION_AREAS
and
(
new_area
.
name
!=
new_area
.
name
or
new_area
.
colour_fg
!=
colour_fg
or
new_area
.
colour_bg
!=
colour_bg
):
new_area
.
name
=
name
new_area
.
colour_fg
=
colour_fg
new_area
.
colour_bg
=
colour_bg
changed
=
True
logger
.
info
(
"
Name, foreground and background colour updated
"
)
if
new_area
.
import_ref_untis
!=
import_ref
:
new_area
.
import_ref_untis
=
import_ref
changed
=
True
logger
.
info
(
"
Import reference updated
"
)
if
changed
:
new_area
.
save
()
# TODO: Supervisions
# TODO: Supervisions
supervision_areas_ref
[
area
.
corridor_id
]
=
new_area
ref
[
import_ref
]
=
new_area
return
supervision_areas_
ref
return
ref
def
import_time_periods_and_breaks
()
->
List
[
List
[
chronos_models
.
TimePeriod
]]:
def
import_time_periods_and_breaks
()
->
List
[
List
[
chronos_models
.
TimePeriod
]]:
...
...
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