cubes_lite/model/utils.py
def object_dict(objects, by_ref=False, error_message=None, error_dict=None, key_func=None):
    """Make an ordered dictionary from model objects `objects` where keys are
    object names. If `by_ref` is `True` then object's `ref` (reference) is
    used instead of object name. Keys are supposed to be unique in the list,
    otherwise an exception is raised."""

    objects = objects or []

    if by_ref:
        if key_func:
            raise ArgumentError(
                'Both `key_func` and `by_ref` arguments are disallowed'
            )
        key_func = attrgetter('ref')
    else:
        key_func = key_func or attrgetter('name')

    ordered = OrderedDict()

    items = ((key_func(obj), obj) for obj in objects)
    for key, value in items:
        if key in ordered:
            error_message = error_message or 'Duplicate key {key}'
            error_dict = error_dict or {}
            raise ModelError(error_message.format(key=key, **error_dict))
        ordered[key] = value

    return ordered
Make an ordered dictionary from model objects `objects` where keys are
    object names. If `by_ref` is `True` then object's `ref` (reference) is
    used instead of object name. Keys are supposed to be unique in the list,
    otherwise an exception is raised.
Make an ordered dictionary from model objects `objects` where keys are
object names.
Make an ordered dictionary from model objects ` objects ` where keys are object names .
def object_dict(objects, by_ref=False, error_message=None, error_dict=None, key_func=None):
    objects = objects or []
    if by_ref:
        if key_func:
            raise ArgumentError(
                'Both `key_func` and `by_ref` arguments are disallowed'
            )
        key_func = attrgetter('ref')
    else:
        key_func = key_func or attrgetter('name')
    ordered = OrderedDict()
    items = ((key_func(obj), obj) for obj in objects)
    for key, value in items:
        if key in ordered:
            error_message = error_message or 'Duplicate key {key}'
            error_dict = error_dict or {}
            raise ModelError(error_message.format(key=key, **error_dict))
        ordered[key] = value
    return ordered
def object_dict ( objects , by_ref = False , error_message = None , error_dict = None , key_func = None ) : objects = objects or [ ] if by_ref : if key_func : raise ArgumentError ( 'Both `key_func` and `by_ref` arguments are disallowed' ) key_func = attrgetter ( 'ref' ) else : key_func = key_func or attrgetter ( 'name' ) ordered = OrderedDict ( ) items = ( ( key_func ( obj ) , obj ) for obj in objects ) for key , value in items : if key in ordered : error_message = error_message or 'Duplicate key {key}' error_dict = error_dict or { } raise ModelError ( error_message . format ( key = key , ** error_dict ) ) ordered [ key ] = value return ordered
Make an ordered dictionary from model objects `objects` where keys are
object names.
Make an ordered dictionary from model objects ` objects ` where keys are object names .
"""Make an ordered dictionary from model objects `objects` where keys are
    object names. If `by_ref` is `True` then object's `ref` (reference) is
    used instead of object name. Keys are supposed to be unique in the list,
    otherwise an exception is raised."""
objects
by_ref
error_message
error_dict
key_func