当前位置: 首页>>代码示例>>Python>>正文


Python common.get_pagination_params函数代码示例

本文整理汇总了Python中nova.api.openstack.common.get_pagination_params函数的典型用法代码示例。如果您正苦于以下问题:Python get_pagination_params函数的具体用法?Python get_pagination_params怎么用?Python get_pagination_params使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_pagination_params函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: fake_get_limit_and_marker

def fake_get_limit_and_marker(request, max_limit=1):
    params = common.get_pagination_params(request)
    limit = params.get('limit', max_limit)
    limit = min(max_limit, limit)
    marker = params.get('marker')

    return limit, marker
开发者ID:375670450,项目名称:nova,代码行数:7,代码来源:test_flavors.py

示例2: limited_by_marker

    def limited_by_marker(self, items, request,
                          max_limit=CONF.osapi_max_limit):
        """
        Return a tuple with slice of items according to the requested marker
        and limit and a set of collection links

        :params items: resource item list
        :params request: webob request
        :params max_limit: maximum number of items to be returned
        :returns: (limited item list, collection links list) as a tuple
        """
        collection_links = []
        params = common.get_pagination_params(request)
        limit = params.get('limit', max_limit)
        marker = params.get('marker')
        limit = min(max_limit, limit)
        if limit == 0:
            return ([], [])
        start_index = 0
        if marker:
            start_index = -1
            for i, item in enumerate(items):
                # NOTE(siva): getter from generateDS
                if item.get_id() == marker:
                    start_index = i + 1
                    break
            if start_index < 0:
                msg = _('marker [%s] not found') % marker
                raise webob.exc.HTTPBadRequest(explanation=msg)
        range_end = start_index + limit
        prev_index = start_index - limit
        try:
            items[range_end]
            items[range_end - 1]
        except Exception:
            pass
        else:
            collection_links.append({
                'rel': 'next',
                'href': self._get_next_link(
                    request,
                    str(items[range_end - 1].get_id()), self._collection_name)
            })
        if prev_index > 0:
            collection_links.append({
                'rel': 'previous',
                'href': self._get_previous_link(
                    request,
                    str(items[prev_index - 1].get_id()), self._collection_name)
            })
        elif prev_index == 0:
            collection_links.append({
                'rel': 'previous',
                'href': self._get_previous_link(request,
                                                None, self._collection_name)
            })
        return (items[start_index:range_end], collection_links)
开发者ID:jessegonzalez,项目名称:healthnmon,代码行数:57,代码来源:base.py

示例3: detail

    def detail(self, req):
        """Return a detailed index listing of images available to the request.

        :param req: `wsgi.Request` object.

        """
        context = req.environ['nova.context']
        filters = self._get_filters(req)
        page_params = common.get_pagination_params(req)
        images = self._image_service.detail(context, filters=filters,
                                            **page_params)
        builder = self.get_builder(req).build
        return dict(images=[builder(image, detail=True) for image in images])
开发者ID:jdaymont,项目名称:nova,代码行数:13,代码来源:images.py

示例4: detail

    def detail(self, req):
        """Return a detailed index listing of images available to the request.

        :param req: `wsgi.Request` object.

        """
        context = req.environ["nova.context"]
        filters = self._get_filters(req)
        params = req.GET.copy()
        page_params = common.get_pagination_params(req)
        for key, val in page_params.iteritems():
            params[key] = val
        images = self._image_service.detail(context, filters=filters, **page_params)

        return self._view_builder.detail(req, images)
开发者ID:ironcamel,项目名称:nova,代码行数:15,代码来源:images.py

示例5: index

    def index(self, req):
        """Return an index listing of images available to the request.

        :param req: `wsgi.Request` object

        """
        context = req.environ['nova.context']
        filters = self._get_filters(req)
        page_params = common.get_pagination_params(req)

        try:
            images = self._image_api.get_all(context, filters=filters,
                                             **page_params)
        except exception.Invalid as e:
            raise webob.exc.HTTPBadRequest(explanation=e.format_message())
        return self._view_builder.index(req, images)
开发者ID:Juniper,项目名称:nova,代码行数:16,代码来源:images.py

示例6: index

    def index(self, req):
        """Return an index listing of images available to the request.

        :param req: `wsgi.Request` object

        """
        context = req.environ['nova.context']
        filters = self._get_filters(req)
        params = req.GET.copy()
        page_params = common.get_pagination_params(req)
        for key, val in page_params.iteritems():
            params[key] = val

        images = self._image_service.index(context, filters=filters,
                                           **page_params)
        return self.get_builder(req).build_list(images, **params)
开发者ID:blamarvt,项目名称:nova,代码行数:16,代码来源:images.py

示例7: _build_list

    def _build_list(self, req, instances, is_detail=False):
        params = req.GET.copy()
        pagination_params = common.get_pagination_params(req)
        # Update params with int() values from pagination params
        for key, val in pagination_params.iteritems():
            params[key] = val

        context = req.environ['nova.context']
        project_id = getattr(context, 'project_id', '')
        base_url = req.application_url
        flavor_builder = views_flavors.ViewBuilder(base_url, project_id)
        image_builder = views_images.ViewBuilder(base_url, project_id)
        addresses_builder = views_addresses.ViewBuilder()
        builder = views_servers.ViewBuilder(context, addresses_builder,
                flavor_builder, image_builder, base_url, project_id)
        return builder.build_list(instances, is_detail=is_detail, **params)
开发者ID:dragonetail,项目名称:nova,代码行数:16,代码来源:servers.py

示例8: detail

    def detail(self, req):
        """Return a detailed index listing of images available to the request.

        :param req: `wsgi.Request` object.

        """
        context = req.environ['nova.context']
        filters = self._get_filters(req)
        params = req.GET.copy()
        page_params = common.get_pagination_params(req)
        for key, val in page_params.iteritems():
            params[key] = val
        try:
            images = self._image_service.detail(context, filters=filters,
                                                **page_params)
        except exception.Invalid as e:
            raise webob.exc.HTTPBadRequest(explanation=str(e))

        return self._view_builder.detail(req, images)
开发者ID:AartiKriplani,项目名称:nova,代码行数:19,代码来源:images.py

示例9: _build_list

    def _build_list(self, req, instances, is_detail=False):
        params = req.GET.copy()
        pagination_params = common.get_pagination_params(req)
        # Update params with int() values from pagination params
        for key, val in pagination_params.iteritems():
            params[key] = val

        project_id = getattr(req.environ['nova.context'], 'project_id', '')
        base_url = req.application_url
        flavor_builder = nova.api.openstack.views.flavors.ViewBuilderV11(
            base_url, project_id)
        image_builder = nova.api.openstack.views.images.ViewBuilderV11(
            base_url, project_id)
        addresses_builder = nova.api.openstack.views.addresses.ViewBuilderV11()
        builder = nova.api.openstack.views.servers.ViewBuilderV11(
            addresses_builder, flavor_builder, image_builder,
            base_url, project_id)
        get_nw = self._get_networks_for_instance
        inst_data = [(inst, get_nw(req, inst)) for inst in instances]
        return builder.build_list(inst_data, is_detail=is_detail, **params)
开发者ID:daniel-hou0,项目名称:nova,代码行数:20,代码来源:servers.py

示例10: detail

    def detail(self, req):
        """Return a detailed index listing of images available to the request.

        :param req: `wsgi.Request` object.

        """
        context = req.environ['nova.context']
        filters = self._get_filters(req)
        params = req.GET.copy()
        page_params = common.get_pagination_params(req)
        for key, val in six.iteritems(page_params):
            params[key] = val
        try:
            images = self._image_api.get_all(context, filters=filters,
                                             **page_params)
        except exception.Invalid as e:
            raise webob.exc.HTTPBadRequest(explanation=e.format_message())

        req.cache_db_items('images', images, 'id')
        return self._view_builder.detail(req, images)
开发者ID:adelina-t,项目名称:nova,代码行数:20,代码来源:images.py

示例11: test_valid_limit_and_page_size

 def test_valid_limit_and_page_size(self):
     # Test valid limit and page_size parameters.
     req = webob.Request.blank("/?limit=20&page_size=5")
     self.assertEqual(common.get_pagination_params(req), {"page_size": 5, "limit": 20})
开发者ID:cyx1231st,项目名称:nova,代码行数:4,代码来源:test_common.py

示例12: test_valid_limit_and_marker

 def test_valid_limit_and_marker(self):
     # Test valid limit and marker parameters.
     marker = '263abb28-1de6-412f-b00b-f0ee0c4333c2'
     req = webob.Request.blank('/?limit=20&marker=%s' % marker)
     self.assertEqual(common.get_pagination_params(req),
                      {'marker': marker, 'limit': 20})
开发者ID:Charu-Sharma,项目名称:nova,代码行数:6,代码来源:test_common.py

示例13: test_valid_limit

 def test_valid_limit(self):
     # Test valid limit param.
     req = webob.Request.blank('/?limit=10')
     self.assertEqual(common.get_pagination_params(req), {'limit': 10})
开发者ID:Charu-Sharma,项目名称:nova,代码行数:4,代码来源:test_common.py

示例14: test_valid_marker

 def test_valid_marker(self):
     # Test valid marker param.
     req = webob.Request.blank(
             '/?marker=263abb28-1de6-412f-b00b-f0ee0c4333c2')
     self.assertEqual(common.get_pagination_params(req),
                      {'marker': '263abb28-1de6-412f-b00b-f0ee0c4333c2'})
开发者ID:Charu-Sharma,项目名称:nova,代码行数:6,代码来源:test_common.py

示例15: test_no_params

 def test_no_params(self):
     # Test no params.
     req = webob.Request.blank('/')
     self.assertEqual(common.get_pagination_params(req), {})
开发者ID:Charu-Sharma,项目名称:nova,代码行数:4,代码来源:test_common.py


注:本文中的nova.api.openstack.common.get_pagination_params函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。