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

Do not import UNTIS school years directly as school terms

Reason: UNTIS school years are always one full year
and school terms also can be a half year.
parent 95dbbe6a
No related branches found
No related tags found
1 merge request!26Fix lint issues and reformat
Pipeline #3001 passed
......@@ -27,6 +27,11 @@ chronos_models.ValidityRange.field(
verbose_name=_("UNTIS import reference"), null=True, blank=True
)
)
chronos_models.ValidityRange.field(
school_year_untis=IntegerField(
verbose_name=_("UNTIS school year ID"), null=True, blank=True
)
)
chronos_models.ValidityRange.field(
school_id_untis=IntegerField(
verbose_name=_("UNTIS school id"), null=True, blank=True
......
......@@ -60,30 +60,30 @@ def import_terms(
logger.info(f"Import term {term_id} ({date_start}{date_end})")
school_year_id = term.schoolyear_id
if school_year_id in school_terms:
school_term = school_terms[school_year_id]
logger.info(f" School year {school_year_id} already there.")
else:
school_year = run_using(mysql_models.Schoolyear.objects).get(
schoolyear_id=school_year_id
)
school_term_name = (
school_year.text if school_year.text else school_year.schoolyearzoned
)
try:
school_term = core_models.SchoolTerm.objects.within_dates(
date_start, date_end
).get()
logger.info(" School term found by time.")
except core_models.SchoolTerm.DoesNotExist:
if school_year_id in school_terms:
school_term = school_terms[school_year_id]
logger.info(f" School year {school_year_id} already there.")
else:
school_year = run_using(mysql_models.Schoolyear.objects).get(
schoolyear_id=school_year_id
)
school_term_name = (
school_year.text if school_year.text else school_year.schoolyearzoned
)
logger.info(f" Import school year {school_year_id} ...")
logger.info(f" Import school year {school_year_id} ...")
try:
school_term = core_models.SchoolTerm.objects.get(
import_ref_untis=school_year_id
)
logger.info(" School year found by import reference.")
except core_models.SchoolTerm.DoesNotExist:
try:
school_term = core_models.SchoolTerm.objects.within_dates(
date_start, date_end
).get()
logger.info(" School year found by time.")
school_term = core_models.SchoolTerm.objects.get(
import_ref_untis=school_year_id
)
logger.info(" School year found by import reference.")
except core_models.SchoolTerm.DoesNotExist:
school_term = core_models.SchoolTerm(
date_start=date_start, date_end=date_end, name=school_term_name
......@@ -92,13 +92,13 @@ def import_terms(
school_term.import_ref_untis = school_year_id
if school_term.date_end < date_end:
school_term.date_end = date_end
if school_term.date_end < date_end:
school_term.date_end = date_end
if school_term.date_start > date_start:
school_term.date_start = date_start
if school_term.date_start > date_start:
school_term.date_start = date_start
school_term.save()
school_term.save()
try:
validity_range = chronos_models.ValidityRange.objects.get(
......@@ -120,6 +120,7 @@ def import_terms(
validity_range.date_end = date_end
validity_range.name = name
validity_range.school_term = school_term
validity_range.school_year_untis = school_year_id
validity_range.school_id_untis = term.school_id
validity_range.version_id_untis = term.version_id
......
......@@ -33,7 +33,7 @@ def run_default_filter(
"""Add a default filter in order to select the correct term."""
term_id, schoolyear_id, school_id, version_id = (
validity_range.import_ref_untis,
validity_range.school_term.import_ref_untis,
validity_range.school_year_untis,
validity_range.school_id_untis,
validity_range.version_id_untis,
)
......
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