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
30622bea
Verified
Commit
30622bea
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Improve import functions for subjects and teachers
- Add configuration options
parent
3352c20b
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
+15
-1
15 additions, 1 deletion
aleksis/apps/untis/settings.py
aleksis/apps/untis/util/mysql/importers/common_data.py
+58
-9
58 additions, 9 deletions
aleksis/apps/untis/util/mysql/importers/common_data.py
with
73 additions
and
10 deletions
aleksis/apps/untis/settings.py
+
15
−
1
View file @
30622bea
...
@@ -23,6 +23,16 @@ CONSTANCE_CONFIG = {
...
@@ -23,6 +23,16 @@ CONSTANCE_CONFIG = {
_
(
"
Update values of existing subjects?
"
),
_
(
"
Update values of existing subjects?
"
),
bool
,
bool
,
),
),
"
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_SHORT_NAME
"
:
(
False
,
_
(
"
Update short name of existing persons?
"
),
bool
,
),
"
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_NAME
"
:
(
False
,
_
(
"
Update first and last name of existing persons?
"
),
bool
,
),
}
}
CONSTANCE_CONFIG_FIELDSETS
=
{
CONSTANCE_CONFIG_FIELDSETS
=
{
...
@@ -33,5 +43,9 @@ CONSTANCE_CONFIG_FIELDSETS = {
...
@@ -33,5 +43,9 @@ CONSTANCE_CONFIG_FIELDSETS = {
"
UNTIS_DB_HOST
"
,
"
UNTIS_DB_HOST
"
,
"
UNTIS_DB_PORT
"
,
"
UNTIS_DB_PORT
"
,
),
),
"
UNTIS import via MySQL: Common Settings
"
:
(
"
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
"
,),
"
UNTIS import via MySQL: Common Settings
"
:
(
"
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_SHORT_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_NAME
"
,
),
}
}
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/importers/common_data.py
+
58
−
9
View file @
30622bea
...
@@ -33,11 +33,13 @@ def import_subjects() -> Dict[int, chronos_models.Subject]:
...
@@ -33,11 +33,13 @@ def import_subjects() -> Dict[int, chronos_models.Subject]:
# Build values
# Build values
short_name
=
subject
.
name
[:
10
]
short_name
=
subject
.
name
[:
10
]
name
=
subject
.
longname
[:
30
]
if
subject
.
longname
else
short_name
name
=
subject
.
longname
if
subject
.
longname
else
short_name
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
import_ref
=
subject
.
subject_id
import_ref
=
subject
.
subject_id
logger
.
info
(
"
Import subject {} …
"
.
format
(
short_name
))
# Get or create subject object by short name
# Get or create subject object by short name
new_subject
,
created
=
chronos_models
.
Subject
.
objects
.
get_or_create
(
new_subject
,
created
=
chronos_models
.
Subject
.
objects
.
get_or_create
(
abbrev
=
short_name
,
abbrev
=
short_name
,
...
@@ -49,20 +51,31 @@ def import_subjects() -> Dict[int, chronos_models.Subject]:
...
@@ -49,20 +51,31 @@ def import_subjects() -> Dict[int, chronos_models.Subject]:
},
},
)
)
if
created
:
logger
.
info
(
"
New subject created
"
)
# Force sync
# Force sync
changed
=
False
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
and
(
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
and
(
new_subject
.
name
!=
name
new_subject
.
name
!=
name
or
new_subject
.
colour_fg
!=
colour_fg
or
new_subject
.
colour_fg
!=
colour_fg
or
new_subject
.
colour_bg
!=
colour_bg
or
new_subject
.
colour_bg
!=
colour_bg
or
new_subject
.
import_ref_untis
!=
import_ref
):
):
new_subject
.
name
=
name
new_subject
.
name
=
name
new_subject
.
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
new_subject
.
colour_fg
=
untis_colour_to_hex
(
subject
.
forecolor
)
new_subject
.
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
new_subject
.
colour_bg
=
untis_colour_to_hex
(
subject
.
backcolor
)
changed
=
True
logger
.
info
(
"
Name, foreground and background colour updated
"
)
if
new_subject
.
import_ref_untis
!=
import_ref
:
new_subject
.
import_ref_untis
=
import_ref
new_subject
.
import_ref_untis
=
import_ref
new_subject
.
save
()
changed
=
True
logger
.
info
(
"
Successfully imported subject {} ({})
"
.
format
(
short_name
,
"
created
"
if
created
else
"
updated
"
))
logger
.
info
(
"
Import reference updated
"
)
if
changed
:
new_subject
.
save
()
subjects_ref
[
import_ref
]
=
new_subject
subjects_ref
[
import_ref
]
=
new_subject
...
@@ -73,26 +86,62 @@ def import_teachers() -> Dict[int, core_models.Person]:
...
@@ -73,26 +86,62 @@ def import_teachers() -> Dict[int, core_models.Person]:
"""
Import teachers
"""
"""
Import teachers
"""
teachers_ref
=
{}
teachers_ref
=
{}
# Get teachers
teachers
=
run_default_filter
(
mysql_models
.
Teacher
.
objects
)
teachers
=
run_default_filter
(
mysql_models
.
Teacher
.
objects
)
for
teacher
in
teachers
:
for
teacher
in
teachers
:
# Check if needed data are provided
if
not
teacher
.
name
:
if
not
teacher
.
name
:
raise
Exception
(
"
Short name needed.
"
)
logger
.
error
(
"
Teacher ID {}: Cannot import teacher without short name.
"
.
format
(
teacher
.
teacher_id
)
)
continue
short_name
=
teacher
.
name
[:
5
]
# Build values
short_name
=
teacher
.
name
first_name
=
teacher
.
firstname
if
teacher
.
firstname
else
"
?
"
first_name
=
teacher
.
firstname
if
teacher
.
firstname
else
"
?
"
last_name
=
teacher
.
longname
if
teacher
.
longname
else
teacher
.
name
last_name
=
teacher
.
longname
if
teacher
.
longname
else
teacher
.
name
import_ref
=
teacher
.
teacher_id
logger
.
info
(
"
Import teacher {} (as person) …
"
.
format
(
short_name
))
new_teacher
,
created
=
core_models
.
Person
.
objects
.
get_or_create
(
new_teacher
,
created
=
core_models
.
Person
.
objects
.
get_or_create
(
short_name__iexact
=
short_name
,
short_name__iexact
=
short_name
,
defaults
=
{
defaults
=
{
"
first_name
"
:
first_name
,
"
first_name
"
:
first_name
,
"
last_name
"
:
last_name
,
"
last_name
"
:
last_name
,
"
import_ref
"
:
teacher
.
teacher_id
,
"
import_ref
_untis
"
:
import_ref
,
},
},
)
)
new_teacher
.
short_name
=
short_name
if
created
:
new_teacher
.
save
()
logger
.
info
(
"
New person created
"
)
changed
=
False
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_NAME
and
(
new_teacher
.
first_name
!=
first_name
or
new_teacher
.
last_name
!=
last_name
):
new_teacher
.
first_name
=
first_name
new_teacher
.
last_name
=
last_name
changed
=
True
logger
.
info
(
"
First and last name updated
"
)
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_SHORT_NAME
and
new_teacher
.
short_name
!=
short_name
:
new_teacher
.
short_name
=
short_name
changed
=
True
logger
.
info
(
"
Short name updated
"
)
if
new_teacher
.
import_ref_untis
!=
import_ref
:
new_teacher
.
import_ref_untis
=
import_ref
changed
=
True
logger
.
info
(
"
Import reference updated
"
)
if
changed
:
new_teacher
.
save
()
teachers_ref
[
teacher
.
teacher_id
]
=
new_teacher
teachers_ref
[
teacher
.
teacher_id
]
=
new_teacher
...
...
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