def preview_page():
    """课程预选页面"""
    stu = session.get("stu")
    if stu is None:
        return render_template("page404.html"), 404

    if not RedisService.judgestu_iscan_selectcourse(stu.id):
        return render_template("not_allow.html", message="你被禁止选课,有问题请联系管理员...")

    crd_sum = StuService.count_credit(stu.id)
    if crd_sum >= 33:
        return render_template("not_allow.html", message="所修学分已满,不需要选课...")

    if RedisService.judge_can_sel(stu):
        return redirect(url_for("app_stu.sel_course_page"))

    data = request.form
    page = int(data.get("page", request.args.get("page", 1)))
    caid = stu.caid
    ctype = data.get("ctype", session.get("ctype", "all"))
    week = data.get("week", session.get("week", "all"))
    session["caid"] = caid
    session["ctype"] = ctype
    session["week"] = week

    course_li, sum, pagenum, page = StuService.get_preview_course(caid, ctype, week, page, 6)
    preview_li = StuService.get_predone(stu.sno)

    return render_template("student/preview_page.html",
                           course_li=course_li,
                           page=page,
                           pagenum=pagenum,
                           sum=sum,
                           preview_li=preview_li)
def sel_course_page():
    """选课操作页面"""
    stu = session.get("stu")
    if stu is None:
        return render_template("page404.html"), 404

    if RedisService.judge_can_sel(stu) is False:
        return render_template("not_allow.html", message="不在选课时段,无法进行选课和退选...")

    if not RedisService.judgestu_iscan_selectcourse(stu.id):
        return render_template("not_allow.html", message="你被禁止选课,有问题请联系管理员...")

    crd_sum = StuService.count_credit(stu.id)
    if crd_sum >= 33:
        return render_template("not_allow.html", message="所修学分已满,不需要选课...")

    data = request.form
    page = int(data.get("page", request.args.get("page", 1)))
    caid = stu.caid
    ctype = data.get("ctype", session.get("ctype", "all"))
    week = data.get("week", session.get("week", "all"))
    session["caid"] = caid
    session["ctype"] = ctype
    session["week"] = week

    course_li, sum, pagenum, page = StuService.get_preview_course(caid, ctype, week, page, 16)
    preview_li = StuService.get_predone(stu.sno)
    sel_li = SelcourseManage.get_by_sidnoend(stu.id)

    return render_template("student/sel_course.html",
                           course_li=course_li,
                           preview_li=preview_li,
                           sel_li=sel_li,
                           page=page,
                           pagenum=pagenum,
                           sum=sum)