예제 #1
0
파일: projects.py 프로젝트: altai/focus2
def members():
    api = flask.g.api
    if flask.request.args.get("api_marker"):
        perPage = int(flask.request.args["perPage"])
        page = int(flask.request.args["page"])
        query = flask.request.args.get("query")
        data_filter = search.transform_search_query(query, "name:eq")
        projects = flask.request.args["projects"]
        if projects:
            project_by_name = dict(
                (u["name"], u)
                for u in api.projects.list()["projects"])
            project_ids = []
            for u in projects.split(","):
                try:
                    project_ids.append(project_by_name[u]["id"])
                except KeyError:
                    pass
            data_filter["projects:any"] = "|".join(project_ids)
        paginator = pagination.Pagination(
            page,
            api.users.list(
                filter=data_filter, limit=0)["collection"]["size"],
            perPage,
            abort=False)
        data = api.users.list(filter=data_filter,
                              limit=paginator.limit,
                              offset=paginator.offset)["users"]
        # filter my projects
        my_projects = set(
            (p["id"]
             for p in api.projects.list(
                 filter={"my-projects": True})["projects"]))
        for user in data:
            user["projects"] = filter(
                lambda p: p["id"] in my_projects, user["projects"])

        pages = list(paginator.iter_pages())
        current = paginator.page
        return flask.jsonify({
            "data": data,
            "pagination": {
                "pages": pages,
                "current": current,
            },
        })

    return {
        "data": {
            "projects": api.projects.list()["projects"],
        },
    }
예제 #2
0
파일: projects.py 프로젝트: altai/focus2
def fw_rule_sets():
    api = flask.g.api
    if flask.request.args.get("api_marker"):
        perPage = int(flask.request.args["perPage"])
        page = int(flask.request.args["page"])
        query = flask.request.args.get("query")
        data_filter = search.transform_search_query(query, "name:eq")
        projects = flask.request.args["projects"]
        if projects:
            project_by_name = dict((u["name"], u)
                                   for u in api.projects.list()["projects"])
            project_ids = []
            for u in projects.split(","):
                try:
                    project_ids.append(project_by_name[u]["id"])
                except KeyError:
                    pass
            data_filter["project:in"] = "|".join(project_ids)
        paginator = pagination.Pagination(
            page,
            api.fw_rule_sets.list(
                filter=data_filter, limit=0)["collection"]["size"],
            perPage,
            abort=False)
        data = api.fw_rule_sets.list(
            filter=data_filter,
            limit=paginator.limit,
            offset=paginator.offset)["fw-rule-sets"]
        pages = list(paginator.iter_pages())
        current = paginator.page
        return flask.jsonify({
            "data": data,
            "pagination": {
                "pages": pages,
                "current": current,
            },
        })

    return {
        "data": {
            "projects": api.projects.list()["projects"],
        },
    }
예제 #3
0
파일: instances.py 프로젝트: altai/focus2
def index():
    '''Manage'''

    if 'api_marker' in flask.request.args:
        query = flask.request.args.get('query')
        deconstruct = search.transform_search_query(query, 'name:eq')
        r = flask.g.api.instances.list(filter=deconstruct, limit=0)
        perPage = int(flask.request.args['perPage'])
        page = int(flask.request.args['page'])
        try:
            p = pagination.Pagination(page, r['collection']['size'], perPage)
        except werkzeug.exceptions.NotFound:
            data = []
            pages = []
            current = 1
        else:
            r = flask.g.api.instances.list(
                filter=deconstruct, limit=p.limit, offset=p.offset)
            paginator = pagination.Pagination(
                page, r['collection']['size'], perPage)
            data = r['instances']
            pages = list(paginator.iter_pages())
            current = paginator.page
        return flask.jsonify({
                'data': data,
                'pagination': {
                    'pages': pages,
                    'current': current
                    }
                })

    return {
        'predefined_searches': [
            {'title': 'My instances', 'url': flask.request.path + '?my'},
        ] + [
            {'title': x['name'],
             'url': flask.request.path + '?project_id=' + x['id']} for x
            in flask.g.api.projects.list()['projects']
        ],
        'user_searches': flask.session.get('user_searches', []),
    }