Ejemplo n.º 1
0
def login():
    if request.method == "GET":
        return ops_render("member/login.html")
    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:
        return ops_renderErrJSON("请输入正确的登录用户名~~")

    if login_pwd is None or len(login_pwd) < 6:
        return ops_renderErrJSON("请输入正确的登录密码~~")
    user_info = User.query.filter_by(login_name=login_name).first()
    if not user_info:
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -1~~")

    if user_info.login_pwd != UserService.genePwd(login_pwd,
                                                  user_info.login_salt):
        return ops_renderErrJSON("请输入正确的登录用户名和密码 -2 ~~")

    if user_info.status != 1:
        return ops_renderErrJSON("账号被禁用,请联系管理员处理~~")
    # session['uid'] = user_info.id

    response = make_response(ops_renderJSON(msg="登录成功~~"))
    response.set_cookie(
        app.config['AUTH_COOKIE_NAME'],
        "%s#%s" % (UserService.geneAuthCode(user_info), user_info.id),
        60 * 60 * 24 * 120)
    return response
Ejemplo n.º 2
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
    user_info.login_pwd = UserService.genePwd(new_password, user_info.login_salt)

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

    responce = make_response(json.dumps(resp))
    responce.set_cookie(app.config['AUTH_COOKIE_NAME'], '%s#%s' % (UserService.geneAuthCode(user_info), user_info.uid))
    return responce
Ejemplo n.º 3
0
def new_set():
    if request.method == "GET":
        resp = {}
        resp['lib_location'] = app.config['LIB_LOCATION']
        return ops_render("index/new_set.html", resp)

    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    title = req['title'] if 'title' in req else ''
    location = req['location'] if 'location' in req else ''
    content = req['content'] if 'content' in req else ''
    # 参数有效性的再次判断的 之前判断了title字数不能小于2,地点名不能少于5个字和content不能为空,这里就暂时鸡肋地随便判断下
    if title is None or len(title) > 20:
        resp['code'] = -1
        resp['msg'] = "请输入规范的标题名~~"
        return jsonify(resp)

    if location is None or len(location) > 15:
        resp['code'] = -1
        resp['msg'] = "请输入规范的校区图书馆名~~"
        return jsonify(resp)

    bulletin = News()
    bulletin.title = title
    bulletin.content = content
    bulletin.location = location
    bulletin.created_time = getCurrentDate()
    # 数据库提交
    db.session.add(bulletin)
    db.session.commit()

    return jsonify(resp)
Ejemplo n.º 4
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']="loging_name failed"
        return jsonify(resp)

    if login_pwd is None or len(login_pwd)<1:
        resp ['code']=-1
        resp['msg']="login_pwd failed"
        return jsonify(resp)

    user_info = User.query.filter_by(login_name = login_name).first()
    if not user_info:
        resp['code'] = -1
        resp['msg'] = "there is not the person"
        return jsonify(resp)

    if user_info.login_pwd != UserService.UserService.genePwd(login_pwd,user_info.login_salt):
        app.logger.info(UserService.UserService.genePwd(login_pwd,user_info.login_salt))
        resp['code'] = -1
        resp['msg'] = "the pwd is wrong"
        return jsonify(resp)

    response = make_response(json.dumps(resp))
    response.set_cookie(app.config['AUTH_COOKIE_NAME'],
            "%s#%s"%(UserService.UserService.geneAuthCode(user_info),user_info.uid))
    return response
def login():
    if request.method == "GET":
        return ops_render("member/login.html")
    elif request.method == "POST":
        req = request.values
        name = req["name"] if "name" in req else ""
        password = req["password"] if "password" in req else ""

        if name is None or len(name) < 1:
            return ops_renderErrJSON(msg="请输入正确的用户名")
        if password is None or len(password) < 6:
            return ops_renderErrJSON(msg="请输入正确的密码")

        user_info = User.query.filter_by(name=name).first()
        if not user_info:
            return ops_renderErrJSON(msg="请输入正确的登录用户名和密码(user not found)")

        if user_info.password != UserService.gene_pwd(password):
            return ops_renderErrJSON(msg="请输入正确的登录用户名和密码(error password)")

        response = make_response(ops_renderJSON(msg="登录成功~"))
        response.set_cookie(
            app.config["AUTH_COOKIE_NAME"],
            "%s#%s" % (UserService.gene_auth_code(user_info), user_info.id),
            60 * 60 * 24)
        return response
def reg():
    if request.method == "GET":
        return ops_render("member/reg.html")
    elif request.method == "POST":
        req = request.values
        name = req["name"] if "name" in req else ""
        type = req["type"] if "type" in req else ""
        password = req["password"] if "password" in req else ""
        password2 = req["password2"] if "password2" in req else ""

        if name is None or len(name) < 1:
            return ops_renderErrJSON(msg="请输入正确的用户名")
        if type is None or len(type) < 1:
            return ops_renderErrJSON(msg="请选择正确的类型")

        if password is None or len(password) < 6:
            return ops_renderErrJSON(msg="请输入正确的密码")

        if password2 != password2:
            return ops_renderErrJSON(msg="两次密码不一致")

        user_info = User.query.filter_by(name=name).first()
        if user_info:
            return ops_renderErrJSON(msg="用户名已被注册,请更换用户名重新注册")

        model_user = User()
        model_user.name = name
        model_user.type = type
        model_user.password = UserService.gene_pwd(password)
        model_user.regist_time = get_current_time()
        db.session.add(model_user)
        db.session.commit()
        return ops_renderJSON(msg="注册成功~")
def index():
    content = {}
    user = g.current_user
    com_list = []
    if user.type == "经销商":
        com_list = Commodity.query.filter(
            Commodity.status.in_(["出售中", "待发货", "已发货", "运输中", "已入库",
                                  "已分发"])).filter_by(seller=user.id)
    if user.type == "运输商":
        com_list_base = []
        com_list_custom = []
        com_list_base += Commodity.query.filter(Commodity.status.in_(["已发货"]))
        com_list_custom += Commodity.query.filter(
            Commodity.status.in_(["运输中", "已入库"])).filter_by(trans=user.id)
        com_list = com_list_custom + com_list_base
    if user.type == "仓库管理员":
        com_list_base = []
        com_list_custom = []
        com_list_base += Commodity.query.filter(Commodity.status.in_(["运输中"]))
        com_list_custom += Commodity.query.filter(
            Commodity.status.in_(["已入库", "已分发"])).filter_by(warehouse=user.id)
        com_list = com_list_custom + com_list_base
    if user.type == "超市管理员":
        com_list_selling = []
        com_list_buyed = []

        com_list_buyed += Commodity.query.filter(
            Commodity.status.in_(["待发货", "已发货", "运输中", "已入库", "已分发",
                                  "已销售"])).filter_by(buyer=user.id)
        com_list_selling += Commodity.query.filter(
            Commodity.status.in_(["出售中"]))
        com_list = com_list_buyed + com_list_selling
    content["com_list"] = com_list
    return ops_render("index.html", content)
Ejemplo n.º 8
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

    app.logger.info(user_info)

    db.session.add(user_info)
    db.session.commit()
    return jsonify(resp)
Ejemplo n.º 9
0
def index():
    req = request.values
    req = request.values
    order_by_f = str(req['order']) if ("order" in req and req['order']) else "lastest"
    query = Movie.query
    page = 1
    if 'p' in req and req['p']:
        page = int(req['p'])

    page_params = {
        'total_count': query.count(),
        "page_size": 30,
        'page': page,
        'url': "/?"
    }
    pages = iPagenation(page_params)
    offset = (page - 1) * page_params['page_size']
    limit = page * page_params['page_size']

    if order_by_f == "hot":
        query = query.order_by(Movie.view_counter.desc(), Movie.id.desc())
    else:
        query = query.order_by(Movie.pub_date.desc(), Movie.id.desc())

    list_movie = query[offset:limit]

    return ops_render("index.html", {"data": list_movie, "pages": pages})
Ejemplo n.º 10
0
def index():
    resp_data = {}
    query = Contribution.query
    query.count()  # 这个就是取得总的页数
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1

    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

    if 'status' in req and int(req['status']) > -1:  # 顺序为1,倒序为2
        if int(req['status']) == 1:
            list = query.order_by(Contribution.created_time.asc()).all()[offset:limit]
        else:
            list = query.order_by(Contribution.created_time.desc()).all()[offset:limit]
    else:
        list = query.order_by(Contribution.id.asc()).all()[offset:limit]

    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['search_con'] = req
    resp_data['order'] = app.config['ORDER']
    resp_data['current'] = 'index'

    return ops_render("feedback/index.html",resp_data)
Ejemplo n.º 11
0
def info():
    resp_data = {}
    req = request.args
    id = int(req.get("id", 0))
    reback_url = UrlManager.buildUrl("/books_lib/index")

    if id < 1:
        return redirect(reback_url)

    book_info = Books.query.filter_by(id=id).first()
    if not book_info:
        return redirect(reback_url)

    # 转换book_type
    books_type = app.config['BOOK_TYPES']
    type_int = book_info.book_type
    type = str(type_int)
    type_str = books_type[type]
    book_info.book_type = type_str

    resp_data['book_info'] = book_info
    # resp_data['news_info'] = news_info


    return ops_render("books_lib/info.html",resp_data)
Ejemplo n.º 12
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']="nickname failed"
        return jsonify(resp)

    if email is None or len(email)<1:
        resp ['code']=-1
        resp['msg']="email failed"
        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)
Ejemplo n.º 13
0
def index():

    resp_data = {}
    req = request.values

    page = int(req['p']) if ('p' in req and req['p']) else 1

    if "mix_kw" in req:
        rule = or_(User.nickname.ilike("%{0}%".format(req['mix_kw'])),
                   User.mobile.ilike("%{0}%".format(req['mix_kw'])))
        User.query = User.query.filter(rule)

    if "status" in req and int(req['status']) > -1:
        User.query = User.query.filter(User.status == int(req['status']))

    page_params = {
        'total': User.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

    #[offset:limit]切片操作,取从offset到limit的数据。
    list = User.query.order_by(User.uid.desc()).all()[offset:limit]
    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['search_con'] = req
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']
    for tmp in resp_data['status_mapping']:
        app.logger.info(tmp)
    return ops_render("account/index.html", resp_data)
Ejemplo n.º 14
0
def resetPwd():
    if request.method == "GET":
        return ops_render("user/reset_pwd.html",{'current':'reset-pwd'})
    app.logger.info("lalalallaalallalall")
    resp = {'code': 200, 'msg': '编辑成功', 'data': {}}
    req = request.values
    new_password = req['new_password'] if 'new_password' in req else ''
    old_password = req['old_password'] if 'old_password' in req else ''

    if new_password is None or len(new_password) < 6:
        resp['code'] = -1
        resp['msg'] = "new_password failed"
        return jsonify(resp)

    if old_password is None or len(old_password) < 6:
        resp['code'] = -1
        resp['msg'] = "old_password failed"
        return jsonify(resp)

    if old_password == new_password:
        resp['code'] = -1
        resp['msg'] = "new password should not equals old password"
        return jsonify(resp)

    user_info = g.current_user
    user_info.login_pwd = UserService.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("mooc_food",
                        "%s#%s" % (UserService.UserService.geneAuthCode(user_info), user_info.uid))
    return response
def info():
    response = send_message("need_chain", "")
    data_dict = json.loads(response)
    req = request.values
    com_id = req["comid"] if "comid" in req else ""
    current_com = ComService.find_com_by_id(com_id)
    ops_list = []
    content = {"ops_list": [], "current_com": current_com}
    chain_data = data_dict["msg"] if "msg" in data_dict else None

    if chain_data:
        chain_list = chain_data["chain"] if "chain" in chain_data else []
        for block in chain_list:
            if not block["index"] == 1:
                content_list = block["content"]
                for ops in content_list:
                    if int(ops["commodity"]) == int(com_id):
                        ops_list.append(ops)

    for ops in ops_list:
        user = User.query.filter_by(id=ops["operator"]).first()
        data = {
            "operator": user.name,
            "option": ops["option"],
            "time": ops["time"]
        }
        content["ops_list"].append(data)

    return ops_render("/blockchain/info.html", content)
Ejemplo n.º 16
0
def index():

    resp_data = {}
    query = News.query
    query.count()  #这个就是取得总的页数
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1

    if 'mix_kw' in req:
        rule = or_(News.title.ilike("%{0}%".format(req['mix_kw'])),
                   News.id.ilike("%{0}%".format(req['mix_kw'])))
        query = query.filter(rule)

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(News.status == int(req['status']))

    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(News.id.asc()).all()[offset:limit]

    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['current'] = 'bulletin'
    resp_data['search_con'] = req
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']
    return ops_render("index/index.html", resp_data)
Ejemplo n.º 17
0
def index():
    student_data = {}
    # query = db.session.query(Student)
    # query.count()
    # list = query.filter_by(Student.status).all()
    list = Student.query.filter(Student.no).all()
    student_data['list']=list
    return ops_render( "member/index.html",student_data)
Ejemplo n.º 18
0
def set():
    default_pwd = "******"
    if request.method == "GET":
        resp_data = {}
        req = request.args
        uid = int(req.get("id", 0))
        info = None
        if uid:
            info = User.query.filter_by(uid=uid).first()
        resp_data['info'] = info
        return ops_render("account/set.html", resp_data)
    resp = {'code': 200, 'msg': '编辑成功', 'data': {}}
    req = request.values
    nickname = req['nickname'] if 'nickname' in req else ''
    email = req['email'] if 'email' in req else ''
    mobile = req['mobile'] if 'mobile' 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 ''
    id = req['id'] if 'id' in req else '0'

    if nickname is None or len(nickname) < 1:
        resp['code'] = -1
        resp['msg'] = "nickname failed"
        return jsonify(resp)

    if email is None or len(email) < 1:
        resp['code'] = -1
        resp['msg'] = "email failed"
        return jsonify(resp)

    has_in = User.query.filter(User.login_name == login_name,
                               User.uid != id).first()
    if has_in:
        resp['code'] = -1
        resp['msg'] = "email failed"
        return jsonify(resp)

    user_info = User.query.filter(User.uid == id).first()
    if user_info:
        model_user = user_info
    else:
        model_user = User()
        model_user.updated_time = getCurrentDate()
        model_user.created_time = getCurrentDate()

    if login_pwd != default_pwd:
        model_user.login_salt = UserService.genSalt()
        model_user.login_pwd = UserService.genePwd(login_pwd,
                                                   model_user.login_salt)

    model_user.nickname = nickname
    model_user.email = email
    model_user.mobile = mobile
    model_user.login_name = login_name

    db.session.add(model_user)
    db.session.commit()
    return jsonify(resp)
Ejemplo n.º 19
0
def list():
    resp_data = {}
    query = Books.query
    query.count()  # 这个就是取得总的页数
    req = request.values
    lib_location=app.config['LIB_LOCATION']
    page = int(req['p']) if ('p' in req and req['p']) else 1

    #将字符类型的book_type转换为int类型


    if 'mix_kw' in req:
        rule = or_(Books.title.ilike("%{0}%".format(req['mix_kw'])),
                   Books.author.ilike("%{0}%".format(req['mix_kw'])))
        query = query.filter(rule)

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(Books.status == int(req['status']))

    if 'cat' in req and int(req['cat']) > -1:
        query = query.filter(Books.book_type == int(req['cat']))

    if 'location' in req and int(req['location']) > -1:
        query = query.filter(Books.location==lib_location[req['location']])

    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(Books.id.asc()).all()[offset:limit]

    #将int类型book_type转换为str类型
    books_type = app.config['BOOK_TYPES']
    for item in list:
        type_int=item.book_type
        type=str(type_int)
        type_str=books_type[type]
        item.book_type=type_str

    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['search_con'] = req
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']
    resp_data['book_types'] = app.config['BOOK_TYPES']
    resp_data['lib_location'] = app.config['LIB_LOCATION']


    #return ops_render("books_lib/index.html",{"current":"Academic_communication"})
    return ops_render("books_lib/index.html",resp_data)
Ejemplo n.º 20
0
def new_speech():
    if request.method == "GET":
        return ops_render("dong_tai/new_speech.html")
    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    title = req['title'] if 'title' in req else ''
    address = req['address'] if 'address' in req else ''
    teacher = req['teacher'] if 'teacher' in req else ''
    email = req['email'] if 'email' in req else ''
    teacher_intro = req['teacher_intro'] if 'teacher_intro' in req else ''
    speech_intro = req['speech_intro'] if 'speech_intro' in req else ''
    app.logger.info(req['time'])
    app.logger.info(getCurrentDate())
    time = req['time'] if 'time' in req else getCurrentDate()
    app.logger.info(time)

    # 注意:
    # input datetime-local控件获取的日期格式是****-**-**T**:**:**,中间有个很奇怪的T,下面的这个函数已经的证明可以将其赋给数据库
    #这里和上一个函数原理不同
    def deleteT(time):
        time1 = time[:4]
        time2 = time[5:7]
        time3 = time[8:10]
        time4 = time[11:13]
        time5 = time[14:]
        time = time1 + time2 + time3 + time4 + time5 + '00'
        time = int(time)
        return time

    time = deleteT(time)
    app.logger.info(time)
    #假吧意思判断两个
    if title is None or len(title) > 20:
        resp['code'] = -1
        resp['msg'] = "请输入规范的标题名~~"
        return jsonify(resp)

    if address is None or len(address) > 15:
        resp['code'] = -1
        resp['msg'] = "请输入规范的讲座地址~~"
        return jsonify(resp)

    speech = Speeches()
    speech.title = title
    speech.address = address
    speech.teacher = teacher
    speech.teacher_conn = email
    speech.speech_time = time
    speech.teacher_intro = teacher_intro
    speech.speech_intro = speech_intro

    # 数据库提交
    db.session.add(speech)
    db.session.commit()

    return jsonify(resp)
Ejemplo n.º 21
0
def new_set():
    if request.method == "GET":
        resp_data = {}
        req = request.args
        id = int( req.get('id',0) )
        info = Books.query.filter_by( id = id ).first()
        if info and info.status != 1:
            return redirect( UrlManager.buildUrl("/books_lib/index") )
        resp_data['info'] = info
        resp_data['lib_location'] = app.config['LIB_LOCATION']
        resp_data['book_types'] = app.config['BOOK_TYPES']
        return ops_render("books_lib/new_set.html", resp_data)

    resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
    req = request.values
    id = int(req['id']) if 'id' in req and req['id'] else 0
    cat_id = int(req['cat_id']) if 'cat_id' in req and req['cat_id'] else 0
    title = req['title'] if 'title' in req else ''
    author = req['author'] if 'author' in req else ''
    press = req['press'] if 'press' in req else ''
    intro = req['intro'] if 'intro' in req else ''
    location = req['location'] if 'location' in req else ''
    amount = int(req['amount']) if 'amount' in req and req['amount'] else 0
    image = req['image'] if 'image' in req else ''

    if image is None or len(image) < 3:
        resp['code'] = -1
        resp['msg'] = "请上传封面图~~"
        return jsonify(resp)

    book_info = Books.query.filter_by(id=id).first()
    if book_info:
        model_info = book_info
        model_info.current_amount = amount  # 现在的数量,只有修改已有书籍的时候的才能修改
    else: #这里铁定的是第一次上新才能修改
        model_info = Books()
        model_info.status = 1
        model_info.current_amount = amount  #第一次上新在馆数量和上新数量是一样的
        model_info.update_amount = amount   #上新数量,只能 第一次 上新书才能更改,不允许出错,因为涉及到新书推荐的地方
        model_info.update_time = getCurrentDate()  #上新时间,只能第一次上新才能更改

    # 这6个均可修改的原因是有可能第一次上新的时候输错了书籍信息

    model_info.book_type = cat_id
    model_info.title = title
    model_info.author = author
    model_info.image = image
    model_info.press = press
    model_info.intro = intro
    model_info.location = location

    db.session.add(model_info)
    db.session.commit()

    return jsonify(resp)
Ejemplo n.º 22
0
def info():
    resp_data = {}
    req = request.args
    uid = int(req.get('id', 0))
    if uid < 1:
        return redirect(UrlManager.buildUrl("/account/index"))
    info = User.query.filter_by(uid=uid).first()
    if not info:
        return redirect(UrlManager.buildUrl("/account/index"))

    resp_data['info'] = info
    return ops_render("account/info.html", resp_data)
Ejemplo n.º 23
0
def info():
    resp_data = {}
    req = request.args
    id = int(req.get("id", 0))
    reback_url = UrlManager.buildUrl("/member/index")

    if id < 1:
        return redirect(reback_url)

    lending_info = Lending.query.filter_by(id=id).first()
    if not lending_info:
        return redirect(reback_url)

    resp_data['lending_info'] = lending_info

    return ops_render("member/info.html", resp_data)
Ejemplo n.º 24
0
def index():
    if request.method == 'GET':
        resp_data = {}
        query = Lending.query
        lending_info = query.all()

        #app.logger.info(lending_info[0].title)
        #这段需要优化
        books_info = Books.query.all()
        for item in lending_info:
            for book in books_info:
                if item.title == book.title:
                    item.book_type = book.book_type
        #app.logger.info(lending_info[0].book_type)

        resp_data['current'] = 'index'
        return ops_render("stat/index.html", resp_data)
Ejemplo n.º 25
0
def info():
    if request.method=='GET':
        resp_data = {}
        req = request.args
        id = int(req.get("id", 0))
        reback_url = UrlManager.buildUrl("/feedback/feedback")

        if id < 1:
            return redirect(reback_url)

        feed_info = Feedback.query.filter_by(id=id).first()
        if not feed_info:
            return redirect(reback_url)

        resp_data['feed_info'] = feed_info
        # resp_data['news_info'] = news_info
        return ops_render("feedback/feed_info.html",resp_data)

    resp = {'code': 200, 'msg': '操作成功~~', 'data': {}}
    req = request.values
    id = int(req['id']) if 'id' in req and req['id'] else 0
    feedback_lib = req['feedback'] if 'feedback' in req else ''

    app.logger.info(feedback_lib)

    if id ==0:
        resp['code'] = -1
        resp['msg'] = "数据的id获取失败~~"
        return jsonify(resp)

    if feedback_lib is None or len(feedback_lib) < 2:
        resp['code'] = -1
        resp['msg'] = "请填写规范的回复~~"
        return jsonify(resp)

    model_info = Feedback.query.filter_by(id=id).first()


    model_info.feedback_lib = feedback_lib


    db.session.add(model_info)
    db.session.commit()

    return jsonify(resp)
Ejemplo n.º 26
0
def login():
    if request.method == "GET":
        resp_data = {}
        config = app.config['APP_MAKER']
        resp_data['config'] = config
        return ops_render("user/login.html", resp_data)

    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 ''

    #测试是否获得输入值,如果有没输入的就直接返回错误
    #return "%s-%s" %(login_name,login_pwd)测试成功
    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)
    #确认密码对的上账户
    #这里是将数据库中的密码(这个密码就是经过MD5与秘钥进行加密过的,不可逆加密) 与 输入的密码通过数据库中的秘钥进行加密得出的密码 进行比对
    #由于数据库中的密码并没有进行加密操作,所以这里的比对先直接进行明文比对
    #if user_info.login_pwd != UserService.genePwd(login_pwd,user_info.login_salt):
    if user_info.login_pwd != login_pwd:
        resp['code'] = -1
        resp['msg'] = "请输入正确的登录用户名和密码-2 "
        return jsonify(resp)

    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
Ejemplo n.º 27
0
def check_speeches():

    resp_data = {}
    query = Speeches.query
    query.count()  #这个就是取得总的页数
    req = request.values
    page = int(req['p']) if ('p' in req and req['p']) else 1

    if 'mix_kw' in req:
        rule = or_(Speeches.title.ilike("%{0}%".format(req['mix_kw'])),
                   Speeches.id.ilike("%{0}%".format(req['mix_kw'])))
        query = query.filter(rule)

    if 'status' in req and int(req['status']) > -1:
        query = query.filter(Speeches.status == int(req['status']))

    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(Speeches.id.asc()).all()[offset:limit]

    #这里是想解决展示的编号问题,先放这里算了
    i = 0
    li = []
    while i < len(list):
        li.append(i)
        i = i + 1

    resp_data['list'] = list
    resp_data['pages'] = pages
    resp_data['sort'] = li
    resp_data['current'] = 'speeches_management'
    resp_data['search_con'] = req
    resp_data['status_mapping'] = app.config['STATUS_MAPPING']

    return ops_render("dong_tai/speeches.html", resp_data)
Ejemplo n.º 28
0
def lost_info():
    resp_data = {}
    req = request.args
    id = int(req.get("id", 0))
    reback_url = UrlManager.buildUrl("/lost")

    if id < 1:
        return redirect(reback_url)

    info = Lost.query.filter_by(id=id).first()
    if not info:
        return redirect(reback_url)

# news_info = News.query.filter(News.id == id).order_by(News.id.asc()).all()

    resp_data['info'] = info
    #resp_data['news_info'] = news_info

    return ops_render("index/lost_info.html", resp_data)
Ejemplo n.º 29
0
def index():
    data = {
        "count":0,
        "in":0,
        "out":0
    }
    sum_in = 0
    sum_out = 0
    list = Student.query.order_by(Student.no).all()
    if list:
        data["count"]=len(list)
        for item in list:
            if item.status == 0:
                sum_out += 1
            elif item.status == 1:
                sum_in += 1
        data['in'] = sum_in
        data['out'] = sum_out
    return ops_render("index/index.html",data)
Ejemplo n.º 30
0
def set():
    if request.method == "GET":
        resp_data = {}
        req = request.args
        id = req['id'] if 'id' in req else ''
        reback_url = UrlManager.buildUrl("/")
        info = News.query.filter_by(id=id).first()
        if not info:
            return redirect(reback_url)

        # news_info = News.query.filter(News.id == id).order_by(News.id.asc()).all()

        resp_data['info'] = info
        resp_data['lib_location'] = app.config['LIB_LOCATION']
        return ops_render("index/set.html", resp_data)

    resp = {'code': 200, 'msg': '操作成功', 'data': {}}
    req = request.values
    id = int(req['id']) if 'id' in req else 0
    title = req['title'] if 'title' in req else ''
    location = req['location'] if 'location' in req else ''
    content = req['content'] if 'content' in req else ''
    # 参数有效性的再次判断的 之前判断了title字数不能小于2,地点名不能少于5个字和content不能为空,这里就暂时鸡肋地随便判断下
    if title is None or len(title) > 20:
        resp['code'] = -1
        resp['msg'] = "请输入规范的标题名~~"
        return jsonify(resp)

    if location is None or len(location) > 15:
        resp['code'] = -1
        resp['msg'] = "请输入规范的校区图书馆名~~"
        return jsonify(resp)

    bulletin_info = News.query.filter_by(id=id).first()
    bulletin_info.title = title
    bulletin_info.content = content
    bulletin_info.location = location
    bulletin_info.created_time = getCurrentDate()
    # 数据库提交
    db.session.add(bulletin_info)
    db.session.commit()

    return jsonify(resp)