示例#1
0
def keep_fetching_texture_libraries(proj_filter):

    groups = g.current_user['groups']
    user_id = g.current_user['user_id']

    page = 1
    max_page = float('inf')

    while page <= max_page:
        request.args.setlist(eve_config.QUERY_PAGE, [page])

        result, _, _, status, _ = get(
            'projects',
            {'$or': [
                {'user': user_id},
                {'permissions.groups.group': {'$in': groups}},
                {'permissions.world': 'GET'}
            ]})

        if status != 200:
            log.warning('Error fetching texture libraries: %s', result)
            raise InternalServerError('Error fetching texture libraries')

        for proj in result['_items']:
            if proj_filter(proj):
                yield proj

        # Compute the last page number we should query.
        meta = result['_meta']
        max_page = meta['total'] // meta['max_results']
        if meta['total'] % meta['max_results'] > 0:
            max_page += 1

        page += 1
示例#2
0
def get_company_name_employees(company_name):
    db = app.data.driver.db
    company = db['companies'].find_one({"company": company_name})
    if db['companies'].count_documents({"company": company_name}) > 0:
        response = get('get_employees', {'company_id': int(company['index'])})
        return send_response('get_employees', response)
    return abort(404)
示例#3
0
 def eve_get(*args, **kwargs):
     res = get(*args, **kwargs)
     data = res[0].get('data')
     next_page = query_dict(res[0], '_links.next')
     # depaginate recursively
     if next_page:
         match = re.match('\w+\?page=(\d+)', next_page.get('href'))
         previous_args = request.args
         # inject page number in the args of the request to allow eve to pick it up
         request.args = ImmutableMultiDict({'page': int(match.group(1))})
         data.extend(AutomaticReviewer.eve_get(*args, **kwargs))
         # restore the args that was there previously
         request.args = previous_args
     return data
示例#4
0
def keep_fetching_texture_libraries(proj_filter):

    groups = g.current_user['groups']
    user_id = g.current_user['user_id']

    page = 1
    max_page = float('inf')

    while page <= max_page:
        request.args.setlist(eve_config.QUERY_PAGE, [page])

        result, _, _, status, _ = get(
            'projects', {
                '$or': [{
                    'user': user_id
                }, {
                    'permissions.groups.group': {
                        '$in': groups
                    }
                }, {
                    'permissions.world': 'GET'
                }]
            })

        if status != 200:
            log.warning('Error fetching texture libraries: %s', result)
            raise InternalServerError('Error fetching texture libraries')

        for proj in result['_items']:
            if proj_filter(proj):
                yield proj

        # Compute the last page number we should query.
        meta = result['_meta']
        max_page = meta['total'] // meta['max_results']
        if meta['total'] % meta['max_results'] > 0:
            max_page += 1

        page += 1
示例#5
0
def home_project():
    """Fetches the home project, creating it if necessary.

    Eve projections are supported, but at least the following fields must be present:
        'permissions', 'category', 'user'
    """
    from pillar.auth import current_user

    user_id = current_user.user_id
    roles = current_user.roles

    log.debug('Possibly creating home project for user %s with roles %s',
              user_id, roles)
    if HOME_PROJECT_USERS and not HOME_PROJECT_USERS.intersection(roles):
        log.debug('User %s is not a subscriber, not creating home project.',
                  user_id)
        return 'No home project', 404

    # Create the home project before we do the Eve query. This costs an extra round-trip
    # to the database, but makes it easier to do projections correctly.
    if not has_home_project(user_id):
        write_access = write_access_with_roles(roles)
        create_home_project(user_id, write_access)

    resp, _, _, status, _ = get('projects', category='home', user=user_id)
    if status != 200:
        return utils.jsonify(resp), status

    if resp['_items']:
        project = resp['_items'][0]
    else:
        log.warning(
            'Home project for user %s not found, while we just created it! Could be '
            'due to projections and other arguments on the query string: %s',
            user_id, request.query_string)
        return 'No home project', 404

    return utils.jsonify(project), status
示例#6
0
def get_favourite_food(person):
    response = get('favourite_food', {'index': person})
    return send_response('favourite_food', response)
示例#7
0
def get_common_friends(person_one, person_two):
    response = get('friends', {'index': {'$in': [person_one, person_two]}})
    if response[-1][0][-1] != 2:
        return abort(404)
    return send_response('friends', response)
示例#8
0
def my_info():
    eve_resp, _, _, status, _ = get('users',
                                    {'_id': g.current_user['user_id']})
    resp = jsonify(eve_resp['_items'][0], status=status)
    return resp
示例#9
0
def my_info():
    eve_resp, _, _, status, _ = get('users', {'_id': current_user.user_id})
    resp = utils.jsonify(eve_resp['_items'][0], status=status)
    return resp
示例#10
0
文件: users.py 项目: JT-a/pillar
def my_info():
    eve_resp, _, _, status, _ = get('users', {'_id': g.current_user['user_id']})
    resp = jsonify(eve_resp['_items'][0], status=status)
    return resp