Skip to content

Commit

Permalink
Fix a crash in the course participants page for unenrolled users
Browse files Browse the repository at this point in the history
The participant details page may be opened for users that are not
enrolled in the course. The code `enrollment.status` used to crash
when `enrollment` is `None`.
  • Loading branch information
markkuriekkinen committed Sep 14, 2021
1 parent 9e402d2 commit 32d959f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
9 changes: 7 additions & 2 deletions exercise/staff_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,15 +230,20 @@ def get_resource_objects(self):
def get_common_objects(self):
profile = self.student.userprofile
enrollment = self.instance.get_enrollment_for(profile.user)
if enrollment.status != Enrollment.ENROLLMENT_STATUS.ACTIVE:
if not enrollment:
messages.warning(self.request, _("USER_NOT_ENROLLED"))
elif enrollment.status != Enrollment.ENROLLMENT_STATUS.ACTIVE:
status_string = Enrollment.ENROLLMENT_STATUS[enrollment.status]
messages.warning(
self.request,
format_lazy(
_("NO_LONGER_PARTICIPATING_IN_COURSE -- {status}"),
status=status_string
),
),
)
elif enrollment.role in (Enrollment.ENROLLMENT_ROLE.TEACHER, Enrollment.ENROLLMENT_ROLE.ASSISTANT):
messages.warning(self.request, _("USER_IS_COURSE_STAFF"))

exercise = LearningObject.objects.find_enrollment_exercise(
self.instance,
profile
Expand Down
10 changes: 9 additions & 1 deletion locale/en/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: PACKAGE VERSION\n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-13 16:29+0300\n"
"POT-Creation-Date: 2021-09-14 16:14+0300\n"
"PO-Revision-Date: 2021-05-27 14:47+0300\n"
"Last-Translator: Ella Anttila <[email protected]>\n"
"Language-Team: English<>\n"
Expand Down Expand Up @@ -2839,12 +2839,20 @@ msgstr "The review was saved successfully and the submitters were notified."
msgid "ERROR_FAILED_TO_LOAD_RESOURCE"
msgstr "Failed to load the resource."

#: exercise/staff_views.py
msgid "USER_NOT_ENROLLED"
msgstr "This person is not enrolled in the course."

#: exercise/staff_views.py
#, python-brace-format
msgid "NO_LONGER_PARTICIPATING_IN_COURSE -- {status}"
msgstr ""
"This student is no longer participating in the course (status: {status})."

#: exercise/staff_views.py
msgid "USER_IS_COURSE_STAFF"
msgstr "This person is a member of the course staff."

#: exercise/staff_views.py
#, python-brace-format
msgid "ERROR_INVALID_POST_DATA -- {error}"
Expand Down
10 changes: 9 additions & 1 deletion locale/fi/LC_MESSAGES/django.po
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ msgid ""
msgstr ""
"Project-Id-Version: \n"
"Report-Msgid-Bugs-To: \n"
"POT-Creation-Date: 2021-09-13 16:29+0300\n"
"POT-Creation-Date: 2021-09-14 16:14+0300\n"
"PO-Revision-Date: 2019-08-14 12:16+0200\n"
"Last-Translator: Ella Anttila <[email protected]>\n"
"Language-Team: Finnish <>\n"
Expand Down Expand Up @@ -2842,11 +2842,19 @@ msgstr "Palaute on tallennettu, ja opiskelijoille on lähetetty ilmoitus."
msgid "ERROR_FAILED_TO_LOAD_RESOURCE"
msgstr "Lataus epäonnistui."

#: exercise/staff_views.py
msgid "USER_NOT_ENROLLED"
msgstr "Tämä henkilö ei ole ilmoittautunut kurssille."

#: exercise/staff_views.py
#, python-brace-format
msgid "NO_LONGER_PARTICIPATING_IN_COURSE -- {status}"
msgstr "Tämä opiskelija ei enää osallistu kurssille (tila: {status})."

#: exercise/staff_views.py
msgid "USER_IS_COURSE_STAFF"
msgstr "Tämä henkilö kuuluu kurssin henkilökuntaan."

#: exercise/staff_views.py
#, python-brace-format
msgid "ERROR_INVALID_POST_DATA -- {error}"
Expand Down

0 comments on commit 32d959f

Please sign in to comment.