Skip to content
Snippets Groups Projects
Commit bf269702 authored by Nik | Klampfradler's avatar Nik | Klampfradler
Browse files

Merge branch 'fix/import-of-lessons-fails' into 'master'

Fix two bugs with importing lessons

Closes #54 and #55

See merge request AlekSIS/official/AlekSIS-App-Untis!151
parents c7397cb3 8b0316c9
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
----------
Fixed
~~~~~
* Import failed sometimes if there were lessons with names.
* Import failed if there was a lesson without a teacher.
`2.3`_ - 2022-06-25
-------------------
......
......@@ -9,6 +9,8 @@ test_lesson_element = """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissensc
test_lesson_element_partial = """49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;"""
test_lesson_element_partial_partial = ";11;12;13;14;15;16;17;"
test_lesson_element_second = """46~0~92~45;~45;~12~11~0~~B~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~21700,45~0~92~45;~45;~0~0~19000~~~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~0"""
def test_untis_split_first():
assert untis_split_first("") == []
......@@ -20,8 +22,14 @@ def test_untis_split_first():
assert len(untis_split_first(test_lesson_element)) == 2
assert untis_split_first(test_lesson_element) == [
"~~n~~;11;12;13;14;15;16;17;",
"~~n~~;11;12;13;14;15;16;17;",
"""49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;""",
"""49~0~302~7r;~0;~0~0~175608~~~~~"Freiraum: Naturwissenschaften, Fokus Physik"~"Nawi"~~n~~;11;12;13;14;15;16;17;""",
]
assert len(untis_split_first(test_lesson_element_second)) == 2
assert untis_split_first(test_lesson_element_second) == [
"""46~0~92~45;~45;~12~11~0~~B~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~21700""",
"""45~0~92~45;~45;~0~0~19000~~~~~~~~n~~;18;~"Wp_Eb"~~34~0~67900~0~0~~0""",
]
......
......@@ -91,7 +91,7 @@ def import_lessons(
logger.info(" Lesson part {}".format(i))
# Get plain ids
teacher_id = int(el[0])
teacher_id = int(el[0]) if el[0] else 0
subject_id = int(el[2])
class_ids = untis_split_third(el[17], conv=int)
......
......@@ -112,7 +112,7 @@ def untis_split_first(
s: str, conv: Callable[[Any], Any] = lambda el: el, remove_empty: bool = True
) -> Sequence:
return clean_array(
re.findall(r"(\"[^\"]+\"|[^,\"]+)*,?", s)[:-1], conv=conv, remove_empty=remove_empty
re.findall(r"((?:\"[^\"]+\"|[^,\"]+)*),?", s)[:-1], conv=conv, remove_empty=remove_empty
)
......
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