def course_agree(cid_li):
        """审批同意操作"""
        if cid_li is None:
            return False

        for cid in cid_li:
            try:
                course = Courses.query.get(int(cid))
                course.ispass = 1
                course.isexamine = 1
                db.session.add(course)
                # 把课程添加到缓存
                RedisService.load_agree_course(Courses.list_to_dict(course))
            except Exception as e:
                print(e)
                ExceptionLog.model_error(e.__str__())
                try:
                    db.session.rollback()
                except Exception as ex:
                    print(ex)
                    ExceptionLog.other_error(ex.__str__())
                return False

        try:
            db.session.commit()
            return True
        except Exception as e:
            print(e)
            ExceptionLog.model_error(e.__str__())
            return False
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 set_seltime(stime, etime, remark, caid, lid):
        """设置选课时段操作"""
        # 查询数据库,并把没有添加到缓存未结束的课程添加到redis
        course_li = CourseManage.get_can_add_to_redis(caid)
        if course_li is not None:
            for course in course_li:
                RedisService.load_agree_course(Courses.list_to_dict(course))

        # 保存记录到mysql,添加数据缓存到redis
        return RedisService.set_sel_time(stime, etime, caid, lid, remark)
Beispiel #4
0
def stu_manage():
    """显示学生信息的学生管理页面"""
    admin = session.get("admin")
    if admin is None:
        return render_template("page404.html"), 404

    stu_li = StuManage.get_all()
    black_li = RedisService.get_stu_blacklist()
    return render_template("admin/stu_manage.html",
                           stu_li=stu_li,
                           black_li=black_li)  # 返回学生管理页面信息
Beispiel #5
0
    def save_preview(sno, cid_li):
        """保存学生的预选课程"""
        ln = len(cid_li)
        if ln > 3:
            return False
        cids = ""
        for i in range(ln):
            cid = str(cid_li[i])
            if i == ln - 1:
                cids = cids + cid
                continue
            cids = cids + cid + ","

        try:
            RedisService.preview_sel(sno, cids)
            return True

        except Exception as e:
            print(e)
            return False
Beispiel #6
0
def tea_manage():
    """显示教师信息的教师管理页面"""
    admin = session.get("admin")
    if admin is None:
        return render_template("page404.html"), 404

    tea_li = TeaManage.get_all()
    black_li = RedisService.get_tea_blacklist()
    return render_template("admin/tea_manage.html",
                           tea_li=tea_li,
                           black_li=black_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)
def course_apply_page():
    """开课申请页面"""
    tea = session.get("tea")
    if tea is None:
        return render_template("page404.html"), 404

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

    course_li = CourseManage.get_by_tid_noend(tid)
    room_li = ClassroomManage.get_by_caid(tea.caid)

    return render_template("teacher/course_apply_page.html",
                           course_li=course_li,
                           room_li=room_li)
Beispiel #9
0
def tea_refuse():
    admin = session.get("admin")
    if admin is None:
        return jsonify({
            "bl": 400,
            "tip": "账号已下线,请重新登录!"
        })
    tid = request.form.get("tid")
    bl = RedisService.tea_refuse(tid)
    if bl is True:
        return jsonify({
            "bl": 200,
            "tip": "禁止开课操作成功!"
        })
    else:
        return jsonify({
            "bl": 400,
            "tip": "禁止开课操作失败!"
        })
Beispiel #10
0
def stu_agree():
    admin = session.get("admin")
    if admin is None:
        return jsonify({
            "bl": 400,
            "tip": "账号已下线,请重新登录!"
        })

    sid = request.form.get("sid")
    bl = RedisService.stu_agree(sid)
    if bl is True:
        return jsonify({
            "bl": 200,
            "tip": "解除操作成功!"
        })
    else:
        return jsonify({
            "bl": 400,
            "tip": "解除操作失败!"
        })
Beispiel #11
0
    def get_preview_course(caid, ctype, week, page, num=10):
        """获取所有可以的预选课程"""
        campus_li = CampusManage.get_all() if caid == -1 else [
            CampusManage.get_by_id(caid)
        ]
        course_li = list()
        for campus in campus_li:
            course_li.extend(RedisService.get_selcourse(campus.get("id")))

        if week != "all" or ctype != "all":
            for course in course_li[::-1]:
                if week != "all" and ctype != "all":
                    if week != course.get("week") or ctype != course.get(
                            "ctype"):
                        course_li.remove(course)
                        continue

                if week != "all" and ctype == "all" and week != course.get(
                        "week"):
                    course_li.remove(course)
                    continue

                if week == "all" and ctype != "all" and ctype != course.get(
                        "ctype"):
                    course_li.remove(course)
                    continue

        page = page if page > 0 else 1
        sum = len(course_li)  # 总数
        pagenum = math.ceil(sum / num)  # 最大页数
        st = (page - 1) * num if (page - 1) * num < (
            sum - 1) else (pagenum - 1) * num  # 截取的开始位置
        end = st + num if (st + num) < sum else sum  # 截取的结束位置

        return course_li[
            st:end], sum, pagenum, page if page <= pagenum else pagenum
Beispiel #12
0
    def save_sel_course(sid, sno, caid, cid_li):
        """保存学生选课信息"""
        ln = len(cid_li)
        if ln > 3:
            return False, ""
        cids = ""
        for i in range(ln):
            try:
                cid = str(cid_li[i])
                num = RedisService.get_selnum(caid, cid)
                if num == 0:
                    continue
                if not RedisService.selnum_sub1(caid, cid):
                    continue
                sel = Selcourses(sid=sid,
                                 cid=cid,
                                 cretime=time.strftime("%Y-%m-%d %H:%M:%S",
                                                       time.localtime()))
                db.session.add(sel)
                if i == ln - 1:
                    cids = cids + cid
                else:
                    cids = cids + cid + ","

            except Exception as e:
                print(e)
                return False, ""

        try:
            RedisService.save_sel(sno, cids)
            RedisService.del_preview(sno)
            db.session.commit()
            return True, cids
        except Exception as e:
            print(e)
            return False, ""
Beispiel #13
0
 def get_predone(sno):
     """获取预选成功的课程列表"""
     return RedisService.get_preview(sno)
Beispiel #14
0
 def get_preview_bycaid(caid):
     """获取对应校区可以预选的课程列表"""
     return RedisService.get_selcourse(caid)
Beispiel #15
0
 def remove_sel_course(sid, sno, cid, caid):
     """课程退选操作业务"""
     return RedisService.judge_and_remove(sid, sno, cid, caid)
 def over_seltime(id_li):
     """结束选课时段记录操作"""
     # 把选课时段记录结束,删除选课时段记录的redis缓存
     return RedisService.del_sel_time(id_li)
Beispiel #17
0
 def is_can_saveachi(caid):
     """判断是否可以进行成绩录入"""
     return RedisService.judge_can_saveachi(caid)
Beispiel #18
0
def stu_refuse():
    admin = session.get("admin")
    if admin is None:
        return jsonify({
            "bl": 400,
            "tip": "账号已下线,请重新登录!"
        })
    sid = request.form.get("sid")
    bl = RedisService.stu_refuse(sid)
    if bl is True:
        return jsonify({
            "bl": 200,
            "tip": "禁止选课操作成功!"
        })
    else:
        return jsonify({
            "bl": 400,
            "tip": "禁止选课操作失败!"
        })

#
#
# @app_admin.route("/teaAdd", methods=["POST"])
# def tea_add():
#     """教师添加操作"""
#     data = request.form
#     tno = data.get("tno")
#     tname = data.get("tname")
#     tsex = data.get("tsex")
#     collegename = data.get("collegename")
#     password = data.get("password")
#     tel = data.get("tel")
#
#     # 该方法返回布尔值
#     bl = TeaManage.add(
#         tno,
#         tname,
#         tsex,
#         collegename,
#         password,
#         tel
#     )
#
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#         })
#
#
# @app_admin.route("/teaDel", methods=["POST"])
# def tea_del():
#     """教师删除操作"""
#     tid = request.form.get("tid")
#     bl = TeaManage.delete(tid)
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#         })
#
#
# @app_admin.route("/teaChange", methods=["POST"])
# def tea_change():
#     """教师信息修改操作"""
#     data = request.form
#     tid = data.get("tid")
#     tno = data.get("tno")
#     tname = data.get("tname")
#     tsex = data.get("tsex")
#     collegename = data.get("collegename")
#     tel = data.get("tel")
#     bl = TeaManage.update(tid, tno, tname, tsex, collegename, tel)
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#     })

#
# @app_admin.route("/teaGet", methods=["POST"])
# def tea_get():
#     """各种筛选获取教师信息"""
#     data = request.form
#     key = data.get("key")
#     value = data.get("value")
#
#     if "tid" == key:
#         tea = TeaManage.get_by_id(value)
#         return jsonify(tea)
#     elif "tname" == key:
#         tea_li = TeaManage.get_by_name(value)
#         return jsonify(tea_li)
#     elif "collegename" == key:
#         tea_li = TeaManage.get_by_college(value)
#         return jsonify(tea_li)
#
#
# @app_admin.route("/stuAdd", methods=["POST"])
# def stu_add():
#     """学生添加操作"""
#     data = request.form
#
#     sno = data.get("sno")
#     sname = data.get("sname")
#     ssex = data.get("ssex")
#     collegename = data.get("collegename")
#     classname = data.get("classname")
#     endate = data.get("endate")
#     nativeplace = data.get("nativeplace")
#     birthday = data.get("birthday")
#     password = data.get("password")
#     tel = data.get("tel")
#     campus = data.get("campus")
#     degree = data.get("degree")
#     pid = data.get("pid")
#
#     bl = StuManage.add(
#         sno,
#         sname,
#         ssex,
#         collegename,
#         classname,
#         endate,
#         nativeplace,
#         birthday,
#         password,
#         tel,
#         campus,
#         degree,
#         pid
#     )
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#     })
#
#
# @app_admin.route("/stuDel", methods=["POST"])
# def stu_del():
#     """学生删除操作"""
#     sid = request.form.get("sid")
#     bl = StuManage.delete(sid)
#
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#     })
#
#
# @app_admin.route("/stuChange", methods=["POST"])
# def stu_change():
#     """学生信息修改操作"""
#     data = request.form
#     sid = data.get("sid")
#     sno = data.get("sno")
#     sname = data.get("sname")
#     ssex = data.get("ssex")
#     collegename = data.get("collegename")
#     classname = data.get("classname")
#     endate = data.get("endate")
#     nativeplace = data.get("nativeplace")
#     birthday = data.get("birthday")
#     tel = data.get("tel")
#     campus = data.get("campus")
#     degree = data.get("degree")
#     pid = data.get("pid")
#
#     bl = StuManage.update(sid, sno, sname, ssex, collegename, classname,
#                           endate, nativeplace, birthday, tel, campus, degree, pid)
#
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#         })
#
#
# @app_admin.route("/stuGet", methods=["POST"])
# def stu_get():
#     """各种筛选获取学生信息"""
#     data = request.form
#     key = data.get("key")
#     value = data.get("value")
#
#     if "sid" == key:
#         stu = StuManage.get_by_id(value)
#         return jsonify(stu)
#
#     elif "sname" == key:
#         stu_li = StuManage.get_by_name(value)
#         return jsonify(stu_li)
#
#     elif "collegename" == key:
#         stu_li = StuManage.get_by_college(value)
#         return jsonify(stu_li)
#
#     elif "classname" == key:
#         stu_li = StuManage.get_by_class(value)
#         return jsonify(stu_li)
#
#     elif "endate" == key:
#         stu_li = StuManage.get_by_endate(value)
#         return jsonify(stu_li)
#
#     elif "campus" == key:
#         stu_li = StuManage.get_by_campus(value)
#         return jsonify(stu_li)
#
#     elif "degree" == key:
#         stu_li = StuManage.get_by_degree(value)
#         return jsonify(stu_li)



# @app_admin.route("/courseManage")
# def course_manage():
#     """显示课程信息的课程管理页面"""
#     admin = session.get("admin")
#     if admin is None:
#         return render_template("page404.html"), 404
#
#     course_li = CourseManage.get_all()
#     return render_template("admin/course_manage.html", course_li=course_li)
#
#
# @app_admin.route("/courseAdd", methods=["POST"])
# def course_add():
#     """课程添加操作"""
#     data = request.form
#     cname = data.get("cname")
#     ctype = data.get("ctype")
#     classweek = data.get("classweek")
#     classtime = data.get("classtime")
#     classplace = data.get("classplace")
#     tid = data.get("tid")
#     credit = data.get("credit")
#
#     bl = CourseManage.add(cname, ctype, classweek, classtime, classplace, tid, credit)
#
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#         })
#
#
# @app_admin.route("/courseDel", methods=["POST"])
# def course_del():
#     """课程删除操作"""
#     cid = request.form.get("cid")
#
#     bl = CourseManage.delete(cid)
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#         })
#
#
# @app_admin.route("/courseChange", methods=["POST"])
# def course_change():
#     """课程修改操作"""
#     data = request.form
#     cid = data.get("cid")
#     cname = data.get("cname")
#     ctype = data.get("ctype")
#     classweek = data.get("classweek")
#     classtime = data.get("classtime")
#     classplace = data.get("classplace")
#     tid = data.get("tid")
#     credit = data.get("credit")
#
#     bl = CourseManage.update(cid, cname, ctype, classweek, classtime, classplace, tid, credit)
#     if bl is True:
#         return jsonify({
#             "bl": 200
#         })
#     else:
#         return jsonify({
#             "bl": 400
#         })
#
#
# @app_admin.route("/courseGet", methods=["POST"])
# def course_get():
#     """各种筛选获取课程信息"""
#     data = request.form
#     key = data.get("key")
#     value = data.get("value")
#
#     if "cid" == key:
#         course = CourseManage.get_by_id(value)
#         return jsonify(course)
#
#     elif "cname" == key:
#         course_li = CourseManage.get_by_name(value)
#         return jsonify(course_li)
#
#     elif "ctype" == key:
#         course_li = CourseManage.get_by_type(value)
#         return jsonify(course_li)
#
#     elif "classweek" == key:
#         course_li = CourseManage.get_by_week(value)
#         return jsonify(course_li)
#
#     elif "classtime" == key:
#         course_li = CourseManage.get_by_time(value)
#         return jsonify(course_li)
#
#     elif "classplace" == key:
#         course_li = CourseManage.get_by_place(value)
#         return jsonify(course_li)
#
#     elif "ispass" == key:
#         course_li = CourseManage.get_by_pass(value)
#         return jsonify(course_li)
#
#     elif "isexamine" == key:
#         course_li = CourseManage.get_by_examine(value)
#         return jsonify(course_li)
#
#     elif "tid" == key:
#         course_li = CourseManage.get_by_tid(value)
#         return jsonify(course_li)
#
#     elif "credit" == key:
#         course_li = CourseManage.get_by_credit(value)
#         return jsonify(course_li)