Exemple #1
0
def adminuser_query():
    # 分页信息
    draw = int(request.form['draw'])
    length = int(request.form['length'])
    start = int(request.form['start'])

    # 查询信息
    search = request.form['search[value]']
    if search:
        entity_query = db.session.query(AdminUser).filter_by(username=search)
    else:
        entity_query = db.session.query(AdminUser)

    # 排序信息
    order_colums = request.form['order[0][column]']
    order_colum_flag = 'columns[%s][data]' % order_colums
    order_colum_name = request.form[order_colum_flag]
    if '.' in order_colum_name:
        order_colum_name = order_colum_name.split('.')[0] + '_id'

    order_dir = request.form['order[0][dir]']

    if order_dir == 'desc':
        order_by = getattr(AdminUser, order_colum_name).desc()
    elif order_dir == 'asc':
        order_by = getattr(AdminUser, order_colum_name).asc()

    entity_page = paginate(entity_query.order_by(order_by), start / length + 1, length, False)

    entity_count = db.session.query(AdminUser).count()
    return jsonify(draw=draw,
                   recordsTotal=entity_count,
                   recordsFiltered=entity_page.total,
                   data=[c.serialize_to_admin() for c in entity_page.items])
Exemple #2
0
def query():
    # 分页信息
    draw = int(request.form['draw'])
    length = int(request.form['length'])
    start = int(request.form['start'])

    # 查询信息
    search = request.form['search[value]']
    if search:
        user_query = db.session.query(User).filter_by(email=search)
    else:
        user_query = db.session.query(User)

    # 排序信息
    order_colums = request.form['order[0][column]']
    order_colum_flag = 'columns[%s][data]' % order_colums
    order_colum_name = request.form[order_colum_flag]

    order_dir = request.form['order[0][dir]']

    if order_dir == 'desc':
        order_by = getattr(User, order_colum_name).desc()
    elif order_dir == 'asc':
        order_by = getattr(User, order_colum_name).asc()

    user_page = paginate(user_query.order_by(order_by), start/length + 1, length, False)

    user_count = User.query.count()
    return jsonify(draw=draw,
                   recordsTotal=user_count,
                   recordsFiltered=user_page.total,
                   data=[c.serialize() for c in user_page.items])
Exemple #3
0
def script_show(page=1):
    category_id = request.args.get('category_id')

    category_l = db.session.query(Category).filter_by(user_id=current_user.id). \
        order_by(Category.create_time, Category.name). \
        all()
    if not category_id:
        if category_l and len(category_l) > 0:
            category_id = category_l[0].id
        else:
            category_id = -1
    script_page = paginate(db.session.query(Script).
                           filter_by(user_id=current_user.id, category_id=category_id).
                           order_by(Script.update_time.desc(), Script.create_time.desc()),
                           page, APP_PER_PAGE, False)

    return render_template('cloud/script_list.html',
                           page=script_page,
                           category_l=category_l,
                           current_page=page,
                           current_category=category_id)
Exemple #4
0
def action_query():
    # 分页信息
    draw = int(request.form['draw'])
    length = int(request.form['length'])
    start = int(request.form['start'])

    # 查询信息
    search = request.form['search[value]']
    if search:
        entity_query = db.session.query(ClientRunningSysInfo).\
            outerjoin(User, ClientRunningSysInfo.user_id == User.id).\
            filter(or_(ClientRunningSysInfo.sys_id == search,
                       ClientRunningSysInfo.ip == search,
                       ClientRunningSysInfo.os_name == search,
                       User.email == search))
    else:
        entity_query = db.session.query(ClientRunningSysInfo).\
            outerjoin(User, ClientRunningSysInfo.user_id == User.id)

    # 排序信息
    order_colums = request.form['order[0][column]']
    order_colum_flag = 'columns[%s][data]' % order_colums
    order_colum_name = request.form[order_colum_flag]
    if '.' in order_colum_name:
        order_colum_name = order_colum_name.split('.')[0] + '_id'

    order_dir = request.form['order[0][dir]']

    if order_dir == 'desc':
        order_by = getattr(ClientRunningSysInfo, order_colum_name).desc()
    elif order_dir == 'asc':
        order_by = getattr(ClientRunningSysInfo, order_colum_name).asc()

    entity_page = paginate(entity_query.order_by(order_by), start/length + 1, length, False)

    count = ClientRunningSysInfo.query.count()
    return jsonify(draw=draw,
                   recordsTotal=count,
                   recordsFiltered=entity_page.total,
                   data=[c.serialize_to_admin() for c in entity_page.items])
Exemple #5
0
def query():
    # 分页信息
    draw = int(request.form["draw"])
    length = int(request.form["length"])
    start = int(request.form["start"])

    # 查询信息
    search = request.form["search[value]"]
    if search:
        script_query = db.session.query(Script).join(Script.user).join(Script.category).filter_by(name=search)
    else:
        script_query = db.session.query(Script).join(Script.user).join(Script.category)

    # 排序信息
    order_colums = request.form["order[0][column]"]
    order_colum_flag = "columns[%s][data]" % order_colums
    order_colum_name = request.form[order_colum_flag]
    if "." in order_colum_name:
        order_colum_name = order_colum_name.split(".")[0] + "_id"

    order_dir = request.form["order[0][dir]"]

    if order_dir == "desc":
        order_by = getattr(Script, order_colum_name).desc()
    elif order_dir == "asc":
        order_by = getattr(Script, order_colum_name).asc()

    script_page = paginate(script_query.order_by(order_by), start / length + 1, length, False)

    script_count = db.session.query(Script).count()
    return jsonify(
        draw=draw,
        recordsTotal=script_count,
        recordsFiltered=script_page.total,
        data=[c.serialize_to_admin() for c in script_page.items],
    )