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


Python hybrid.hybrid_property方法代码示例

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


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

示例1: __init__

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

        Usage is typically via decorator::

            from sqlalchemy.ext.hybrid import hybrid_property

            class SomeClass(object):
                @hybrid_property
                def value(self):
                    return self._value

                @value.setter
                def value(self, value):
                    self._value = value

        """
        self.fget = fget
        self.fset = fset
        self.fdel = fdel
        self.expr = expr or fget
        util.update_wrapper(self, fget) 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:hybrid.py

示例2: DateTimeAtColumn

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def DateTimeAtColumn(prefix: str) -> hybrid_property:
    datetime_key = f'{prefix}_datetime'
    timezone_key = f'{prefix}_timezone'

    def getter(self) -> Optional[datetime.datetime]:
        dt: Optional[datetime.datetime] = getattr(self, datetime_key)
        tz: Optional[datetime.tzinfo] = getattr(self, timezone_key)
        if dt and tz:
            return dt.replace(tzinfo=UTC).astimezone(tz)
        if dt:
            return dt.replace(tzinfo=None)
        return dt

    def setter(self, dt: datetime.datetime):
        setattr(self, timezone_key, dt.tzinfo)
        setattr(self, datetime_key, dt.astimezone(UTC))

    def custom_comparator(cls):
        return DateTimeAtComparator(
            getattr(cls, datetime_key), getattr(cls, timezone_key),
        )

    return hybrid_property(
        fget=getter, fset=setter, custom_comparator=custom_comparator,
    ) 
开发者ID:item4,项目名称:yui,代码行数:27,代码来源:columns.py

示例3: create_column

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def create_column(self, cname, remote_type, foreign_key, properties):

        def wrapper(cls):
            return SA_Column(
                cname.attribute_name,
                remote_type,
                nullable=self.nullable,
                unique=self.unique,
                index=self.index,
                primary_key=self.primary_key,
                info=dict(label=self.label, foreign_key=foreign_key))

        properties[(anyblok_column_prefix +
                    cname.attribute_name)] = declared_attr(wrapper)
        properties['loaded_columns'].append(cname.attribute_name)
        properties['hybrid_property_columns'].append(cname.attribute_name)
        properties[cname.attribute_name] = hybrid_property(
            self.wrap_getter_column(cname.attribute_name),
            super(Many2One, self).wrap_setter_column(cname.attribute_name),
            expr=self.wrap_expr_column(cname.attribute_name)) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:22,代码来源:relationship.py

示例4: get_property

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def get_property(self, registry, namespace, fieldname, properties):
        """Return the property of the field

        .. warning::

            In the case of the get is called in classattribute,
            SQLAlchemy wrap for each call the column, the id of the wrapper
            is not the same

        :param registry: current registry
        :param namespace: name of the model
        :param fieldname: name of the field
        :param properties: properties known to the model
        """
        return hybrid_property(
            self.wrap_getter_column(fieldname),
            self.wrap_setter_column(fieldname),
            expr=self.wrap_expr_column(fieldname)) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:20,代码来源:field.py

示例5: get_sqlalchemy_mapping

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def get_sqlalchemy_mapping(self, registry, namespace, fieldname,
                               properties):
        """Return the property of the field

        :param registry: current registry
        :param namespace: name of the model
        :param fieldname: name of the field
        :param properties: properties known to the model
        """
        self.format_label(fieldname)
        properties['loaded_fields'][fieldname] = self.label
        return hybrid_property(
            self.get_fget(),
            self.get_fset(),
            fdel=self.get_fdel(),
            expr=self.get_fexpr()
        ) 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:19,代码来源:field.py

示例6: __init__

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

        Usage is typically via decorator::

            from sqlalchemy.ext.hybrid import hybrid_property

            class SomeClass(object):
                @hybrid_property
                def value(self):
                    return self._value

                @value.setter
                def value(self, value):
                    self._value = value

        """
        self.fget = fget
        self.fset = fset
        self.fdel = fdel
        self.expression(expr or fget)
        util.update_wrapper(self, fget) 
开发者ID:eirannejad,项目名称:pyRevit,代码行数:24,代码来源:hybrid.py

示例7: _db_row_to_dict

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def _db_row_to_dict(row, remove_columns=False):
    """Converts a DB object to a dictionary."""

    from sqlalchemy.inspection import inspect as sa_inspect
    from sqlalchemy.ext.hybrid import hybrid_property

    row_dict = collections.OrderedDict()

    columns = row.__table__.columns.keys()

    mapper = sa_inspect(row.__class__)
    for key, item in mapper.all_orm_descriptors.items():

        if isinstance(item, hybrid_property):
            columns.append(key)

    for col in columns:
        if remove_columns and col in remove_columns:
            continue
        row_dict[col] = getattr(row, col)

    return row_dict 
开发者ID:sdss,项目名称:marvin,代码行数:24,代码来源:general.py

示例8: _loadParams

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [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

示例9: _fixture

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

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

            @hybrid.hybrid_property
            def value(self):
                return self._value - 5

            if assignable:

                @value.setter
                def value(self, v):
                    self._value = v + 5

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

示例10: _get_model_hybrid_properties

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def _get_model_hybrid_properties(model, ins):
    """ Get a dict of model hybrid properties """
    return {name: getattr(model, name)
            for name, c in ins.all_orm_descriptors.items()
            if not name.startswith('_')
            and isinstance(c, hybrid_property)} 
开发者ID:kolypto,项目名称:py-mongosql,代码行数:8,代码来源:bag.py

示例11: fields

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def fields(self):
        model = self.index.model
        schema_fields = self._fields()
        primary_keys = [key.name for key in inspect(model).primary_key]

        schema = getattr(model, "__msearch_schema__", dict())
        for field in self.index.searchable:
            if '.' in field:
                fields = field.split('.')
                field_attr = getattr(
                    getattr(model, fields[0]).property.mapper.class_,
                    fields[1])
            else:
                field_attr = getattr(model, field)

            if field in schema:
                field_type = schema[field]
                if isinstance(field_type, str):
                    schema_fields[field] = self.fields_map(field_type)
                else:
                    schema_fields[field] = field_type
                continue

            if hasattr(field_attr, 'descriptor') and isinstance(
                    field_attr.descriptor, hybrid_property):
                schema_fields[field] = self.fields_map("text")
                continue

            if field in primary_keys:
                schema_fields[field] = self.fields_map("primary")
                continue

            field_type = field_attr.property.columns[0].type
            schema_fields[field] = self.fields_map(field_type)
        return schema_fields 
开发者ID:honmaple,项目名称:flask-msearch,代码行数:37,代码来源:backends.py

示例12: hybrid_properties

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

示例13: get_property

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def get_property(self, registry, namespace, fieldname, properties):
        """Return the property of the field

        :param registry: current registry
        :param namespace: name of the model
        :param fieldname: name of the field
        :param properties: properties known to the model
        """
        res = super(Many2One, self).get_property(
            registry, namespace, fieldname, properties)
        # force the info value in hybrid_property because since SQLAlchemy
        # 1.1.* the info is not propagate
        res.info = self.kwargs['info']
        return res 
开发者ID:AnyBlok,项目名称:AnyBlok,代码行数:16,代码来源:relationship.py

示例14: __init__

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

        Usage is typically via decorator::

            from sqlalchemy.ext.hybrid import hybrid_property

            class SomeClass(object):
                @hybrid_property
                def value(self):
                    return self._value

                @value.setter
                def value(self, value):
                    self._value = value

        """
        self.fget = fget
        self.fset = fset
        self.fdel = fdel
        self.expr = expr
        self.custom_comparator = custom_comparator
        self.update_expr = update_expr
        util.update_wrapper(self, fget) 
开发者ID:yfauser,项目名称:planespotter,代码行数:28,代码来源:hybrid.py

示例15: overrides

# 需要导入模块: from sqlalchemy.ext import hybrid [as 别名]
# 或者: from sqlalchemy.ext.hybrid import hybrid_property [as 别名]
def overrides(self):
        """Prefix for a method that is overriding an existing attribute.

        The :attr:`.hybrid_property.overrides` accessor just returns
        this hybrid object, which when called at the class level from
        a parent class, will de-reference the "instrumented attribute"
        normally returned at this level, and allow modifying decorators
        like :meth:`.hybrid_property.expression` and
        :meth:`.hybrid_property.comparator`
        to be used without conflicting with the same-named attributes
        normally present on the :class:`.QueryableAttribute`::

            class SuperClass(object):
                # ...

                @hybrid_property
                def foobar(self):
                    return self._foobar

            class SubClass(SuperClass):
                # ...

                @SuperClass.foobar.overrides.expression
                def foobar(cls):
                    return func.subfoobar(self._foobar)

        .. versionadded:: 1.2

        .. seealso::

            :ref:`hybrid_reuse_subclass`

         """
        return self 
开发者ID:yfauser,项目名称:planespotter,代码行数:36,代码来源:hybrid.py


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