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

Use teachers only as fallback match for course groups

parent 6e377815
No related branches found
No related tags found
1 merge request!154Resolve "Use teachers only as fallback for course group matching"
Pipeline #85477 passed with stages
in 11 minutes and 39 seconds
......@@ -183,5 +183,6 @@ def import_absences(
if a.import_ref_untis and a.import_ref_untis not in existing_absences:
logger.info("Absence {} deleted".format(a.id))
a.delete()
LessonSubstitution.objects.filter(absence_ref_untis=a.import_ref_untis).delete()
return ref, created_substitutions
......@@ -128,46 +128,49 @@ def import_lessons(
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))
if not qs.exists():
logger.warning(" Not matching course group not found")
# 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()) and 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"
)
possible_groups.append(found_group)
if len(possible_groups) == 1:
course_group = possible_groups[0]
logger.info(" Course group found by searching by parent groups, and subject")
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
and get_site_preferences()["untis_mysql__course_groups_fuzzy_matching"]
):
qs = qs.filter(owners__in=[t.id for t in teachers])
if qs.count() != 1:
logger.warning(
" Course group not found by searching by parent groups, "
" Course group not found or more than one 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 course_group:
logger.warning(
" More than one course group found "
"by searching by parent groups, "
"teachers (owners) and subject (fuzzy matching mode)"
)
course_group = None
else:
course_group = found_group
logger.info(
" Course group found by searching by parent groups, "
"teachers (owners) and subject (fuzzy matching mode)"
)
course_group = qs.first()
logger.info(
" Course group found by searching by parent groups, "
"teachers (owners) and subject (fuzzy matching mode)"
)
changed = False
register_data_check = get_site_preferences()[
......
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