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


Python hybrid.hybrid_method方法代码示例

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


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

示例1: __init__

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def __init__(self, func, expr=None):
        """Create a new :class:`.hybrid_method`.

        Usage is typically via decorator::

            from sqlalchemy.ext.hybrid import hybrid_method

            class SomeClass(object):
                @hybrid_method
                def value(self, x, y):
                    return self._value + x + y

                @value.expression
                def value(self, x, y):
                    return func.some_function(self._value, x, y)

        """
        self.func = func
        self.expr = expr or func 
开发者ID:jpush,项目名称:jbox,代码行数:21,代码来源:hybrid.py

示例2: transform_base_attribute

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def transform_base_attribute(self, attr, method, namespace, base,
                                 transformation_properties,
                                 new_type_properties):
        """ Find the sqlalchemy hybrid methods in the base to save the
        namespace and the method in the registry

        :param attr: attribute name
        :param method: method pointer of the attribute
        :param namespace: the namespace of the model
        :param base: One of the base of the model
        :param transformation_properties: the properties of the model
        :param new_type_properties: param to add in a new base if need
        """
        if not hasattr(method, 'is_an_hybrid_method'):
            return
        elif method.is_an_hybrid_method is True:
            if attr not in transformation_properties['hybrid_method']:
                transformation_properties['hybrid_method'].append(attr) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:20,代码来源:hybrid_method.py

示例3: __init__

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def __init__(self, func, expr=None):
        """Create a new :class:`.hybrid_method`.

        Usage is typically via decorator::

            from sqlalchemy.ext.hybrid import hybrid_method

            class SomeClass(object):
                @hybrid_method
                def value(self, x, y):
                    return self._value + x + y

                @value.expression
                def value(self, x, y):
                    return func.some_function(self._value, x, y)

        """
        self.func = func
        self.expression(expr or func) 
开发者ID:yfauser,项目名称:planespotter,代码行数:21,代码来源:hybrid.py

示例4: _loadParams

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def _loadParams(self, newclass):
        ''' Loads all parameters from wtforms into a dictionary with
            key, value = {'parameter_name': 'parent WTForm name'}.
            Ignores hidden attributes and the Meta class
        '''

        model = newclass.Meta.model
        schema = model.__table__.schema
        tablename = model.__table__.name

        mapper = sa_inspect(model)
        for key, item in mapper.all_orm_descriptors.items():
            if isinstance(item, (hybrid_property, hybrid_method)):
                key = key
            elif isinstance(item, InstrumentedAttribute):
                key = item.key
            else:
                continue

            lookupKeyName = schema + '.' + tablename + '.' + key
            self._param_form_lookup[lookupKeyName] = newclass
            self._paramtree[newclass.Meta.model.__name__][key] 
开发者ID:sdss,项目名称:marvin,代码行数:24,代码来源:forms.py

示例5: hybrid_methods_full

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def hybrid_methods_full(cls):
        items = inspect(cls).all_orm_descriptors
        return {item.func.__name__: item
                for item in items if type(item) == hybrid_method} 
开发者ID:absent1706,项目名称:sqlalchemy-mixins,代码行数:6,代码来源:inspection.py

示例6: initialisation_tranformation_properties

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def initialisation_tranformation_properties(self, properties,
                                                transformation_properties):
        """ Initialise the transform properties: hybrid_method

        :param properties: the properties declared in the model
        :param new_type_properties: param to add in a new base if need
        """
        if 'hybrid_method' not in transformation_properties:
            transformation_properties['hybrid_method'] = [] 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:11,代码来源:hybrid_method.py

示例7: insert_in_bases

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def insert_in_bases(self, new_base, namespace, properties,
                        transformation_properties):
        """ Create overload to define the write declaration of sqlalchemy
        hybrid method, add the overload in the declared bases of the
        namespace

        :param new_base: the base to be put on front of all bases
        :param namespace: the namespace of the model
        :param properties: the properties declared in the model
        :param transformation_properties: the properties of the model
        """
        type_properties = {}

        def apply_wrapper(attr):

            def wrapper(self, *args, **kwargs):
                self_ = self.registry.loaded_namespaces[self.__registry_name__]
                if self is self_:
                    return getattr(super(new_base, self), attr)(
                        self, *args, **kwargs)
                elif hasattr(self, '_aliased_insp'):
                    return getattr(super(new_base, self._aliased_insp._target),
                                   attr)(self, *args, **kwargs)
                else:
                    return getattr(super(new_base, self), attr)(
                        *args, **kwargs)

            setattr(new_base, attr, hybrid_method(wrapper))

        if transformation_properties['hybrid_method']:
            for attr in transformation_properties['hybrid_method']:
                apply_wrapper(attr)

        return type_properties 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:36,代码来源:hybrid_method.py

示例8: _fixture

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_method [as 别名]
def _fixture(self):
        Base = declarative_base()

        class A(Base):
            __tablename__ = "a"
            id = Column(Integer, primary_key=True)
            _value = Column("value", String)

            @hybrid.hybrid_method
            def value(self, x):
                "This is an instance-level docstring"
                return int(self._value) + x

            @value.expression
            def value(cls, value):
                "This is a class-level docstring"
                return func.foo(cls._value, value) + value

            @hybrid.hybrid_method
            def other_value(self, x):
                "This is an instance-level docstring"
                return int(self._value) + x

            @other_value.expression
            def other_value(cls, value):
                return func.foo(cls._value, value) + value

        return A 
开发者ID:sqlalchemy,项目名称:sqlalchemy,代码行数:30,代码来源:test_hybrid.py


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