From f899f6d1ab653ed7f1ad0e6e065fd1eed2b34bf5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sybren=20A=2E=20St=C3=BCvel?= Date: Fri, 15 Jul 2016 16:56:39 +0200 Subject: [PATCH] Started pagination support, but it isn't used yet. --- blender_cloud/pillar.py | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/blender_cloud/pillar.py b/blender_cloud/pillar.py index ba2aa71..ef69d6d 100644 --- a/blender_cloud/pillar.py +++ b/blender_cloud/pillar.py @@ -260,7 +260,7 @@ async def get_project_uuid(project_url: str) -> str: async def get_nodes(project_uuid: str = None, parent_node_uuid: str = None, - node_type=None) -> list: + node_type=None, max_results=None) -> list: """Gets nodes for either a project or given a parent node. @param project_uuid: the UUID of the project, or None if only querying by parent_node_uuid. @@ -290,23 +290,34 @@ async def get_nodes(project_uuid: str = None, parent_node_uuid: str = None, else: where['node_type'] = {'$in': node_type} - children = await pillar_call(pillarsdk.Node.all, { - 'projection': {'name': 1, 'parent': 1, 'node_type': 1, - 'properties.order': 1, 'properties.status': 1, - 'properties.files': 1, - 'properties.content_type': 1, 'picture': 1}, - 'where': where, - 'embed': ['parent']}) + params = {'projection': {'name': 1, 'parent': 1, 'node_type': 1, 'properties.order': 1, + 'properties.status': 1, 'properties.files': 1, + 'properties.content_type': 1, 'picture': 1}, + 'where': where, + 'embed': ['parent']} + + # Pagination + if max_results: + params['max_results'] = int(max_results) + + children = await pillar_call(pillarsdk.Node.all, params) return children['_items'] -async def get_texture_projects() -> list: +async def get_texture_projects(max_results=None) -> list: """Returns project dicts that contain textures.""" + params = {} + + # Pagination + if max_results: + params['max_results'] = int(max_results) + try: children = await pillar_call(pillarsdk.Project.all_from_endpoint, - '/bcloud/texture-libraries') + '/bcloud/texture-libraries', + params=params) except pillarsdk.ResourceNotFound as ex: log.warning('Unable to find texture projects: %s', ex) raise PillarError('Unable to find texture projects: %s' % ex)