Skip to content

Commit

Permalink
Send user to their homepage after altering a course
Browse files Browse the repository at this point in the history
  • Loading branch information
JakobGM committed Aug 8, 2017
1 parent 74419eb commit 4de009c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions semesterpage/admin.py
Expand Up @@ -75,6 +75,7 @@ class CourseAdmin(ObjectPermissionsModelAdmin):
list_filter = ('semesters',)
search_fields = ('full_name', 'display_name', 'course_code',)
filter_horizontal = ('semesters', 'contributors',)
view_on_site = False
# Without this 'contributors' exclude, the save_model() method won't work properly,
# that might be the case for created_by too, but that hasn't been tested yet
inlines = [CourseLinkInline]
Expand Down Expand Up @@ -117,6 +118,14 @@ def formfield_for_manytomany(self, db_field, request, **kwargs):
return super().formfield_for_manytomany(db_field, request, **kwargs)

def response_change(self, request, obj):
"""
Where to send the user when the user saves the course.
"""
if obj in request.user.options.self_chosen_courses.all():
# The course is part of the students homepage.
return redirect(request.user.options.get_absolute_url())

# Delegate to the course object how to show itself.
return redirect(obj.get_absolute_url())

def has_delete_permission(self, request, obj=None):
Expand Down

0 comments on commit 4de009c

Please sign in to comment.