def get(self,request,video_id): video = Video.objects.get(id=int(video_id)) #通过外键找到章节再找到视频对应的课程 course = video.lesson.course course.students += 1 course.save() # 查询用户是否已经学习了该课程 user_courses = UserCourse.objects.filter(user=request.user,course=course) if not user_courses: # 如果没有学习该门课程就关联起来 user_course = UserCourse(user=request.user,course=course) user_course.save() #相关课程推荐 # 找到学习这门课的所有用户 user_courses = UserCourse.objects.filter(course=course) # 找到学习这门课的所有用户的id user_ids = [user_course.user_id for user_course in user_courses] # 通过所有用户的id,找到所有用户学习过的所有过程 all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程id course_ids = [all_user_course.course_id for all_user_course in all_user_courses] # 通过所有课程的id,找到所有的课程,按点击量去五个 relate_courses = Course.objects.filter(id__in=course_ids).order_by("-click_nums")[:5] # 资源 all_resources = CourseResource.objects.filter(course=course) return render(request,'../templates/course/course-play.html',{ 'course':course, 'all_resources':all_resources, 'relate_courses':relate_courses, 'video':video, })
def get(self, request, course_id): #课程 course = Course.objects.get(id=int(course_id)) # 查询用户是否已经学习了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: # 如果没有学习该门课程就关联起来 user_course = UserCourse(user=request.user, course=course) user_course.save() # 相关课程推荐 # 找到学习这门课的所有用户 user_courses = UserCourse.objects.filter(course=course) # 找到学习这门课的所有用户的id user_ids = [user_course.user_id for user_course in user_courses] # 通过所有用户的id,找到所有用户学习过的所有过程 all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程id course_ids = [all_user_course.course_id for all_user_course in all_user_courses] # 通过所有课程的id,找到所有的课程,按点击量去五个 relate_courses = Course.objects.filter(id__in=course_ids).order_by("-click_nums")[:5] course.students += 1 course.save() #资源 all_resources = CourseResource.objects.filter(course=course) return render(request, "../templates/course/course-video.html", { "course": course, "all_resources":all_resources, 'relate_courses': relate_courses, })
def get(self, request, course_id): course = Course.objects.get(id=int(course_id)) course.students += 1 course.save() # 查询用户是否已经关联该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_course = UserCourse(user=request.user, course=course) user_course.save() user_courses = UserCourse.objects.filter(course=course) user_ids = [user_course.user.id for user_course in user_courses] all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程ID course_ids = [ user_course.course.id for user_course in all_user_courses ] # 获取学过该用户学过的其他所有课程 relate_courses = Course.objects.filter( id__in=course_ids).order_by("-click_nums")[:5] all_resources = CourseResource.objects.filter(course=course) return render( request, 'course-video.html', { 'courses': course, 'course_resources': all_resources, 'relate_courses': relate_courses })
def get(self, request, video_id): video = Video.objects.get(id=int(video_id)) course = video.lesson.course user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_courses = UserCourse(user=request.user, course=course) user_courses.save() user_courses = UserCourse.objects.filter(course=course) user_ids = [user_course.user.id for user_course in user_courses] all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) course_ids = [ user_course.course.id for user_course in all_user_courses ] relate_courses = Course.objects.filter( id__in=course_ids).order_by('-click_nums')[:5] all_resources = CourseResource.objects.filter(course=course) return render( request, 'course-play.html', { 'courses': course, 'all_resources': all_resources, 'relate_courses': relate_courses, 'video': video, })
def get(self, request, video_id): video = Video.objects.get(id=int(video_id)) course = video.lesson.course course.students += 1 course.save() # 查询用户是否已经关联了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_course = UserCourse(user=request.user, course=course) user_course.save() user_courses = UserCourse.objects.filter(course=course) user_ids = [user_courses.user.id for user_courses in user_courses] all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程ID course_ids = [ user_courses.course.id for user_courses in all_user_courses ] # 获取学过该用户学过其他的所有课程 relate_courses = Course.objects.filter( id__in=course_ids).order_by("-click_nums")[:5] all_resources = CourseResourse.objects.filter(course=course) return render( request, 'course-play.html', { 'video': video, 'course': course, 'all_resources': all_resources, 'relate_courses': relate_courses, })
def get(self, request, course_id): course = Course.objects.get(id=int(course_id)) course.students += 1 course.save() # 查询用户是否已经关联了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: # 如果没有学习该门课程就关联起来 user_course = UserCourse(user=request.user, course=course) user_course.save() # 相关课程推荐 # 找到学习这门课的所有用户 user_courses = UserCourse.objects.filter(course=course) user_ids = [user_course.user.id for user_course in user_courses] # 通过所有用户的id,找到所有用户学习的所有课程 all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程id course_ids = [ all_user_course.course.id for all_user_course in all_user_courses ] # 获取学过该用户学过其他的所有课程 relate_courses = Course.objects.filter( id__in=course_ids).order_by("-click_nums")[:5] all_resources = CourseResource.objects.filter(course=course) return render( request, "course-video.html", { "course": course, "course_resources": all_resources, "relate_courses": relate_courses })
def get(self, request, course_id, video_id): """视屏页面显示""" # 查出此课程并将点击数加1 try: course = Course.objects.get(id=course_id) course.click_nums += 1 course.save() except Exception: return HttpResponseRedirect(reverse('course:list')) # 资料下载 resources = course.courseresource_set.all() # 和用户建立链接 user_course = course.usercourse_set.filter(course=course, user=request.user) if not user_course: user_course = UserCourse(course=course, user=request.user) user_course.save() course.students += 1 course.save() # 学习过该课的同学还学习过那些课程 users_course = UserCourse.objects.filter(course=course) users_id = [user.user_id for user in users_course] user_course = UserCourse.objects.filter( user_id__in=users_id).order_by('-course__click_nums').exclude( course_id=course.id) # 去重 distinct_set = set() all_user_course = [] for cou in user_course: if cou.course_id not in distinct_set: distinct_set.add(cou.course_id) all_user_course.append(cou) # 此课程的所有章节 cou_lesson = course.lesson_set.all() # 查询此章节小节 try: video = Video.objects.get(id=int(video_id)) except Exception: return HttpResponseRedirect(redirect('course:lesson')) # 组织模板上下文 context = { 'course': course, 'cou_lesson': cou_lesson, 'resources': resources, 'all_user_course': all_user_course, 'video': video, } # 返回数据 return render(request, 'course-play.html', context)
def get(self, request, course_id): """评论页显示""" # 查出此课程并将点击数加1 try: course = Course.objects.get(id=course_id) course.click_nums += 1 course.save() except Exception: return HttpResponseRedirect(reverse('course:list')) # 资料下载 resources = course.courseresource_set.all() # 和用户建立链接 user_course = course.usercourse_set.filter(course=course, user=request.user) if not user_course: user_course = UserCourse(course=course, user=request.user) user_course.save() course.students += 1 course.save() # 学习过该课的同学还学习过那些课程 users_course = UserCourse.objects.filter(course=course) users_id = [user.user_id for user in users_course] user_course = UserCourse.objects.filter( user_id__in=users_id).order_by('-course__click_nums').exclude( course_id=course.id) # 去重 distinct_set = set() all_user_course = [] for cou in user_course: if cou.course_id not in distinct_set: distinct_set.add(cou.course_id) all_user_course.append(cou) # 此课程的所有评论 course_comments = CourseComments.objects.filter(course=course)[::-1] # 组织模板上下文 context = { 'course': course, 'resources': resources, 'all_user_course': all_user_course, 'course_comments': course_comments, } has_reverse = request.GET.get('has_reverse') return render(request, 'course-comment.html', context)
def get(self, request, course_id): course = get_object_or_404(Course, id=int(course_id)) # 查询用户是否已经关联了该课程 user_course = UserCourse.objects.filter(user=request.user, course=course) if not user_course: user_course = UserCourse(user=request.user, course=course) user_course.save() course_resource = CourseResource.objects.filter(course=course) return render(request, 'course-video.html', { 'course': course, 'course_resource': course_resource, })
def get(self, request, course_id, play_id, *args, **kwargs): course = Course.objects.get(id=int(course_id)) course.click_nums += 1 course.save() # 关联用户与课程 user_course = UserCourse.objects.filter(user=request.user, course=course) if not user_course: user_course = UserCourse(user=request.user, course=course) user_course.save() course.students += 1 course.save() # 视频 video_play = Video.objects.get(id=int(play_id)) # 所有用户的评论 comments = CourseComments.objects.filter(course=course) # 显示学过该课程的人还学过哪些课程 all_user_courses = UserCourse.objects.filter(course=course) # 都学这门课的用户 all_user_id = [ user_course.user.id for user_course in all_user_courses ] # 都学这门课的用户ID all_courses = UserCourse.objects.filter( user_id__in=all_user_id)[:5] # 都学这门课的用户学的别的课程 # 所有学过当前课程人学的课程,排除当前课程 related_course = [] for course1 in all_courses: if course1.course.id != course.id: related_course.append(course1.course) # 课程资源 all_resourse = CourseResource.objects.filter(course=course) return render( request, 'course-play.html', { "course": course, 'all_resourse': all_resourse, 'related_course': related_course, 'comments': comments, 'video_play': video_play })
def get(self, request, course_id, video_id, *args, **kwargs): """ 获取课程章节信息 """ course = Course.objects.get(id=int(course_id)) course.click_nums += 1 course.save() video = Video.objects.get(id=int(video_id)) # 查询用户是否已经关联了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_course = UserCourse(user=request.user, course=course) user_course.save() course.students += 1 course.save() # 学习过该课程的所有同学 user_courses = UserCourse.objects.filter(course=course) user_ids = [user_course.user.id for user_course in user_courses] all_courses = UserCourse.objects.filter( user_id__in=user_ids).order_by("-course__click_nums")[:5] # related_courses = [user_course.course for user_course in all_courses if user_course.course.id != course.id] related_courses = [] for item in all_courses: if item.course.id != course.id: related_courses.append(item.course) course_resources = CourseResource.objects.filter(course=course) return render( request, "course-play.html", { "course": course, "course_resources": course_resources, "related_courses": related_courses, "video": video, })
def get(self, request, course_id): course = Course.objects.get(id=int(course_id)) all_resources = CourseResource.objects.filter(course=course) course.students += 1 course.save() # 查询用户是否已经学习了该课程 user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: # 如果没有学习该门课程就关联起来 user_course = UserCourse(user=request.user, course=course) user_course.save() # 找到学习这门课的所有用户 user_courses = UserCourse.objects.filter(course=course) # 找到学习这门课的所有用户的id user_ids = [user_course.user_id for user_course in user_courses] # 通过所有用户的id,找到所有用户学习过的所有过程 all_user_courses = UserCourse.objects.filter(user_id__in=user_ids) # 取出所有课程id course_ids = [ all_user_course.course_id for all_user_course in all_user_courses ] # 通过所有课程的id,找到所有的课程,按点击量去五个 relate_courses = Course.objects.filter( id__in=course_ids).order_by("-click_nums")[:5] # vedio = course.lesson_set.first().get_lesson_vedio().first().name # print(vedio) return render( request, "course-video.html", { "course": course, 'all_resources': all_resources, 'relate_courses': relate_courses, })
def get(self, request, cou_id): course = Course.objects.get(id=int(cou_id)) if not UserCourse.objects.filter(user=request.user, course=course): course.students += 1 course.save() user_courses = UserCourse.objects.filter(user=request.user, course=course) if not user_courses: user_course = UserCourse(user=request.user, course=course) user_course.save() user_courses = UserCourse.objects.filter(course=course) users_ids = [user_course.user.id for user_course in user_courses] all_user_courses = UserCourse.objects.filter(user_id__in=users_ids) courses_ids = [ user_course.course.id for user_course in all_user_courses ] relate_courses = Course.objects.filter(id__in=courses_ids)[:5] lessons = Lesson.objects.filter(course=course) return render( request, 'course-video.html', { 'course': course, 'lessons': lessons, 'relate_courses': relate_courses, })