Update not delete `CourseSessionAttendanceCourse`
This commit is contained in:
parent
dfc0a01e9f
commit
842b0b4334
|
|
@ -150,25 +150,20 @@ def create_or_update_course_session(
|
||||||
for circle in circle_keys:
|
for circle in circle_keys:
|
||||||
circle_name = CIRCLE_NAMES[circle][language]
|
circle_name = CIRCLE_NAMES[circle][language]
|
||||||
|
|
||||||
attendance_course_lp_qs = LearningContentAttendanceCourse.objects.filter(
|
attendance_course_lc = LearningContentAttendanceCourse.objects.filter(
|
||||||
slug=f"{course.slug}-lp-circle-{circle_name.lower()}-lc-präsenzkurs-{circle_name.lower()}"
|
slug=f"{course.slug}-lp-circle-{circle_name.lower()}-lc-präsenzkurs-{circle_name.lower()}"
|
||||||
)
|
).first()
|
||||||
|
|
||||||
if attendance_course_lp_qs and attendance_course_lp_qs.exists():
|
if attendance_course_lc:
|
||||||
# reset existing data
|
# update existing data
|
||||||
# TODO: Is this save? stuff shouldn't get lost
|
csa, _created = CourseSessionAttendanceCourse.objects.get_or_create(
|
||||||
CourseSessionAttendanceCourse.objects.filter(
|
course_session=cs, learning_content=attendance_course_lc
|
||||||
course_session=cs, learning_content=attendance_course_lp_qs.first()
|
)
|
||||||
).delete()
|
|
||||||
|
|
||||||
location = f"{data[f'{circle} Raum']}, {data[f'{circle} Standort']}, {data[f'{circle} Adresse']}"
|
location = f"{data[f'{circle} Raum']}, {data[f'{circle} Standort']}, {data[f'{circle} Adresse']}"
|
||||||
|
csa.location = location
|
||||||
|
|
||||||
csa = CourseSessionAttendanceCourse.objects.create(
|
csa.trainer = ""
|
||||||
course_session=cs,
|
|
||||||
learning_content=attendance_course_lp_qs.first(),
|
|
||||||
location=location,
|
|
||||||
trainer="",
|
|
||||||
)
|
|
||||||
csa.due_date.start = try_parse_datetime(data[f"{circle} Start"])[1]
|
csa.due_date.start = try_parse_datetime(data[f"{circle} Start"])[1]
|
||||||
csa.due_date.end = try_parse_datetime(data[f"{circle} Ende"])[1]
|
csa.due_date.end = try_parse_datetime(data[f"{circle} Ende"])[1]
|
||||||
csa.due_date.save()
|
csa.due_date.save()
|
||||||
|
|
@ -269,7 +264,6 @@ def create_or_update_trainer(course: Course, data: Dict[str, Any], language="de"
|
||||||
# circle expert handling
|
# circle expert handling
|
||||||
circle_data = parse_circle_group_string(data["Circles"])
|
circle_data = parse_circle_group_string(data["Circles"])
|
||||||
for circle_key in circle_data:
|
for circle_key in circle_data:
|
||||||
|
|
||||||
circle_name = CIRCLE_NAMES[circle_key][language]
|
circle_name = CIRCLE_NAMES[circle_key][language]
|
||||||
|
|
||||||
# print(circle_name, groups)
|
# print(circle_name, groups)
|
||||||
|
|
|
||||||
|
|
@ -123,6 +123,57 @@ class CreateOrUpdateCourseSessionTestCase(TestCase):
|
||||||
attendance_course.due_date.end.isoformat(), "2023-06-06T13:00:00+00:00"
|
attendance_course.due_date.end.isoformat(), "2023-06-06T13:00:00+00:00"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_import_course_session_twice(self):
|
||||||
|
"""
|
||||||
|
importing the course session twice should create the
|
||||||
|
`CourseSessionAttendanceCourse` only once
|
||||||
|
"""
|
||||||
|
row = [
|
||||||
|
("ID", "DE 2023 A"),
|
||||||
|
("Generation", 2023),
|
||||||
|
("Region", "Deutschschweiz"),
|
||||||
|
("Sprache", "de"),
|
||||||
|
("Klasse", "A"),
|
||||||
|
("Fahrzeug Start", "06.06.2023, 13:30"),
|
||||||
|
("Fahrzeug Ende", "06.06.2023, 15:00"),
|
||||||
|
(
|
||||||
|
"Fahrzeug Raum",
|
||||||
|
"https://teams.microsoft.com/l/meetup-join/19%3ameeting_N2I5YzViZTQtYTM2Ny00OTYwLTgzNzAtYWI4OTQzODcxNTlj%40thread.v2/0?context=%7b%22Tid%22%3a%22fedd03c8-a756-4803-8f27-0db8f7c488f2%22%2c%22Oid%22%3a%22f92e6382-3884-4e71-a2fd-b305a75d9812%22%7d",
|
||||||
|
),
|
||||||
|
("Fahrzeug Standort", None),
|
||||||
|
("Fahrzeug Adresse", None),
|
||||||
|
]
|
||||||
|
|
||||||
|
data = dict(row)
|
||||||
|
|
||||||
|
cs1 = create_or_update_course_session(
|
||||||
|
self.course, data, language="de", circle_keys=["Fahrzeug"]
|
||||||
|
)
|
||||||
|
attendance_course1 = CourseSessionAttendanceCourse.objects.first()
|
||||||
|
self.assertEqual(
|
||||||
|
attendance_course1.due_date.start.isoformat(), "2023-06-06T11:30:00+00:00"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
attendance_course1.due_date.end.isoformat(), "2023-06-06T13:00:00+00:00"
|
||||||
|
)
|
||||||
|
|
||||||
|
# import a second time
|
||||||
|
data["Fahrzeug Start"] = "06.06.2023, 13:15"
|
||||||
|
data["Fahrzeug Ende"] = "06.06.2023, 14:45"
|
||||||
|
cs2 = create_or_update_course_session(
|
||||||
|
self.course, data, language="de", circle_keys=["Fahrzeug"]
|
||||||
|
)
|
||||||
|
|
||||||
|
self.assertEqual(cs1.id, cs2.id)
|
||||||
|
attendance_course2 = CourseSessionAttendanceCourse.objects.first()
|
||||||
|
self.assertEqual(
|
||||||
|
attendance_course2.due_date.start.isoformat(), "2023-06-06T11:15:00+00:00"
|
||||||
|
)
|
||||||
|
self.assertEqual(
|
||||||
|
attendance_course2.due_date.end.isoformat(), "2023-06-06T12:45:00+00:00"
|
||||||
|
)
|
||||||
|
self.assertEqual(attendance_course1.id, attendance_course2.id)
|
||||||
|
|
||||||
def test_raise_exception_if_header_is_missing(self):
|
def test_raise_exception_if_header_is_missing(self):
|
||||||
data = [
|
data = [
|
||||||
("ID", "DE 2023"),
|
("ID", "DE 2023"),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue