Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

actually save student affiliations #414

Merged
merged 1 commit into from
May 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions compass/dao/csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ def persons_from_file(self, fileobj):
row.get(*self.student_identifiers))

if student_number is None:
persons.append({'error': 'Missing student number'})
continue

try:
Expand All @@ -98,6 +97,8 @@ def persons_from_file(self, fileobj):
persons.append(person_dict)
except PersonNotFoundException:
persons.append({
'error': f'Student number {student_number} not found'})
'student_number': student_number,
'error': f'Student number not found'
})

return persons
30 changes: 18 additions & 12 deletions compass/views/api/student.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,18 +295,24 @@ def post(self, request, *args, **kwargs):
return self.response_badrequest(f"Invalid CSV file: {ex.error}")

for p in person_data:
if hasattr(p, "system_key"):
student, _ = Student.objects.get_or_create(
system_key=p["system_key"])
sa, _ = StudentAffiliation.objects.get_or_create(
student=student, affiliation=affiliation)
sa.date = current_datetime_utc().date()
sa.cohorts.clear()
sa.cohorts.add(cohort)
sa.save()
logger.info(
f"StudentAffiliation for {student.systemkey} added: "
f"{affiliation.name} ({affiliation.id}), {cohort_str}")
if "error" in p:
continue

student, _ = Student.objects.get_or_create(
system_key=p["system_key"])
sa, _ = StudentAffiliation.objects.get_or_create(
student=student, affiliation=affiliation)
sa.date = current_datetime_utc().date()
sa.cohorts.clear()
sa.cohorts.add(cohort)
sa.save()

logger.info(
f"StudentAffiliation for {student.systemkey} added: "
f"{affiliation.name} ({affiliation.id}), {cohort_str}")

serializer = StudentAffiliationReadSerializer(sa)
p['affiliation'] = serializer.data

return self.response_ok(person_data)

Expand Down
Loading