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
b849d087
Verified
Commit
b849d087
authored
2 years ago
by
Jonathan Weth
Browse files
Options
Downloads
Plain Diff
Merge branch '59-support-overlapping-periods' into 58-support-student-group-field-of-lesson
parents
a4693dc6
4877f8aa
No related branches found
No related tags found
1 merge request
!162
Draft: Resolve "Support "student group" field of lesson"
Pipeline
#110844
failed
2 years ago
Stage: prepare
Stage: test
Stage: build
Stage: publish
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
aleksis/apps/untis/model_extensions.py
+2
-2
2 additions, 2 deletions
aleksis/apps/untis/model_extensions.py
aleksis/apps/untis/util/mysql/importers/lessons.py
+89
-64
89 additions, 64 deletions
aleksis/apps/untis/util/mysql/importers/lessons.py
with
91 additions
and
66 deletions
aleksis/apps/untis/model_extensions.py
+
2
−
2
View file @
b849d087
from
django.utils.translation
import
gettext
as
_
from
jsonstore
import
IntegerField
from
jsonstore
import
IntegerField
,
CharField
from
aleksis.apps.chronos
import
models
as
chronos_models
from
aleksis.core
import
models
as
core_models
...
...
@@ -12,7 +12,7 @@ core_models.Person.field(
import_ref_untis
=
IntegerField
(
verbose_name
=
_
(
"
Untis import reference
"
),
null
=
True
,
blank
=
True
)
)
core_models
.
Group
.
field
(
import_ref_untis
=
Intege
rField
(
verbose_name
=
_
(
"
Untis import reference
"
),
null
=
True
,
blank
=
True
)
import_ref_untis
=
Cha
rField
(
verbose_name
=
_
(
"
Untis import reference
"
),
null
=
True
,
blank
=
True
)
)
# Chronos models
...
...
This diff is collapsed.
Click to expand it.
aleksis/apps/untis/util/mysql/importers/lessons.py
+
89
−
64
View file @
b849d087
...
...
@@ -94,6 +94,7 @@ def import_lessons(
teacher_id
=
int
(
el
[
0
])
if
el
[
0
]
else
0
subject_id
=
int
(
el
[
2
])
class_ids
=
untis_split_third
(
el
[
17
],
conv
=
int
)
student_group_id
=
int
(
el
[
19
])
if
el
[
19
]
else
0
# Get teacher
if
teacher_id
!=
0
:
...
...
@@ -113,6 +114,16 @@ def import_lessons(
if
current_teacher_id
and
current_teacher_id
!=
teacher_id
:
use_room_idx
+=
1
# Get student group
student_group
=
None
if
student_group_id
!=
0
:
student_group
=
run_default_filter
(
validity_range
,
mysql_models
.
Studentgroup
.
objects
,
filter_term
=
False
).
get
(
studentgroup_id
=
student_group_id
)
if
not
student_group
.
name
:
student_group
=
None
else
:
class_ids
=
untis_split_third
(
student_group
.
classids
,
conv
=
int
)
# Get classes
course_classes
=
[]
for
class_id
in
class_ids
:
...
...
@@ -128,73 +139,94 @@ def import_lessons(
if
get_site_preferences
()[
"
untis_mysql__use_course_groups
"
]:
# Negative import_ref denotes a course group
group_import_ref
=
-
int
(
"
{}{}
"
.
format
(
lesson_id
,
i
))
group_short_name
=
"
{}-{}
"
.
format
(
""
.
join
([
c
.
short_name
for
c
in
course_classes
]),
subject
.
short_name
,
)
group_name
=
"
{}: {}
"
.
format
(
"
,
"
.
join
([
c
.
short_name
for
c
in
course_classes
]),
subject
.
short_name
,
)
# Search by parent groups, teachers/owners and subject
qs
=
(
core_models
.
Group
.
objects
.
filter
(
parent_groups__in
=
[
c
.
id
for
c
in
course_classes
],
subject_id
=
subject
.
id
,
if
student_group
:
# Search by student group
group_import_ref
=
f
"
sg_
{
student_group_id
}
"
group_short_name
=
student_group
.
name
group_name
=
student_group
.
longname
if
student_group
.
longname
else
group_short_name
qs
=
core_models
.
Group
.
objects
.
filter
(
Q
(
import_ref_untis
=
group_import_ref
)
|
Q
(
short_name
=
group_short_name
)
|
Q
(
name
=
group_name
)).
filter
(
school_term
=
validity_range
.
school_term
)
else
:
# Search by parent groups, teachers/owners and subject
qs
=
(
core_models
.
Group
.
objects
.
filter
(
parent_groups__in
=
[
c
.
id
for
c
in
course_classes
],
subject_id
=
subject
.
id
,
)
.
filter
(
Q
(
school_term__isnull
=
True
)
|
Q
(
school_term
=
validity_range
.
school_term
))
.
distinct
()
)
.
filter
(
Q
(
school_term__isnull
=
True
)
|
Q
(
school_term
=
validity_range
.
school_term
))
.
distinct
()
)
course_group
=
None
if
not
qs
.
exists
():
logger
.
warning
(
"
No matching course group found
"
)
elif
student_group
and
qs
.
count
()
==
1
:
logger
.
debug
(
"
Found exact match with student group
"
)
course_group
=
qs
.
first
()
else
:
logger
.
debug
(
f
"
{
qs
.
count
()
}
possibly matching course groups found:
{
qs
}
"
)
# Check if found groups match
possible_groups
=
[]
course_group
=
None
for
found_group
in
qs
:
if
compare_m2m
(
course_classes
,
found_group
.
parent_groups
.
all
()):
possible_groups
.
append
(
found_group
)
logger
.
debug
(
f
"
{
len
(
possible_groups
)
}
possible groups found
"
f
"
by searching by parent groups:
{
possible_groups
}
"
)
if
not
course_group
:
# Check if found groups match
possible_groups
=
[]
for
found_group
in
qs
:
if
compare_m2m
(
course_classes
,
found_group
.
parent_groups
.
all
()):
possible_groups
.
append
(
found_group
)
if
len
(
possible_groups
)
==
1
:
course_group
=
possible_groups
[
0
]
logger
.
info
(
"
Course group found by searching
"
f
"
by parent groups, and subject:
{
course_group
}
"
logger
.
debug
(
f
"
{
len
(
possible_groups
)
}
possible groups found
"
f
"
by searching by parent groups:
{
possible_groups
}
"
)
else
:
for
found_group
in
possible_groups
:
if
compare_m2m
(
teachers
,
found_group
.
owners
.
all
()):
course_group
=
found_group
logger
.
info
(
"
Course group found by searching by parent groups,
"
"
teachers (owners) and subject
"
)
if
not
course_group
:
logger
.
debug
(
"
No course group found by searching
"
"
by parent groups, teachers (owners) and subject
"
)
if
(
not
course_group
and
get_site_preferences
()[
"
untis_mysql__course_groups_fuzzy_matching
"
]
):
logger
.
debug
(
"
Fuzzy matching mode used
"
)
qs
=
qs
.
filter
(
owners__in
=
[
t
.
id
for
t
in
teachers
])
if
qs
.
count
()
!=
1
:
logger
.
warning
(
"
Course group not found or more than one found
"
f
"
(
{
qs
.
count
()
}
groups found:
{
qs
}
) by searching by parent groups,
"
"
teachers (owners) and subject (fuzzy matching mode)
"
)
else
:
course_group
=
qs
.
first
()
if
len
(
possible_groups
)
==
1
:
course_group
=
possible_groups
[
0
]
logger
.
info
(
"
Course group found by searching
by parent groups,
"
f
"
teachers (owners) and subject (fuzzy matching mode)
:
{
course_group
}
"
"
Course group found by searching
"
f
"
by parent groups, and subject
:
{
course_group
}
"
)
else
:
for
found_group
in
possible_groups
:
if
compare_m2m
(
teachers
,
found_group
.
owners
.
all
()):
course_group
=
found_group
logger
.
info
(
"
Course group found by searching by parent groups,
"
"
teachers (owners) and subject
"
)
if
not
course_group
:
logger
.
debug
(
"
No course group found by searching
"
"
by parent groups, teachers (owners) and subject
"
)
if
(
not
course_group
and
get_site_preferences
()[
"
untis_mysql__course_groups_fuzzy_matching
"
]
):
logger
.
debug
(
"
Fuzzy matching mode used
"
)
qs
=
qs
.
filter
(
owners__in
=
[
t
.
id
for
t
in
teachers
])
if
qs
.
count
()
!=
1
:
logger
.
warning
(
"
Course group not found or more than one found
"
f
"
(
{
qs
.
count
()
}
groups found:
{
qs
}
) by searching by parent groups,
"
"
teachers (owners) and subject (fuzzy matching mode)
"
)
else
:
course_group
=
qs
.
first
()
logger
.
info
(
"
Course group found by searching by parent groups,
"
f
"
teachers (owners) and subject (fuzzy matching mode):
{
course_group
}
"
)
changed
=
False
register_data_check
=
get_site_preferences
()[
...
...
@@ -204,19 +236,9 @@ def import_lessons(
# No matching group found
logger
.
info
(
"
No matching course group found, generate one
"
)
# Build names and refs for course groups
group_short_name
=
"
{}-{}
"
.
format
(
""
.
join
([
c
.
short_name
for
c
in
course_classes
]),
subject
.
short_name
,
)
group_name
=
"
{}: {}
"
.
format
(
"
,
"
.
join
([
c
.
short_name
for
c
in
course_classes
]),
subject
.
short_name
,
)
# Get or create course group
course_group
,
created
=
core_models
.
Group
.
objects
.
get_or_create
(
short_name
=
group_short_name
,
defaults
=
{
"
name
"
:
group_name
}
school_term
=
validity_range
.
school_term
,
short_name
=
group_short_name
,
defaults
=
{
"
name
"
:
group_name
}
)
# Log
...
...
@@ -246,6 +268,9 @@ def import_lessons(
# Update owners
course_group
.
owners
.
set
(
teachers
)
# Update parent groups
course_group
.
parent_groups
.
add
(
*
course_classes
)
# Update import ref
if
course_group
.
import_ref_untis
!=
group_import_ref
:
course_group
.
import_ref_untis
=
group_import_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