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
3352c20b
Verified
Commit
3352c20b
authored
4 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Patches
Plain Diff
Improve import job for subjects (MySQL)
- Configurable force sync
parent
4ffaae54
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
+19
-6
19 additions, 6 deletions
aleksis/apps/untis/settings.py
aleksis/apps/untis/util/mysql/importers/common_data.py
+44
-9
44 additions, 9 deletions
aleksis/apps/untis/util/mysql/importers/common_data.py
with
63 additions
and
15 deletions
aleksis/apps/untis/settings.py
+
19
−
6
View file @
3352c20b
from
aleksis.core.util.core_helpers
import
lazy_config
from
django.utils.translation
import
gettext_lazy
as
_
DATABASES
=
{
'
untis
'
:
{
...
...
@@ -12,13 +13,25 @@ DATABASES = {
}
CONSTANCE_CONFIG
=
{
"
UNTIS_NAME
"
:
(
"
untis
"
,
_
(
"
Name of database
"
),
"
char_field
"
),
"
UNTIS_USER
"
:
(
"
aleksis
"
,
_
(
"
Database user
"
),
"
char_field
"
),
"
UNTIS_PASSWORD
"
:
(
"
aleksis
"
,
_
(
"
Database password
"
),
"
char_field
"
),
"
UNTIS_HOST
"
:
(
"
127.0.0.1
"
,
_
(
"
Database host
"
),
"
char_field
"
),
"
UNTIS_PORT
"
:
(
"
3306
"
,
_
(
"
Database port
"
),
"
char_field
"
),
"
UNTIS_DB_NAME
"
:
(
"
untis
"
,
_
(
"
Name of database
"
),
"
char_field
"
),
"
UNTIS_DB_USER
"
:
(
"
aleksis
"
,
_
(
"
Database user
"
),
"
char_field
"
),
"
UNTIS_DB_PASSWORD
"
:
(
"
aleksis
"
,
_
(
"
Database password
"
),
"
char_field
"
),
"
UNTIS_DB_HOST
"
:
(
"
127.0.0.1
"
,
_
(
"
Database host
"
),
"
char_field
"
),
"
UNTIS_DB_PORT
"
:
(
"
3306
"
,
_
(
"
Database port
"
),
"
char_field
"
),
"
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
"
:
(
True
,
_
(
"
Update values of existing subjects?
"
),
bool
,
),
}
CONSTANCE_CONFIG_FIELDSETS
=
{
"
Untis Database Settings
"
:
(
"
UNTIS_NAME
"
,
"
UNTIS_USER
"
,
"
UNTIS_PASSWORD
"
,
"
UNTIS_HOST
"
,
"
UNTIS_PORT
"
),
"
UNTIS import via MySQL: Database Settings
"
:
(
"
UNTIS_DB_NAME
"
,
"
UNTIS_DB_USER
"
,
"
UNTIS_DB_PASSWORD
"
,
"
UNTIS_DB_HOST
"
,
"
UNTIS_DB_PORT
"
,
),
"
UNTIS import via MySQL: Common Settings
"
:
(
"
UNTIS_IMPORT_MYSQL_UPDATE_SUBJECTS
"
,),
}
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/importers/common_data.py
+
44
−
9
View file @
3352c20b
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
...
...
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