Пример #1
0
def admin_set(request):
    if request.method == "POST":
        response = {'code': 200, 'msg': "添加管理员账号成功~", "data": {}}
        request_json = request.POST
        # TODO 此处应该出参数校验
        nickname = request_json.get("nickname", "")
        mobile = request_json.get("mobile", "")
        email = request_json.get("email", "")
        login_name = request_json.get("login_name", "")
        login_pwd = request_json.get("login_pwd", "")
        id = request_json.get("id", "")

        if id:
            user = User.objects.filter(id=id)[0]
            user.nickname = nickname
            user.mobile = mobile
            user.email = email
            user.username = login_name
            if login_pwd == "******":
                pass
            else:
                password = UserService.gene_pwd(login_pwd, user.salt)
                user.password = password
            user.save()
            response["msg"] = "修改成功"
        else:
            if len(User.objects.filter(username=login_name)) > 0:
                response["msg"] = "登录名已经存在~"
                response["code"] = 1
            else:
                salt = UserService.gene_salt()
                password = UserService.gene_pwd(login_pwd, salt)
                save_user = {
                    "username": login_name,
                    "password": password,
                    "salt": salt,
                    "type": 2,
                    "nickname": nickname,
                    "email": email,
                    "mobile": mobile
                }
                User.objects.create(**save_user)

        return JsonResponse(response)
    rep = {}
    id = request.GET.get("id", "")
    info = {'type': -1}
    if id:
        user = User.objects.filter(id=id).first()
        if user:
            info["nickname"] = user.nickname
            info["mobile"] = user.mobile
            info['email'] = user.email
            info['login_name'] = user.username
            info['id'] = user.id
            info['type'] = user.type
    else:
        pass
    rep["info"] = info
    return ops_render(request, "account/set.html", rep)
Пример #2
0
def edit():
    if request.method == "GET":
        return ops_render("user/edit.html", {'current': 'edit'})

    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values
    nickname = req['nickname'] if 'nickname' in req else ''
    email = req['email'] if 'email' in req else ''

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的姓名~~"
        return jsonify(resp)

    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的邮箱~~"
        return jsonify(resp)

    user_info = g.current_user
    user_info.nickname = nickname
    user_info.email = email

    db.session.add(user_info)
    db.session.commit()
    return jsonify(resp)
Пример #3
0
def new(request):
    if request.myself.type == 2:
        return HttpResponse("管理员就不用进来了~,服务器会奔溃的")
    major_second_array = MajorSecond.objects.all()

    majors = []
    for major_second_item in major_second_array:
        major_first = major_second_item.major_first
        major_first_id = major_second_item.major_first.id
        major_first_name = major_second_item.major_first.name
        major_class = major_first.major_class
        major_class_id = major_class.id
        major_class_name = major_class.name
        major_second_id = major_second_item.id
        major_second_name = major_second_item.name
        major_second_declare_start_time = major_second_item.declare_start_time
        major_second_declare_end_time = major_second_item.declare_end_time
        major_second_review_start_time = major_second_item.review_start_time
        major_second_review_end_time = major_second_item.review_end_time
        major_second_add_time = major_second_item.add_time
        majors.append({
            "major_first_id": major_first_id,
            "major_first_name": major_first_name,
            "major_class_id": major_class_id,
            "major_class_name": major_class_name,
            "major_second_id": major_second_id,
            "major_second_name": major_second_name,
            "major_second_declare_start_time": major_second_declare_start_time,
            "major_second_declare_end_time": major_second_declare_end_time,
            "major_second_review_start_time": major_second_review_start_time,
            "major_second_review_end_time": major_second_review_end_time,
            "major_second_add_time": major_second_add_time,
        })
    ret = {"majors": majors}
    return ops_render(request, "new/index.html", ret)
Пример #4
0
def major_second(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    rep = {}
    my_list = []
    major_class_array = MajorSecond.objects.all()
    for class_item in major_class_array:
        first = class_item.major_first
        item = {
            "id": class_item.id,
            "name": class_item.name,
            "status_desc": "正常" if class_item.status == 1 else "删除",
            "weight": class_item.weight,
            "status": class_item.status,
            "first_name": first.name,
            "class_name": first.major_class.name,
            "declare": {
                "start": class_item.declare_start_time,
                "end": class_item.declare_end_time
            },
            "review": {
                "start": class_item.review_start_time,
                "end": class_item.review_end_time
            }
        }
        my_list.append(item)
    rep["list"] = my_list
    rep["current"] = "second"
    rep["status_mapping"] = ["正常", "删除"]
    rep["search_con"] = {"status": "正常"}

    return ops_render(request, "major/major_second.html", rep)
Пример #5
0
def index():
    req = request.values
    resp_data = {}
    page = int(req['p']) if ('p' in req and req['p']) else 1
    query = db.session.query(MAC, ARP).outerjoin(ARP, ARP.macadd == MAC.macadd)
    if 'mix_kw' in req:
        rule = or_(MAC.macadd.like("%{0}%".format(req['mix_kw'])),
                   ARP.ipaddr.like("%{0}%".format(req['mix_kw'])))
        # query = query.filter(rule)
        query = query.filter(rule)
    # query = MAC.query.join(ARP, MAC.MacAdd == ARP.MacAdd).all()

    page_params = {
        'total': query.count(),
        'page_size': app.config['PAGE_SIZE'],
        'page': page,
        'display': app.config['PAGE_DISPLAY'],
        'url': request.full_path.replace("&p={}".format(page), "")
    }
    pages = iPagination(page_params)
    offset = (page - 1) * app.config['PAGE_SIZE']
    limit = app.config['PAGE_SIZE'] * page
    # list = query.order_by(MAC.Id.desc()).all()[offset:limit]
    # list=query.outerjion(ARP).all()[offset:limit]
    list = query.order_by(MAC.swip).all()[offset:limit]

    resp_data['info'] = list
    resp_data['pages'] = pages
    resp_data['search_con'] = req
    return ops_render('index/index.html', resp_data)
Пример #6
0
def set():
    if request.method == 'GET':
        resp_date = {}
        info = None
        resp_date['info'] = info
        return ops_render('mon/set.html', resp_date)
    resp = {'code': 200, 'msg': '设置成功', 'data': {}}
    req = request.values
    ip = req['ipaddr'] if 'ipaddr' in req else ''
    if ip is None:
        resp['code'] = -1
        resp['msg'] = '交换机输入错误'
        return jsonify(resp)

    for item in json.loads(ip):
        has_in = Monitor.query.filter(Monitor.ipaddr == item).first()
        if has_in:
            resp['code'] = -1
            resp['msg'] = 'IP地址:%s 已存在,请更改' % item
            return jsonify(resp)
        db.session.execute(Monitor.__table__.insert(),
                           [{
                               'ipaddr': item,
                               'create_time': getCurrentDate(),
                               'update_time': getCurrentDate()
                           }])
        db.session.commit()
    return jsonify(resp)
Пример #7
0
def login():
    if request.method == "GET":
        return ops_render("user/login.html")

    resp = {'code': 200, 'msg': '登录成功', 'data': {}}
    req = request.values
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''

    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名~~"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd) < 1:
        resp['code'] = -1
        resp['msg'] = "请输入正确的邮箱密码~~"
        return jsonify(resp)

    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名和密码-1~~"
        return jsonify(resp)

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名和密码-2~~"
        return jsonify(resp)
    response = make_response(json.dumps({'code': 200, 'msg': '登录成功~~'}))
    response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' %
                        (UserService.geneAuthCode(user_info), user_info.uid),
                        60 * 60 * 24 * 120)  # 保存120天
    return response
Пример #8
0
def resume(request):
    that = request.myself
    ret = {'that': that}
    uid = request.GET.get("uid", "")
    user = that
    if uid:
        users = User.objects.filter(id=uid)
        if len(users) == 1:
            user = users[0]
            ret["that"] = user
        else:
            return HttpResponse("服务器异常,没有该用户~")
    enrolls = Enroll.objects.filter(uid=user, status=1)
    if len(enrolls) != 1:
        if request.myself.type == 2:
            return HttpResponse("管理员就不用进来了~,服务器会奔溃的")
        return HttpResponseRedirect("/new")
    p_c_or_q_array = ProfessionalCertificationOrQualification.objects.filter(
        uid=user)
    ret['p_c_or_q_array'] = p_c_or_q_array
    thesis_works_array = ThesisWorks.objects.filter(uid=user)
    ret['thesis_works_array'] = thesis_works_array
    national_patent_array = NationalPatent.objects.filter(uid=user)
    ret['national_patent_array'] = national_patent_array
    technological_innovation_array = TechnologicalInnovation.objects.filter(
        uid=user)
    ret['technological_innovation_array'] = technological_innovation_array
    skills_competition_array = SkillsCompetition.objects.filter(uid=user)
    ret['skills_competition_array'] = skills_competition_array
    honour_array = Honour.objects.filter(uid=user)
    ret['honour_array'] = honour_array
    professional_array = Professional.objects.filter(uid=user)
    ret['professional_array'] = professional_array
    edu_array = Edu.objects.filter(uid=user)
    ret['edu_array'] = edu_array
    mark_ret = sum_mark(
        user,
        p_c_or_q_array=p_c_or_q_array,
        thesis_works_array=thesis_works_array,
        national_patent_array=national_patent_array,
        technological_innovation_array=technological_innovation_array,
        skills_competition_array=skills_competition_array,
        honour_array=honour_array,
        professional_array=professional_array,
        edu_array=edu_array)
    ret['mark'] = mark_ret
    major = enrolls[0].major
    ret['major_second'] = major
    n_time = datetime.datetime.now()

    is_update = False
    if n_time > major.declare_start_time and n_time < major.declare_end_time:
        is_update = True
    if request.myself.type == 2:
        is_update = True
    ret["is_update"] = is_update
    return ops_render(request, "new/resume.html", ret)
Пример #9
0
def info():
    resp_data = {}
    req = request.values
    id = req['id'] if 'id' in req or 'id' != None else 0
    log_info = MonLog.query.filter_by(mon_id=id).limit(10)
    mon_info = Monitor.query.filter_by(id=id).first()
    # mac_info= MAC.query.filter_by(IpAdd=sw_info.IpAdd).first()
    resp_data['info'] = log_info
    resp_data['moninfo'] = mon_info
    return ops_render('mon/info.html', resp_data)
Пример #10
0
def info():
    resp_data = {}
    req = request.values
    swid = req['id'] if 'id' in req or 'id' == None else 0
    sw_info = Sw.query.filter_by(id=swid).first()
    mac_info = db.session.query(MAC, ARP).outerjoin(
        ARP,
        ARP.macadd == MAC.macadd).filter(MAC.swip == sw_info.ipaddr).order_by(
            MAC.port).all()
    # mac_info= MAC.query.filter_by(IpAdd=sw_info.IpAdd).first()
    resp_data['info'] = sw_info
    resp_data['macinfo'] = mac_info
    return ops_render('switch/info.html', resp_data)
Пример #11
0
def major_first_set(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    if request.method == "POST":
        response = {'code': 200, 'msg': "添加一级专业成功~", "data": {}}
        request_json = request.POST
        name = request_json.get("name", "")
        weight = request_json.get("weight", 1)
        id = request_json.get("id")
        major_id = request_json.get("major_id")

        major = MajorClass.objects.filter(id=major_id)[0]
        if id:
            firsts = MajorFirst.objects.filter(id=id)
            if firsts:
                first = firsts[0]
                first.name = name
                first.weight = weight
                first.major_class = major
                first.save()
            return JsonResponse(response)
        save_dice = {"name": name, "weight": weight, "major_class": major}
        MajorFirst.objects.create(**save_dice)

        return JsonResponse(response)

    rep = {}
    id = request.GET.get("id")

    info = {}
    major_first_array = MajorFirst.objects.filter(id=id)
    if major_first_array:
        first = major_first_array[0]
        name = first.name
        weight = first.weight
        info["name"] = name
        info["weight"] = weight
        info["id"] = first.id
        info['major_id'] = first.major_class.id
    rep["info"] = info

    major_list = []
    # 查询所有可以使用的分类
    majors = MajorClass.objects.filter(status=1)
    for major in majors:
        id = major.id
        name = major.name
        major_list.append({"id": id, "name": name})

    rep["major_list"] = major_list
    return ops_render(request, "major/major_first_set.html", rep)
Пример #12
0
def admin_users(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    admins = User.objects.filter(type=2)
    rep_admins = []
    for admin in admins:
        item = {
            "id": admin.id,
            "nickname": admin.nickname,
            "username": admin.username,
            "add_time": admin.add_time,
            "status": admin.status
        }
        rep_admins.append(item)
    rep = {"list": rep_admins}
    return ops_render(request, "account/index.html", rep)
Пример #13
0
def resetPwd():
    if request.method == "GET":
        return ops_render("user/reset_pwd.html", {'current': 'reset-pwd'})

    resp = {'code': 200, 'msg': '操作成功~', 'data': {}}
    req = request.values

    old_password = req['old_password'] if 'old_password' in req else ''
    new_password = req['new_password'] if 'new_password' in req else ''

    if old_password is None or len(old_password) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的原密码~~"
        return jsonify(resp)

    if new_password is None or len(new_password) < 6:
        resp['code'] = -1
        resp['msg'] = "请输入符合规范的新密码~~"
        return jsonify(resp)

    if old_password == new_password:
        resp['code'] = -1
        resp['msg'] = "请重新输入一个吧,新密码和原密码不能相同哦~~"
        return jsonify(resp)

    user_info = g.current_user

    if user_info.uid == 1:
        resp['code'] = -1
        resp['msg'] = "该用户是演示账号,不准修改密码和登录用户名~~"
        return jsonify(resp)

    user_info.login_pwd = UserService.genePwd(new_password,
                                              user_info.login_salt)

    db.session.add(user_info)
    db.session.commit()

    response = make_response(json.dumps(resp))
    response.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' %
                        (UserService.geneAuthCode(user_info), user_info.uid),
                        60 * 60 * 24 * 120)  # 保存120天
    return response
Пример #14
0
def admin_info(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    rep = {}
    id = request.GET.get("id", "")
    info = {'type': -1}
    if id:
        user = User.objects.filter(id=id).first()
        if user:
            info["nickname"] = user.nickname
            info["mobile"] = user.mobile
            info['email'] = user.email
            info['login_name'] = user.username
            info['id'] = user.id
            info['type'] = user.type
    else:
        pass
    rep["info"] = info
    return ops_render(request, "account/info.html", rep)
Пример #15
0
def major_class(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    rep = {}
    my_list = []

    major_class_array = MajorClass.objects.all()
    for class_item in major_class_array:
        item = {
            "id": class_item.id,
            "name": class_item.name,
            "status_desc": "正常" if class_item.status == 1 else "删除",
            "weight": class_item.weight,
            "status": class_item.status,
        }
        my_list.append(item)
    rep["list"] = my_list
    rep["current"] = "class"
    rep["status_mapping"] = ["正常", "删除"]
    rep["search_con"] = {"status": "正常"}

    return ops_render(request, "major/major_class.html", rep)
Пример #16
0
def major_class_set(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    if request.method == "POST":
        response = {'code': 200, 'msg': "添加分类成功~", "data": {}}
        request_json = request.POST
        name = request_json.get("name", "")
        weight = request_json.get("weight", 1)
        id = request_json.get("id")
        if id:
            majors = MajorClass.objects.filter(id=id)
            if majors:
                major = majors[0]
                major.name = name
                major.weight = weight
                major.save()
            return JsonResponse(response)
        save_dice = {"name": name, "weight": weight}
        MajorClass.objects.create(**save_dice)

        return JsonResponse(response)

    rep = {}
    id = request.GET.get("id")

    info = {}
    major_class_array = MajorClass.objects.filter(id=id)
    if major_class_array:
        major = major_class_array[0]
        name = major.name
        weight = major.weight
        info["name"] = name
        info["weight"] = weight
        info["id"] = major.id
    rep["info"] = info

    return ops_render(request, "major/major_class_set.html", rep)
Пример #17
0
def error_404(e):
    return ops_render("error/error.html", {'status': 404, 'msg': '很抱歉,您访问的页面不存在!'})
Пример #18
0
def index():
    return ops_render("index/index.html")
Пример #19
0
def index():
    resp_data = {}
    info = Monitor.query.all()
    resp_data['info'] = info
    return ops_render('mon/index.html', resp_data)
Пример #20
0
def index():
    resp_data = {}
    sw_info = Sw.query.all()
    resp_data['info'] = sw_info
    return ops_render('switch/index.html', resp_data)
Пример #21
0
def set():
    default_pwd = "******"
    if request.method == 'GET':
        resp_date = {}
        req = request.values
        info = None
        swid = int(req.get('id', 0))
        if swid:
            info = Sw.query.filter_by(id=swid).first()
        resp_date['info'] = info
        return ops_render('switch/set.html', resp_date)

    resp = {'code': 200, 'msg': '设置成功', 'data': {}}
    req = request.values
    id = req['id'] if 'id' in req or 'id' == None else 0
    swip = req['ipaddr'] if 'ipaddr' in req else ''
    login_name = req['login_name'] if 'login_name' in req else ''
    login_pwd = req['login_pwd'] if 'login_pwd' in req else ''
    iscore = req['iscore'] if 'iscore' in req else 0
    note = req['note'] if 'note' in req else ''

    if swip is None:
        resp['code'] = -1
        resp['msg'] = '交换机输入错误'
        return jsonify(resp)
    if login_name is None or len(login_name) < 1:
        resp['code'] = -1
        resp['msg'] = '交换机登陆名输入错误'
        return jsonify(resp)
    if login_pwd is None or len(login_pwd) < 2:
        resp['code'] = -1
        resp['msg'] = '交换机登陆密码输入格式错误'
        return jsonify(resp)
    if id != '':
        sw_info = Sw.query.filter_by(id=id).first()
        if sw_info:
            model_sw = sw_info
        else:
            model_sw = Sw()
        model_sw.iscore = iscore
        model_sw.user = login_name
        model_sw.note = note
        model_sw.create_time = getCurrentDate()
        if login_pwd != default_pwd:
            model_sw.passwd = login_pwd
        db.session.add(model_sw)
        db.session.commit()
        return jsonify(resp)

    for item in json.loads(swip):
        has_in = Sw.query.filter_by(ipaddr=item).first()
        if has_in:
            resp['code'] = -1
            resp['msg'] = '交换机%s已存在,请更改' % item
            return jsonify(resp)
        # db.session.execute(
        #     Sw.__table__.insert(),
        #     [{'Passwd': login_pwd, 'User': login_name, 'Ipaddr': item, 'iscore': iscore,
        #       'create_time': getCurrentDate()}]
        # )
        info = Sw()
        info.iscore = iscore
        info.user = login_name
        info.note = note
        info.passwd = login_pwd
        info.create_time = getCurrentDate()
        info.ipaddr = item
        db.session.add(info)
        db.session.commit()
    return jsonify(resp)
Пример #22
0
def user(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    args = request.GET
    # 分类 过滤
    c = int(args.get("c", -1))
    # first major 过滤
    f = int(args.get("f", -1))
    # second major 过滤
    s = int(args.get("s", -1))
    # 排序 1 = 分数倒叙 2 = 分数顺序 3 = 创建时间倒叙 4 = 创建时间顺序
    sort = int(args.get("sort", 0))
    rep_admins = []

    admins = User.objects.filter(type=1)

    for admin in admins:
        enroll_name = "没有报名"
        enroll_time = get_date_form_str(detester="1900-1-1", format="%Y-%m-%d")
        enrolls = Enroll.objects.filter(uid=admin)
        second_id = -1
        if len(enrolls) == 1:
            enroll_name = enrolls[0].major.name
            enroll_time = enrolls[0].add_time
            second_id = enrolls[0].major
        marks = Mark.objects.filter(uid=admin)
        mark = 0

        if len(marks) == 1:
            mark = marks[0].sum

        item = {
            "id": admin.id,
            "nickname": admin.nickname,
            "username": admin.username,
            "add_time": admin.add_time,
            "enroll_name": enroll_name,
            "enroll_time": enroll_time,
            "mark": mark,
            "status": admin.status,
            "major_second_id": second_id
        }
        rep_admins.append(item)

    major_class_array = MajorClass.objects.all()

    # 如果c不对-1,说明要通过id去过滤类别
    if int(c) > 0:
        # 第一专业需要过滤
        major_first_array = MajorFirst.objects.filter(major_class_id=c)
    else:
        major_first_array = MajorFirst.objects.all()

    # 如果f不是-1 ,那么也需要过滤第二专业
    if int(f) > 0:
        item_major_first_array = major_first_array.filter(id=f)
    else:
        item_major_first_array = major_first_array

    if sort == 0:
        pass
    elif sort == 1:
        rep_admins = sorted(rep_admins,
                            key=lambda x: x['enroll_time'],
                            reverse=True)
    elif sort == 2:
        rep_admins = sorted(rep_admins,
                            key=lambda x: x['enroll_time'],
                            reverse=False)
    elif sort == 3:
        rep_admins = sorted(rep_admins, key=lambda x: x['mark'], reverse=True)
    elif sort == 4:
        rep_admins = sorted(rep_admins, key=lambda x: x['mark'], reverse=False)

    sorts = [{
        "id": 1,
        "name": "报名时间倒叙"
    }, {
        "id": 2,
        "name": "报名时间顺序"
    }, {
        "id": 3,
        "name": "分数倒序"
    }, {
        "id": 4,
        "name": "分数顺序"
    }]

    ids = list([first_id.id for first_id in item_major_first_array])
    major_second_array = MajorSecond.objects.filter(major_first_id__in=ids)
    new_rep_admins = []
    for item in major_second_array:
        for rep_admins_item in rep_admins:
            if rep_admins_item["enroll_name"] == item.name:
                print("我被添加了")
                new_rep_admins.append(rep_admins_item)
    rep_admins = new_rep_admins
    rep = {
        "list": rep_admins,
        "classs": major_class_array,
        "firsts": major_first_array,
        "seconds": major_second_array,
        "c": c,
        "f": f,
        "s": s,
        "sorts": sorts,
        "sort_status": sort
    }
    return ops_render(request, "user/index.html", rep)
Пример #23
0
def major_second_set(request):
    if request.myself.type == 1:
        return HttpResponse("普通用户不用来管理员界面玩耍~")
    if request.method == "POST":
        response = {'code': 200, 'msg': "添加一级专业成功~", "data": {}}
        request_json = request.POST
        name = request_json.get("name", "")
        weight = request_json.get("weight", 1)
        id = request_json.get("id")
        first_id = request_json.get("first_id")
        declare_start = request_json.get("declare_start")
        declare_end = request_json.get("declare_end")
        review_start = request_json.get("review_start")
        review_end = request_json.get("review_end")

        first = MajorFirst.objects.filter(id=first_id)[0]
        if id:
            seconds = MajorSecond.objects.filter(id=id)
            if seconds:
                second = seconds[0]
                second.name = name
                second.major_first = first
                second.weight = weight
                second.declare_start_time = get_date_form_str(
                    declare_start, "%Y-%m-%d %H:%M")
                second.declare_end_time = get_date_form_str(
                    declare_end, "%Y-%m-%d %H:%M")
                second.review_start_time = get_date_form_str(
                    review_start, "%Y-%m-%d %H:%M")
                second.review_end_time = get_date_form_str(
                    review_end, "%Y-%m-%d %H:%M")
                second.save()
            return JsonResponse(response)
        save_dice = {
            "name":
            name,
            "weight":
            weight,
            "major_first":
            first,
            "declare_start_time":
            get_date_form_str(declare_start, "%Y-%m-%d %H:%M"),
            "declare_end_time":
            get_date_form_str(declare_end, "%Y-%m-%d %H:%M"),
            "review_start_time":
            get_date_form_str(review_start, "%Y-%m-%d %H:%M"),
            "review_end_time":
            get_date_form_str(review_end, "%Y-%m-%d %H:%M"),
        }
        MajorSecond.objects.create(**save_dice)

        return JsonResponse(response)

    rep = {}
    id = request.GET.get("id")

    info = {}
    major_second_array = MajorSecond.objects.filter(id=id)
    if major_second_array:
        second = major_second_array[0]
        name = second.name
        weight = second.weight
        info["name"] = name
        info["weight"] = weight
        info["id"] = second.id
        info['first_id'] = second.major_first.id
        info['class_id'] = second.major_first.major_class.id
        info["declare_start"] = getFormatDate(second.declare_start_time,
                                              "%Y-%m-%d %H:%M")
        info["declare_end"] = getFormatDate(second.declare_end_time,
                                            "%Y-%m-%d %H:%M")
        info["review_start"] = getFormatDate(second.review_start_time,
                                             "%Y-%m-%d %H:%M")
        info["review_end"] = getFormatDate(second.review_end_time,
                                           "%Y-%m-%d %H:%M")
    rep["info"] = info

    major_list = []
    # 查询所有可以使用的分类
    firsts = MajorFirst.objects.filter(status=1)
    for first in firsts:
        id = first.id
        name = first.name
        first_in_major_class = first.major_class
        c_id = first_in_major_class.id
        c_name = first_in_major_class.name
        major_list.append({
            "id": id,
            "name": name,
            "c_id": c_id,
            "c_name": c_name
        })

    rep["major_list"] = major_list
    return ops_render(request, "major/major_second_set.html", rep)
Пример #24
0
def index(request):
    return ops_render(request, "user/login.html")