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
3207b91d
Verified
Commit
3207b91d
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Improve import process for groups
parent
30622bea
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
+18
-0
18 additions, 0 deletions
aleksis/apps/untis/settings.py
aleksis/apps/untis/util/mysql/importers/common_data.py
+44
-5
44 additions, 5 deletions
aleksis/apps/untis/util/mysql/importers/common_data.py
with
62 additions
and
5 deletions
aleksis/apps/untis/settings.py
+
18
−
0
View file @
3207b91d
...
...
@@ -33,6 +33,21 @@ CONSTANCE_CONFIG = {
_
(
"
Update first and last name of existing persons?
"
),
bool
,
),
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_SHORT_NAME
"
:
(
False
,
_
(
"
Update short name of existing groups?
"
),
bool
,
),
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_NAME
"
:
(
False
,
_
(
"
Update name of existing groups?
"
),
bool
,
),
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_OVERWRITE_OWNERS
"
:
(
False
,
_
(
"
Overwrite existing owners?
"
),
bool
,
),
}
CONSTANCE_CONFIG_FIELDSETS
=
{
...
...
@@ -47,5 +62,8 @@ CONSTANCE_CONFIG_FIELDSETS = {
"
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_SHORT_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_PERSONS_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_SHORT_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_NAME
"
,
"
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_OVERWRITE_OWNERS
"
,
),
}
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/importers/common_data.py
+
44
−
5
View file @
3207b91d
...
...
@@ -154,27 +154,66 @@ def import_classes(
"""
Import classes
"""
classes_ref
=
{}
# Get classes
course_classes
=
run_default_filter
(
mysql_models
.
Class
.
objects
,
filter_term
=
True
)
for
class_
in
course_classes
:
# Check if needed data are provided
if
not
class_
.
name
:
raise
Exception
(
"
Short name needed.
"
)
logger
.
error
(
"
Class ID {}: Cannot import class without short name.
"
.
format
(
class_
.
teacher_id
)
)
continue
# Build values
short_name
=
class_
.
name
[:
16
]
name
=
class_
.
longname
if
class_
.
longname
else
short_name
teacher_ids
=
untis_split_first
(
class_
.
teacherids
,
int
)
owners
=
[
teachers_ref
[
t_id
]
for
t_id
in
teacher_ids
]
import_ref
=
class_
.
class_id
logger
.
info
(
"
Import class {} (as group) …
"
.
format
(
short_name
))
new_group
,
created
=
core_models
.
Group
.
objects
.
get_or_create
(
short_name__iexact
=
short_name
,
defaults
=
{
"
name
"
:
name
,
"
import_ref
"
:
class_
.
class_id
},
defaults
=
{
"
name
"
:
name
,
"
import_ref
_untis
"
:
import_ref
},
)
new_group
.
name
=
name
new_group
.
save
()
if
created
:
logger
.
info
(
"
New person created
"
)
changed
=
False
if
(
config
.
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_SHORT_NAME
and
new_group
.
short_name
!=
short_name
):
new_group
.
short_name
=
short_name
changed
=
True
logger
.
info
(
"
Short name updated
"
)
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_NAME
and
new_group
.
name
!=
name
:
new_group
.
name
=
name
changed
=
True
logger
.
info
(
"
Name updated
"
)
if
new_group
.
import_ref_untis
!=
import_ref
:
new_group
.
import_ref_untis
=
import_ref
changed
=
True
logger
.
info
(
"
Import reference updated
"
)
if
changed
:
new_group
.
save
()
if
config
.
UNTIS_IMPORT_MYSQL_UPDATE_GROUPS_OVERWRITE_OWNERS
:
new_group
.
owners
.
clear
()
logger
.
info
(
"
Group owners cleared
"
)
new_group
.
owners
.
clear
()
# configurable
new_group
.
owners
.
add
(
*
owners
)
logger
.
info
(
"
Group owners updated
"
)
classes_ref
[
class_
.
class_id
]
=
new_group
...
...
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