Skip to content
Snippets Groups Projects
Verified Commit 83d3b0b8 authored by Jonathan Weth's avatar Jonathan Weth :keyboard:
Browse files

Merge branch 'master' into use-change-tracker-from-chronos

parents 768994a0 3cc3e69c
No related branches found
No related tags found
No related merge requests found
......@@ -9,6 +9,12 @@ and this project adheres to `Semantic Versioning`_.
Unreleased
----------
Added
~~~~~
* Add fuzzy matching mode for searching course groups: If no 100 % match is found,
the importer will search a match by a subset of parent groups.
Changed
~~~~~~~
......@@ -16,6 +22,12 @@ Changed
to prevent accidental imports of old plans
* Use new change tracker from Chronos to trigger notifications
Fixed
~~~~~
* Search course groups not only by parent groups and subject, but also take
the teachers (group owners) into account
`2.1.3`_ - 2022-02-06
---------------------
......
......@@ -91,6 +91,15 @@ class UseCourseGroups(BooleanPreference):
)
@site_preferences_registry.register
class CourseGroupsFuzzyMatching(BooleanPreference):
section = untis_mysql
name = "course_groups_fuzzy_matching"
default = False
verbose_name = _("Match course groups by a subset of parent groups if no 100% match is found")
help_text = _("Works only if 'Use course groups' is activated.")
@site_preferences_registry.register
class IgnoreIncompleteSubstitutions(BooleanPreference):
section = untis_mysql
......
......@@ -124,22 +124,54 @@ def import_lessons(
# Negative import_ref denotes a course group
group_import_ref = -int("{}{}".format(lesson_id, i))
# Search by parent groups and subject
# 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,
owners__in=[t.id for t in teachers],
).filter(Q(school_term__isnull=True) | Q(school_term=validity_range.school_term))
# Check if found groups match
match = False
for found_group in qs:
if compare_m2m(course_classes, found_group.parent_groups.all()):
if compare_m2m(course_classes, found_group.parent_groups.all()) and compare_m2m(
teachers, found_group.owners.all()
):
match = True
course_group = found_group
logger.info(
" Course group found by searching by parent groups and subject"
" Course group found by searching by parent groups, "
"teachers (owners) and subject"
)
if (
not match
and get_site_preferences()["untis_mysql__course_groups_fuzzy_matching"]
):
if qs.count() != 1:
logger.warning(
" Course group not found by searching by parent groups, "
"teachers (owners) and subject (fuzzy matching mode)"
)
else:
for found_group in qs:
if compare_m2m(teachers, found_group.owners.all()):
if match:
logger.warning(
" More than one course group found "
"by searching by parent groups, "
"teachers (owners) and subject (fuzzy matching mode)"
)
match = False
course_group = None
else:
match = True
course_group = found_group
logger.info(
" Course group found by searching by parent groups, "
"teachers (owners) and subject (fuzzy matching mode)"
)
changed = False
if not match:
# No matching group found
......
......@@ -45,7 +45,7 @@ aleksis-core = "^2.0"
aleksis-app-chronos = "^2.0"
[tool.poetry.dev-dependencies]
aleksis-builddeps = "^6"
aleksis-builddeps = "*"
[tool.poetry.plugins."aleksis.app"]
untis = "aleksis.apps.untis.apps:UntisConfig"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment