Example #1
0
def get_inheritance(table):
    # inheritance
    inherits = []
    mapper = None
    for m, s in _mapper_registry.items():
        if m.local_table is table:
            mapper = m

    curr_mapper = mapper
    while curr_mapper is not None:
        curr_mapper = curr_mapper.inherits
        if curr_mapper is not None and \
                curr_mapper.local_table.name != table.name:
            inherits.append(curr_mapper.local_table.name)

    inherits.reverse()
    return inherits
Example #2
0
File: sqla.py Project: runyaga/ptah
def get_inheritance(table):
    # inheritance
    inherits = []
    mapper = None
    for m, s in _mapper_registry.items():
        if m.local_table is table:
            mapper = m

    curr_mapper = mapper
    while curr_mapper is not None:
        curr_mapper = curr_mapper.inherits
        if curr_mapper is not None and \
                curr_mapper.local_table.name != table.name and \
                curr_mapper.local_table.name not in inherits:
            inherits.append(curr_mapper.local_table.name)

    inherits.reverse()
    return inherits
Example #3
0
def clear_mappers():
    """
    Clears all mappers set up by SA and also clears all custom "id" and
    "slug" attributes inserted by the :func:`mapper` function in this module.

    This should only ever be needed in a testing context.
    """
    # Remove our hybrid property constructs.
    for mpr, is_primary in _mapper_registry.items():
        if is_primary:
            for attr_name in ('id', 'slug'):
                try:
                    attr = object.__getattribute__(mpr.class_, attr_name)
                    if isinstance(attr, hybrid_property):
                        if attr_name == 'id':
                            delattr(mpr.class_, attr_name)
                        else:
                            setattr(mpr.class_, attr_name, attr.descriptor)
                except AttributeError:
                    pass
    sa_clear_mappers()
Example #4
0
def clear_mappers():
    """
    Clears all mappers set up by SA and also clears all custom "id" and
    "slug" attributes inserted by the :func:`mapper` function in this module.

    This should only ever be needed in a testing context.
    """
    # Remove our hybrid property constructs.
    for mpr, is_primary in _mapper_registry.items():
        if is_primary:
            for attr_name in ("id", "slug"):
                try:
                    attr = object.__getattribute__(mpr.class_, attr_name)
                    if isinstance(attr, hybrid_property):
                        if attr_name == "id":
                            delattr(mpr.class_, attr_name)
                        else:
                            setattr(mpr.class_, attr_name, attr.descriptor)
                except AttributeError:
                    pass
    sa_clear_mappers()