-
Notifications
You must be signed in to change notification settings - Fork 74
/
views.py
20 lines (16 loc) · 1.04 KB
/
views.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
from django.shortcuts import redirect, get_object_or_404
from course.models import Course, CourseInstance
from exercise.exercise_models import BaseExercise
def course(request, course_url=None):
course = get_object_or_404(Course, url=course_url)
return redirect(course.instances.first().get_absolute_url(), permanent=True)
def instance(request, course_url=None, instance_url=None):
instance = get_object_or_404(CourseInstance, url=instance_url, course__url=course_url)
return redirect(instance.get_absolute_url(), permanent=True)
def exercise(request, exercise_id=None):
exercise = get_object_or_404(BaseExercise, id=exercise_id)
return redirect(exercise.get_absolute_url(), permanent=True)
def instance_exercise(request, course_url=None, instance_url=None, exercise_id=None):
instance = get_object_or_404(CourseInstance, url=instance_url, course__url=course_url)
exercise = get_object_or_404(BaseExercise, id=exercise_id, course_module__course_instance=instance)
return redirect(exercise.get_absolute_url(), permanent=True)