本文整理汇总了Python中courses.models.Course.get_or_fail方法的典型用法代码示例。如果您正苦于以下问题:Python Course.get_or_fail方法的具体用法?Python Course.get_or_fail怎么用?Python Course.get_or_fail使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类courses.models.Course
的用法示例。
在下文中一共展示了Course.get_or_fail方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_queryset
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_or_fail [as 别名]
def get_queryset(self):
user = self.request.user
self.course = Course.get_or_fail(self.kwargs['course_id'], user=user, check_student=False, only_id=False)
self.users = self.course.students.select_related('profile').order_by('last_name', 'first_name', 'profile__middle_name')
return self.users
示例2: finish_lecture_view
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_or_fail [as 别名]
def finish_lecture_view(request, course_id, lecture_id):
course = Course.get_or_fail(course_id, user=request.user,
queryset=Course.objects.only('id'))
lecture = get_object_or_404(Lecture.objects.only('title'), id=lecture_id)
if not lecture.in_course(course):
raise Http404('Запрошенная лекция отсутствует в составе курса')
LectureResult.pass_lecture(lecture, course, request.user)
return render(request, 'lecture_finished.html', {'course': course, 'lecture': lecture})
示例3: dispatch
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_or_fail [as 别名]
def dispatch(self, *args, **kwargs):
request = args[0]
user = request.user
self.is_self_mon = user.id == int(kwargs['user_id'])
if self.is_self_mon:
self.user_mon = user
else:
self.user_mon = get_object_or_404(User, id=kwargs['user_id'])
self.course = Course.get_or_fail(kwargs['course_id'], user=self.user_mon, check_manager=False, only_id=False)
if not user.is_superuser and not self.is_self_mon and not self.course.has_course_manager(user):
raise Http403('Вы не можете просматривать результаты по курсам, управляющими которых не являетесь')
return super(UserResultsView, self).dispatch(*args, **kwargs)
示例4: get_object
# 需要导入模块: from courses.models import Course [as 别名]
# 或者: from courses.models.Course import get_or_fail [as 别名]
def get_object(self):
self.course = Course.get_or_fail(self.kwargs['course_id'], user=self.request.user)
if self.kwargs['overview']:
self.lecture = get_object_or_404(Lecture, id=self.kwargs['lecture_id'])
self.pages = self.lecture.pages.only('title')
for page in self.pages:
page.num += 1
else:
self.lecture = get_object_or_404(Lecture.objects.only('title'), id=self.kwargs['lecture_id'])
if not self.lecture.in_course(self.course):
raise Http404('Запрошенная лекция отсутствует в составе курса')
paginator = Paginator(self.lecture.pages.all(), 1)
self.paginator = paginator
cur_page_num = self.kwargs['page']
try:
self.page = paginator.page(cur_page_num)
except InvalidPage:
raise Http404('Запрошенный номер страницы отсутствует')
return self.lecture