Esempio n. 1
0
def get_all_file():
    # 1 img ,2 txt,3 audio,4 video
    form = GetGroupFile().validate_for_api()
    folder_id = int(form.folder_id.data)
    isDelete = int(form.isDelete.data)
    current_path = current_app.static_url_path
    site_domain = current_app.config.get('SITE_DOMAIN') \
        if current_app.config.get('SITE_DOMAIN') else 'http://127.0.0.1:2100'
    join_path = site_domain + current_path
    start, count = paginate()
    FileManage = FileMap[form.type.data]
    total = get_total_nums(FileManage, True)
    if (isDelete):
        FileObj = FileManage.query.filter(
            db.and_(FileManage.folder_id == folder_id, FileManage.delete_time
                    != None) if folder_id else FileManage.delete_time != None)
        paths = FileObj.order_by(
            db.desc('create_time')).offset(start).limit(count).all()
        total = get_total_nums(FileManage) - total
    else:
        FileObj = FileManage.query.filter(
            db.and_(FileManage.folder_id == folder_id, FileManage.delete_time
                    == None) if folder_id else FileManage.delete_time == None)
        paths = FileObj.order_by(
            db.desc('create_time')).offset(start).limit(count).all()
    for x in paths:
        x.path = x.path if re.search(r'http', x.path) else join_path + x.path

    total_page = math.ceil(total / count)
    page = get_page_from_query()
    return json_res(count=count,
                    items=paths,
                    page=page,
                    total=total,
                    total_page=total_page)
Esempio n. 2
0
def get_admin_users():
    start, count = paginate()
    group_id = request.args.get('group_id')
    condition = {
        'admin': UserAdmin.COMMON.value,
        'group_id': group_id
    } if group_id else {
        'admin': UserAdmin.COMMON.value
    }

    users = db.session.query(
        manager.user_model,
        manager.group_model.name).filter_by(soft=True, **condition).join(
            manager.group_model, manager.user_model.group_id ==
            manager.group_model.id).offset(start).limit(count).all()

    user_and_group = []
    for user, group_name in users:
        setattr(user, 'group_name', group_name)
        user._fields.append('group_name')
        user.hide('update_time')
        user_and_group.append(user)
        # 有分组的时候就加入分组条件
        # total_nums = get_total_nums(manager.user_model, is_soft=True, admin=UserAdmin.COMMON.value)
    total = get_total_nums(manager.user_model, is_soft=True, **condition)
    total_page = math.ceil(total / count)
    page = get_page_from_query()
    return json_res(count=count,
                    items=user_and_group,
                    page=page,
                    total=total,
                    total_page=total_page)
Esempio n. 3
0
def get_admin_groups():
    start, count = paginate()
    groups = manager.group_model.query.filter().offset(start).limit(
        count).all()
    if groups is None:
        raise NotFound(msg='不存在任何权限组')

    for group in groups:
        auths = db.session.query(manager.auth_model.auth,
                                 manager.auth_model.module).filter_by(
                                     soft=False, group_id=group.id).all()

        auths = [{'auth': auth[0], 'module': auth[1]} for auth in auths]
        res = _split_modules(auths)
        setattr(group, 'auths', res)
        group._fields.append('auths')

    total = get_total_nums(manager.group_model)
    total_page = math.ceil(total / count)
    page = get_page_from_query()

    return json_res(count=count,
                    items=groups,
                    page=page,
                    total=total,
                    total_page=total_page)
Esempio n. 4
0
def get_admin_users():
    start, count = paginate()
    group_id = request.args.get('group_id')
    condition = {
        'admin': UserAdmin.COMMON.value,
        'group_id': group_id
    } if group_id else {
        'admin': UserAdmin.COMMON.value
    }

    users = db.session.query(
        manager.user_model,
        manager.group_model.name).filter_by(soft=True, **condition).join(
            manager.group_model, manager.user_model.group_id ==
            manager.group_model.id).offset(start).limit(count).all()

    user_and_group = []
    for user, group_name in users:
        setattr(user, 'group_name', group_name)
        user._fields.append('group_name')
        user.hide('update_time', 'delete_time')
        user_and_group.append(user)
    # 有分组的时候就加入分组条件
    # total_nums = get_total_nums(manager.user_model, is_soft=True, admin=UserAdmin.COMMON.value)
    total_nums = get_total_nums(manager.user_model, is_soft=True, **condition)
    return jsonify({"collection": user_and_group, 'total_nums': total_nums})
Esempio n. 5
0
def get_admin_groups():
    start, count = paginate()
    groups = manager.group_model.query.filter().offset(start).limit(
        count).all()
    if groups is None:
        raise NotFound(msg='不存在任何权限组')
    for group in groups:
        auths = db.session.query(manager.auth_model.auth, manager.auth_model.module) \
            .filter_by(soft=False, group_id=group.id).all()
        auths = [{'auth': auth[0], 'module': auth[1]} for auth in auths]
        res = _split_modules(auths)
        setattr(group, 'auths', res)
        group._fields.append('auths')
    total_nums = get_total_nums(manager.group_model)
    return jsonify({"collection": groups, 'total_nums': total_nums})