Skip to content

Commit

Permalink
Pick the latest visible course instance in the redirect
Browse files Browse the repository at this point in the history
If the course has only hidden instances and the user is
course staff, then the latest hidden instance is used in the
redirect. Otherwise, the latest visible instance is always used.

Fix #791
  • Loading branch information
markkuriekkinen committed Mar 5, 2021
1 parent 4f45eac commit ae4aef1
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions course/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,22 @@ def get_resource_objects(self):
course = get_object_or_404(Course, url=self._get_kwarg(self.course_kw))
course_instances = CourseInstance.objects.filter(course=course).order_by('-starting_time')

if course_instances:
self.course_instance = course_instances[0]
latest_visible = None
latest_hidden = None
for instance in course_instances:
if instance.visible_to_students:
latest_visible = instance
break
else:
latest_hidden = latest_hidden or instance

if latest_visible:
self.course_instance = latest_visible
elif latest_hidden and latest_hidden.is_course_staff(self.request.user):
self.course_instance = latest_hidden
else:
raise Http404(_("There are no course instances for this course."))

def get(self, request, *args, **kwargs):
return self.redirect(self.course_instance.url)

Expand Down

0 comments on commit ae4aef1

Please sign in to comment.