Beispiel #1
0
    def get(self, request, teacher_id):
        """详情页显示"""
        # 查询出此教师
        try:
            teacher = Teacher.objects.get(id=int(teacher_id))
        except Exception:
            return HttpResponseRedirect(reverse('org:teacher_list'))

        # 讲师排行傍
        order_all_teacher = Teacher.objects.all().order_by('-work_years')[:5]

        # 查询出此教师所属的机构
        org = teacher.org

        # 查询此教师下的所有课程
        teacher_all_course = teacher.course_set.all()

        # 使用自定义工具查看用户时候收藏过当前机构和课程
        has_collect_teacher = judge_org_login(request, teacher.id, 3)
        has_collect_org = judge_org_login(request, org.id, 2)

        # 组织模板上下文
        context = {
            "org": org,
            'order_all_teacher': order_all_teacher,
            'teacher': teacher,
            'teacher_all_course': teacher_all_course,
            'has_collect_org': has_collect_org,
            'has_collect_teacher': has_collect_teacher,
        }

        # 返回数据
        return render(request, 'teacher-detail.html', context)
Beispiel #2
0
    def get(self, request, org_id):
        """显示机构介绍
        render-Prama: org,
        """
        # 校验数据
        try:
            org_id = int(org_id)
        except Exception:
            return HttpResponseRedirect(reverse('org:org_list'))

        # 处理业务
        # 查询出课程机构
        try:
            org = CourseOrg.objects.get(id=org_id)
        except CourseOrg.DoesNotExist:
            return HttpResponseRedirect(reverse('org:org_list'))

        # 检查用户是否登录,是否关注过此机构
        judge_collect = judge_org_login(request, org_id, 2)

        # 返回数据
        return render(request, 'org-detail-desc.html', {
            'org': org,
            'judge_collect': judge_collect
        })
Beispiel #3
0
    def get(self, request, org_id):
        """显示机构讲师"""
        # 校验数据
        try:
            org_id = int(org_id)
        except Exception:
            return HttpResponseRedirect(reverse('org:org_list'))

        # 处理业务
        # 查询出课程机构
        try:
            org = CourseOrg.objects.get(id=org_id)
        except CourseOrg.DoesNotExist:
            return HttpResponseRedirect(reverse('org:org_list'))
        # 查出此课程机构下的所有讲师
        teachers = org.teacher_set.all()

        # 检查用户是否登录,是否关注过此机构
        judge_collect = judge_org_login(request, org_id, 2)

        # 组织上下文
        context = {
            'teachers': teachers,
            'active': 'teacher',
            'org': org,
            'judge_collect': judge_collect,
        }

        # 返回数据
        return render(request, 'org-detail-teachers.html', context)
Beispiel #4
0
    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'))

        # 查看用户是否收藏过此课程
        has_collect_course = judge_org_login(request, course_id, 1)
        org_id = course.course_org.id
        has_collect_org = judge_org_login(request, org_id, 2)

        # 根据课程标签相关课程推荐
        tags = course.coursetag_set.all()  # 本课程的所有标签
        # 取出此课程的所有标签,为了达到多个标签无重复,这里使用集合数据结构
        tag_set = set()
        for tag in tags:
            tag_set.add(tag.tag)
        # 查询出带有标签tag_ste集合里标签
        all_tags = CourseTag.objects.filter(tag__in=tag_set).exclude(
            course__id=course.id)
        # 取粗这些标签中的所有课程,放到tag_courses中
        tag_courses = []
        # 遍历取出
        for cou in all_tags[:3]:
            tag_courses.append(cou.course)

        # 组织模板上下文
        context = {
            'course': course,
            'has_collect_course': has_collect_course,
            'has_collect_org': has_collect_org,
            'org_id': org_id,
            'tag_courses': tag_courses,
        }

        # 返回数据
        return render(request, 'course-detail.html', context)
Beispiel #5
0
    def get(self, request, org_id):
        """显示课程机构主页"""
        # 校验数据
        try:
            org_id = int(org_id)
        except Exception:
            return HttpResponseRedirect(reverse('org:org_list'))

        # 处理业务
        # 点击次数加1
        try:
            org = CourseOrg.objects.get(id=org_id)
        except CourseOrg.DoesNotExist:
            return HttpResponseRedirect(reverse('org:org_list'))

        org.click_nums += 1
        org.save()

        # 全部课程查询,取前四
        portion_course = org.course_set.all()[:4]

        # 查询全部教师,取一个
        try:
            portion_teacher = org.teacher_set.all()[0]
            teacher_none = False
        except IndexError:
            teacher_none = True
            portion_teacher = None

        # 检查用户是否登录,是否关注过此机构
        judge_collect = judge_org_login(request, org_id, 2)

        # 组织上下文
        context = {
            'org': org,
            'portion_course': portion_course,
            'portion_teacher': portion_teacher,
            'teacher_none': teacher_none,
            'active': 'home',
            'judge_collect': judge_collect,
        }

        # 返回数据
        return render(request, 'org-detail-homepage.html', context)
Beispiel #6
0
    def get(self, request, org_id):
        """机构页显示"""
        # 校验数据
        try:
            org_id = int(org_id)
        except Exception:
            return HttpResponseRedirect(reverse('org:org_list'))

        # 处理业务
        # 查询出课程机构
        try:
            org = CourseOrg.objects.get(id=org_id)
        except CourseOrg.DoesNotExist:
            return HttpResponseRedirect(reverse('org:org_list'))

        # 此机构下全部课程查询
        all_course = org.course_set.all()

        # 对前边课程进行分页
        try:
            page = request.GET.get('page', 1)
        except PageNotAnInteger:
            page = 1
        # 对课程分页  Paginator(分页集合, per_page=每页显示多少, request=request)
        p = Paginator(all_course, per_page=1, request=request)

        pag_course = p.page(page)

        # 检查用户是否登录,是否关注过此机构
        judge_collect = judge_org_login(request, org_id, 2)

        # 组织上下文
        context = {
            'pag_course': pag_course,
            'active': 'course',
            'org': org,
            'judge_collect': judge_collect,
        }

        # 返回数据
        return render(request, 'org-detail-course.html', context)