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


Python exception.InvalidSortKey方法代码示例

本文整理汇总了Python中oslo_db.exception.InvalidSortKey方法的典型用法代码示例。如果您正苦于以下问题:Python exception.InvalidSortKey方法的具体用法?Python exception.InvalidSortKey怎么用?Python exception.InvalidSortKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在oslo_db.exception的用法示例。


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

示例1: _paginate_query

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def _paginate_query(model, limit=None, marker=None, sort_key=None,
                    sort_dir=None, query=None, default_sort_key='id'):
    if not query:
        query = model_query(model)
    sort_keys = [default_sort_key]
    if sort_key and sort_key not in sort_keys:
        sort_keys.insert(0, sort_key)
    try:
        query = db_utils.paginate_query(query, model, limit, sort_keys,
                                        marker=marker, sort_dir=sort_dir)
    except db_exc.InvalidSortKey:
        raise exception.InvalidParameterValue(
            _('The sort_key value "%(key)s" is an invalid field for sorting')
            % {'key': sort_key})
    return query.all() 
开发者ID:openstack,项目名称:zun,代码行数:17,代码来源:api.py

示例2: _paginate_query

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def _paginate_query(model, limit=None, marker=None, sort_key=None,
                    sort_dir=None, query=None):
    if not query:
        query = model_query(model)
    sort_keys = ['id']
    if sort_key and sort_key not in sort_keys:
        sort_keys.insert(0, sort_key)
    try:
        query = db_utils.paginate_query(query, model, limit, sort_keys,
                                        marker=marker, sort_dir=sort_dir)
    except db_exc.InvalidSortKey:
        raise exception.InvalidParameterValue(
            _('The sort_key value "%(key)s" is an invalid field for sorting')
            % {'key': sort_key})
    return query.all() 
开发者ID:openstack,项目名称:magnum,代码行数:17,代码来源:api.py

示例3: failover_segment_get_all_by_filters

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def failover_segment_get_all_by_filters(
        context, filters=None, sort_keys=None,
        sort_dirs=None, limit=None, marker=None):

    # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going
    # to the database since nothing is going to be returned anyway.
    if limit == 0:
        return []

    sort_keys, sort_dirs = _process_sort_params(sort_keys,
                                                sort_dirs)
    filters = filters or {}
    query = model_query(context, models.FailoverSegment)

    if 'recovery_method' in filters:
        query = query.filter(models.FailoverSegment.recovery_method == filters[
            'recovery_method'])
    if 'service_type' in filters:
        query = query.filter(models.FailoverSegment.service_type == filters[
            'service_type'])

    marker_row = None
    if marker is not None:
        marker_row = model_query(context,
                                 models.FailoverSegment
                                 ).filter_by(id=marker).first()

        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    try:
        query = sqlalchemyutils.paginate_query(query, models.FailoverSegment,
                                               limit, sort_keys,
                                               marker=marker_row,
                                               sort_dirs=sort_dirs)
    except db_exc.InvalidSortKey as e:
        raise exception.InvalidSortKey(e)

    return query.all() 
开发者ID:openstack,项目名称:masakari,代码行数:41,代码来源:api.py

示例4: test_invalid_sort_key_str

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def test_invalid_sort_key_str(self):
        self.assertEqual("Sort key supplied is invalid: None",
                         str(exception.InvalidSortKey()))
        self.assertEqual("Sort key supplied is invalid: lol",
                         str(exception.InvalidSortKey("lol"))) 
开发者ID:openstack,项目名称:oslo.db,代码行数:7,代码来源:test_utils.py

示例5: test_paginate_query_attribute_error

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def test_paginate_query_attribute_error(self):
        self.mock_asc.return_value = 'asc'

        self.assertRaises(exception.InvalidSortKey,
                          utils.paginate_query, self.query,
                          self.model, 5, ['user_id', 'non-existent key'])

        self.mock_asc.assert_called_once_with(self.model.user_id)
        self.query.order_by.assert_called_once_with('asc') 
开发者ID:openstack,项目名称:oslo.db,代码行数:11,代码来源:test_utils.py

示例6: test_paginate_query_attribute_error_invalid_sortkey

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def test_paginate_query_attribute_error_invalid_sortkey(self):
        self.assertRaises(exception.InvalidSortKey,
                          utils.paginate_query, self.query,
                          self.model, 5, ['bad_user_id']) 
开发者ID:openstack,项目名称:oslo.db,代码行数:6,代码来源:test_utils.py

示例7: test_paginate_query_attribute_error_invalid_sortkey_2

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def test_paginate_query_attribute_error_invalid_sortkey_2(self):
        self.assertRaises(exception.InvalidSortKey,
                          utils.paginate_query, self.query,
                          self.model, 5, ['foo']) 
开发者ID:openstack,项目名称:oslo.db,代码行数:6,代码来源:test_utils.py

示例8: test_paginate_query_attribute_error_invalid_sortkey_3

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def test_paginate_query_attribute_error_invalid_sortkey_3(self):
        self.assertRaises(exception.InvalidSortKey,
                          utils.paginate_query, self.query,
                          self.model, 5, ['asc-nullinvalid']) 
开发者ID:openstack,项目名称:oslo.db,代码行数:6,代码来源:test_utils.py

示例9: _paginate_query

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def _paginate_query(context, model, query, limit=None, marker=None,
                    sort_key=None, sort_dir=None):
    sort_keys = ['id']
    if sort_key and sort_key not in sort_keys:
        sort_keys.insert(0, sort_key)
    try:
        query = sqlalchemyutils.paginate_query(query, model, limit, sort_keys,
                                               marker=marker,
                                               sort_dir=sort_dir)
    except db_exc.InvalidSortKey:
        raise exception.InvalidParameterValue(
            _('The sort_key value "%(key)s" is an invalid field for sorting')
            % {'key': sort_key})
    return query.all() 
开发者ID:openstack,项目名称:cyborg,代码行数:16,代码来源:api.py

示例10: host_get_all_by_filters

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def host_get_all_by_filters(
        context, filters=None, sort_keys=None,
        sort_dirs=None, limit=None, marker=None):

    # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going
    # to the database since nothing is going to be returned anyway.
    if limit == 0:
        return []

    sort_keys, sort_dirs = _process_sort_params(sort_keys,
                                                sort_dirs)

    filters = filters or {}
    query = model_query(context,
                        models.Host).options(joinedload('failover_segment'))

    if 'failover_segment_id' in filters:
        query = query.filter(models.Host.failover_segment_id == filters[
            'failover_segment_id'])

    if 'type' in filters:
        query = query.filter(models.Host.type == filters['type'])

    if 'on_maintenance' in filters:
        query = query.filter(models.Host.on_maintenance == filters[
            'on_maintenance'])

    if 'reserved' in filters:
        query = query.filter(models.Host.reserved == filters['reserved'])

    marker_row = None
    if marker is not None:
        marker_row = model_query(context,
                                 models.Host
                                 ).filter_by(id=marker).first()
        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    try:
        query = sqlalchemyutils.paginate_query(query, models.Host, limit,
                                               sort_keys,
                                               marker=marker_row,
                                               sort_dirs=sort_dirs)
    except db_exc.InvalidSortKey as e:
        raise exception.InvalidSortKey(e)

    return query.all() 
开发者ID:openstack,项目名称:masakari,代码行数:49,代码来源:api.py

示例11: notifications_get_all_by_filters

# 需要导入模块: from oslo_db import exception [as 别名]
# 或者: from oslo_db.exception import InvalidSortKey [as 别名]
def notifications_get_all_by_filters(
        context, filters=None, sort_keys=None,
        sort_dirs=None, limit=None, marker=None):

    # NOTE(Dinesh_Bhor): If the limit is 0 there is no point in even going
    # to the database since nothing is going to be returned anyway.
    if limit == 0:
        return []

    sort_keys, sort_dirs = _process_sort_params(sort_keys,
                                                sort_dirs)

    filters = filters or {}
    query = model_query(context, models.Notification)

    if 'source_host_uuid' in filters:
        query = query.filter(models.Notification.source_host_uuid == filters[
            'source_host_uuid'])

    if 'type' in filters:
        query = query.filter(models.Notification.type == filters['type'])

    if 'status' in filters:
        status = filters['status']
        if isinstance(status, (list, tuple, set, frozenset)):
            column_attr = getattr(models.Notification, 'status')
            query = query.filter(column_attr.in_(status))
        else:
            query = query.filter(models.Notification.status == status)

    if 'generated-since' in filters:
        generated_since = timeutils.normalize_time(filters['generated-since'])
        query = query.filter(
            models.Notification.generated_time >= generated_since)

    marker_row = None
    if marker is not None:
        marker_row = model_query(context,
                                 models.Notification
                                 ).filter_by(id=marker).first()
        if not marker_row:
            raise exception.MarkerNotFound(marker=marker)

    try:
        query = sqlalchemyutils.paginate_query(query, models.Notification,
                                               limit,
                                               sort_keys,
                                               marker=marker_row,
                                               sort_dirs=sort_dirs)
    except db_exc.InvalidSortKey as err:
        raise exception.InvalidSortKey(err)

    return query.all() 
开发者ID:openstack,项目名称:masakari,代码行数:55,代码来源:api.py


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