Source code for pyams_alchemy.mixin

#
# Copyright (c) 2008-2015 Thierry Florac <tflorac AT ulthar.net>
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#

__docformat__ = 'restructuredtext'


# import standard library

# import interfaces

# import packages
from pyams_utils.registry import get_global_registry
from sqlalchemy.ext.declarative import declared_attr


[docs]class DynamicSchemaMixin(object): """Dynamic schema mixin class This class is used to set an entity schema name in Pyramid settings """ __schema__ = None
[docs] @classmethod def get_schema_settings_name(cls): return 'pyams_alchemy:{0}.{1}.schema'.format(cls.__module__, cls.__name__)
[docs] @classmethod def get_schema(cls): settings_name = cls.get_schema_settings_name() if settings_name: registry = get_global_registry() if hasattr(registry, 'settings'): return {'schema': registry.settings.get(settings_name, cls.__schema__)} return {'schema': cls.__schema__}
@declared_attr def __table_args__(cls): return cls.get_schema()