Skip to content

Commit 3c02f1b

Browse files
committed
Import programs from exam events in JSON import
1 parent e441e73 commit 3c02f1b

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

evap/staff/importers/json.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,6 @@ def _import_lecturers(self, data: list[ImportLecturer]) -> None:
219219

220220
def _import_course(self, data: ImportEvent) -> Course:
221221
course_type = self._get_course_type(data["type"])
222-
programs = [self._get_program(c["cprid"]) for c in data["courses"]]
223222
responsibles = self._get_user_profiles(data["lecturers"])
224223
responsibles = self._filter_user_profiles(responsibles)
225224
responsibles = self._choose_responsibles(responsibles)
@@ -229,7 +228,6 @@ def _import_course(self, data: ImportEvent) -> Course:
229228
cms_id=data["gguid"],
230229
defaults={"name_de": data["title"], "name_en": data["title_en"], "type": course_type},
231230
)
232-
course.programs.set(programs)
233231
course.responsibles.set(responsibles)
234232

235233
if changes:
@@ -241,6 +239,10 @@ def _import_course(self, data: ImportEvent) -> Course:
241239

242240
return course
243241

242+
def _import_course_programs(self, course: Course, data: ImportEvent) -> None:
243+
programs = [self._get_program(c["cprid"]) for c in data["courses"]]
244+
course.programs.set(programs)
245+
244246
# pylint: disable=too-many-locals
245247
def _import_evaluation(self, course: Course, data: ImportEvent) -> Evaluation:
246248
last_appointment = sorted(data["appointments"], key=lambda x: x["end"])[-1]
@@ -333,6 +335,8 @@ def _import_events(self, data: list[ImportEvent]) -> None:
333335
for event in exam_events:
334336
course = self.course_map[event["relatedevents"]["gguid"]]
335337

338+
self._import_course_programs(course, event)
339+
336340
self._import_evaluation(course, event)
337341

338342
@transaction.atomic

evap/staff/tests/test_json_importer.py

+5-9
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,7 @@
3333
"title_en": "Process-oriented information systems",
3434
"type": "Vorlesung",
3535
"isexam": False,
36-
"courses": [
37-
{"cprid": "BA-Inf", "scale": "GRADE_PARTICIPATION"},
38-
{"cprid": "MA-Inf", "scale": "GRADE_PARTICIPATION"},
39-
],
36+
"courses": [],
4037
"relatedevents": {"gguid": "0x6"},
4138
"appointments": [{"begin": "15.04.2024 10:15", "end": "15.07.2024 11:45"}],
4239
"lecturers": [{"gguid": "0x3"}],
@@ -50,8 +47,8 @@
5047
"type": "Klausur",
5148
"isexam": True,
5249
"courses": [
53-
{"cprid": "BA-Inf", "scale": ""},
54-
{"cprid": "MA-Inf", "scale": ""},
50+
{"cprid": "BA-Inf", "scale": "GRADE_PARTICIPATION"},
51+
{"cprid": "MA-Inf", "scale": "GRADE_PARTICIPATION"},
5552
],
5653
"relatedevents": {"gguid": "0x5"},
5754
"appointments": [{"begin": "29.07.2024 10:15", "end": "29.07.2024 11:45"}],
@@ -182,7 +179,7 @@ def test_import_courses(self):
182179
self.assertEqual(course.name_en, EXAMPLE_DATA["events"][0]["title_en"])
183180
self.assertEqual(course.type.name_de, EXAMPLE_DATA["events"][0]["type"])
184181
self.assertSetEqual(
185-
{d.name_de for d in course.programs.all()}, {d["cprid"] for d in EXAMPLE_DATA["events"][0]["courses"]}
182+
{d.name_de for d in course.programs.all()}, {d["cprid"] for d in EXAMPLE_DATA["events"][1]["courses"]}
186183
)
187184
self.assertSetEqual(
188185
set(course.responsibles.values_list("email", flat=True)),
@@ -200,7 +197,6 @@ def test_import_courses(self):
200197
set(main_evaluation.participants.values_list("email", flat=True)),
201198
202199
)
203-
self.assertTrue(main_evaluation.wait_for_grade_upload_before_publishing)
204200

205201
self.assertEqual(Contribution.objects.filter(evaluation=main_evaluation).count(), 2)
206202
self.assertSetEqual(
@@ -223,7 +219,7 @@ def test_import_courses(self):
223219
set(exam_evaluation.participants.values_list("email", flat=True)),
224220
225221
)
226-
self.assertFalse(exam_evaluation.wait_for_grade_upload_before_publishing)
222+
self.assertTrue(exam_evaluation.wait_for_grade_upload_before_publishing)
227223

228224
self.assertEqual(Contribution.objects.filter(evaluation=exam_evaluation).count(), 4)
229225
self.assertSetEqual(

0 commit comments

Comments
 (0)