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
Merge requests
!13
Resolve "Support import from MySQL"
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Resolve "Support import from MySQL"
4-support-import-from-mysql
into
master
Overview
3
Commits
62
Pipelines
0
Changes
2
1 unresolved thread
Hide all comments
Merged
Tom Teichler
requested to merge
4-support-import-from-mysql
into
master
5 years ago
Overview
3
Commits
62
Pipelines
0
Changes
2
1 unresolved thread
Hide all comments
Expand
Closes
#4 (closed)
Edited
4 years ago
by
Jonathan Weth
0
0
Merge request reports
Viewing commit
3352c20b
Prev
Next
Show latest version
2 files
+
63
−
15
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
2
Search (e.g. *.vue) (Ctrl+P)
Verified
3352c20b
Improve import job for subjects (MySQL)
· 3352c20b
Jonathan Weth
authored
5 years ago
- Configurable force sync
aleksis/apps/untis/util/mysql/importers/common_data.py
+
44
−
9
Options
import
logging
from
datetime
import
time
from
typing
import
List
,
Dict
from
constance
import
config
from
aleksis.apps.chronos
import
models
as
chronos_models
from
aleksis.core
import
models
as
core_models
from
....
import
models
as
mysql_models
from
..util
import
run_default_filter
,
untis_colour_to_hex
,
untis_split_first
logger
=
logging
.
getLogger
(
__name__
)
def
import_subjects
()
->
Dict
[
int
,
chronos_models
.
Subject
]:
"""
Import subjects
"""
subjects_ref
=
{}
# Get subjects
subjects
=
run_default_filter
(
mysql_models
.
Subjects
.
objects
,
filter_term
=
False
)
for
subject
in
subjects
:
# Check if needed data are provided
if
not
subject
.
name
:
raise
Exception
(
"
Short name needed.
"
)
logger
.
error
(
"
Subject ID {}: Cannot import subject without short name.
"
.
format
(
subject
.
subject_id
)
)
continue
# Build values
short_name
=
subject
.
name
[:
10
]
name
=
subject
.
longname
if
subject
.
longname
else
short_name
name
=
subject
.
longname
[:
30
]
if
subject
.
longname
else
short_name
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
import_ref
=
subject
.
subject_id
# Get or create subject object by short name
new_subject
,
created
=
chronos_models
.
Subject
.
objects
.
get_or_create
(
abbrev
=
short_name
,
defaults
=
{
"
name
"
:
name
}
abbrev
=
short_name
,
defaults
=
{
"
name
"
:
name
,
"
colour_fg
"
:
colour_fg
,
"
colour_bg
"
:
colour_bg
,
"
import_ref_untis
"
:
import_ref
,
},
)
new_subject
.
name
=
name
new_subject
.
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
new_subject
.
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
new_subject
.
save
()
subjects_ref
[
subject
.
subject_id
]
=
new_subject
# Force sync
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
and
(
new_subject
.
name
!=
name
or
new_subject
.
colour_fg
!=
colour_fg
or
new_subject
.
colour_bg
!=
colour_bg
or
new_subject
.
import_ref_untis
!=
import_ref
):
new_subject
.
name
=
name
new_subject
.
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
new_subject
.
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
new_subject
.
import_ref_untis
=
import_ref
new_subject
.
save
()
logger
.
info
(
"
Successfully imported subject {} ({})
"
.
format
(
short_name
,
"
created
"
if
created
else
"
updated
"
))
subjects_ref
[
import_ref
]
=
new_subject
return
subjects_ref
Loading