本文整理汇总了Python中sqlalchemy.orm.composite函数的典型用法代码示例。如果您正苦于以下问题:Python composite函数的具体用法?Python composite怎么用?Python composite使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了composite函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: setup_mappers
def setup_mappers(cls):
class Descriptions(_base.BasicEntity):
pass
class Values(_base.BasicEntity):
pass
class CustomValues(_base.BasicEntity, list):
def __init__(self, *args):
self.extend(args)
def __composite_values__(self):
return self
desc_values = select(
[values, descriptions.c.d1, descriptions.c.d2],
descriptions.c.id == values.c.description_id
).alias('descriptions_values')
mapper(Descriptions, descriptions, properties={
'values': relationship(Values, lazy='dynamic'),
'custom_descriptions': composite(
CustomValues,
descriptions.c.d1,
descriptions.c.d2),
})
mapper(Values, desc_values, properties={
'custom_values': composite(CustomValues,
desc_values.c.v1,
desc_values.c.v2),
})
开发者ID:chatch,项目名称:pinyin-toolkit,代码行数:34,代码来源:test_composites.py
示例2: InitMapper
def InitMapper( cls, metadata, ObjectType ):
cls.__table__ = Table( cls.__tablename__, metadata,
Column('id', Integer, index = True, primary_key = True),
Column('type_id', Integer, ForeignKey( ObjectType.id ), nullable = False),
Column('parent_id', Integer, ForeignKey( "%s.id" % cls.__tablename__ ), nullable = True),
Column('name', Text, nullable = False),
Column('size', Integer(64), nullable = False, default = 0),
Column('pos_x', Integer(64), nullable = False, default = 0),
Column('pos_y', Integer(64), nullable = False, default = 0),
Column('pos_z', Integer(64), nullable = False, default = 0),
Column('mtime', DateTime, nullable = False,
onupdate = func.current_timestamp(), default = func.current_timestamp()))
cols = cls.__table__.c
Index('ix_%s_position' % cls.__tablename__, cols.pos_x, cols.pos_y, cols.pos_z)
mapper( cls, cls.__table__, polymorphic_on = cols.type_id, properties = {
'type': relation( ObjectType,
uselist = False,
backref = backref( 'objects' )),
# Tree like hierarchy for objects ie. Universe => Solar systems => Planets => etc.
'children': relation( cls,
backref = backref( 'parent', remote_side = [ cols.id ] )),
# Object position in 3D space
'position': composite( Vector3D, cols.pos_x, cols.pos_y, cols.pos_z ),
})
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:27,代码来源:Object.py
示例3: setup_mappers
def setup_mappers(cls):
a, b = cls.tables.a, cls.tables.b
class A(cls.Comparable):
pass
class B(cls.Comparable):
pass
class C(cls.Comparable):
def __init__(self, b1, b2):
self.b1, self.b2 = b1, b2
def __composite_values__(self):
return self.b1, self.b2
def __eq__(self, other):
return (
isinstance(other, C)
and other.b1 == self.b1
and other.b2 == self.b2
)
mapper(
A,
a,
properties={"b2": relationship(B), "c": composite(C, "b1", "b2")},
)
mapper(B, b)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:29,代码来源:test_composites.py
示例4: prep_database
def prep_database():
global myengine
# create engine
myengine = create_engine('sqlite:///:memory:', echo=False)
# setup table metadata
metadata = MetaData()
table_infomatic = Table('infomatic', metadata,
Column('id', Integer, primary_key=True),
Column('info', Unicode(255)),
Column('expectedoffset', Integer),
Column('utcdate', DateTime), # for TZAwareDateTime
Column('tzname', Unicode), # for TZAwareDateTime
Column('tzoffset', Integer)) # for TZAwareDateTime
# setup mappings
mapper(InfoMatic, table_infomatic, properties={
'info': table_infomatic.c.info,
'expectedoffset': table_infomatic.c.expectedoffset,
'tzawaredate': composite(TZAwareDateTime,
table_infomatic.c.utcdate,
table_infomatic.c.tzname,
table_infomatic.c.tzoffset)
})
# create all tables
metadata.create_all(myengine)
开发者ID:tephyr,项目名称:sqlalchemy_tzaware,代码行数:28,代码来源:demo.py
示例5: i18nString
def i18nString(name: str, with_plural: bool=False, **kwargs) -> CompositeProperty:
"""
Translatable String
Usage:
>>> news.topic = ('Deutscher Titel', 'English Topic')
>>> news.topic.en
'English Topic'
>>> template.render('{{ _(news.topic) }}')
'Deutscher Titel'
:param name: Prefix of column names
:param with_plural: Does this Column can have a plural?
If true, it will generate for each language a \*_pl column additionally.
:param kwargs: Additional Parameters passed to Column Instance
:rtype: :class:`_i18nObject` as :class:`MutableObject(**environment.langs)`
"""
dwargs = dict(nullable=False, server_default='')
dwargs.update(kwargs)
columns = []
for lang in environment.langs:
columns.append(Column('%s_%s' % (name, lang), sqUnicode, **dwargs))
if with_plural:
for lang in environment.langs:
columns.append(Column('%s_%s_pl' % (name, lang), sqUnicode, **dwargs))
cls = composite(with_plural and _i18nPluralizedObject or _i18nObject,
*columns,
comparator_factory=_i18nObjectComparator)
return cls
开发者ID:MartinMartimeo,项目名称:avalon,代码行数:35,代码来源:i18n.py
示例6: test_addr_composite
def test_addr_composite(self):
flds = "name addr1 addr2 addr3 addr4 email fax phone".split()
class B(DeclarativeBaseGuid):
__tablename__ = "b_table"
def __init__(self, **kwargs):
for k, v in kwargs.items():
setattr(self, k, v)
l = []
for fld in flds:
col = Column(fld, TEXT())
setattr(B, fld, col)
l.append(col)
B.addr = composite(Address, *l)
s = session()
a = B(addr1="foo")
assert a.addr
a.addr.fax = "baz"
assert a.addr1 == "foo"
assert a.addr.addr1 == "foo"
assert a.addr.fax == "baz"
s.add(a)
s.flush()
开发者ID:sdementen,项目名称:piecash,代码行数:26,代码来源:test_model_common.py
示例7: setup_mappers
def setup_mappers(cls):
a, b = cls.tables.a, cls.tables.b
class A(cls.Comparable):
pass
class B(cls.Comparable):
pass
class C(cls.Comparable):
def __init__(self, b1, b2):
self.b1, self.b2 = b1, b2
def __composite_values__(self):
return self.b1, self.b2
def __eq__(self, other):
return isinstance(other, C) and \
other.b1 == self.b1 and \
other.b2 == self.b2
mapper(A, a, properties={
'b2':relationship(B),
'c':composite(C, 'b1', 'b2')
})
mapper(B, b)
开发者ID:Affirm,项目名称:sqlalchemy,代码行数:26,代码来源:test_composites.py
示例8: setUp
def setUp(self):
"""prep db access"""
# create engine
self.db_myengine = create_engine('sqlite:///:memory:', echo=False)
# setup table metadata
self.db_metadata = MetaData()
table_infomatic = Table('infomatic', self.db_metadata,
Column('id', Integer, primary_key=True),
Column('info', Unicode(255)),
Column('expectedoffset', Integer),
Column('utcdate', DateTime), # for tzawaredate
Column('tzname', Unicode), # for tzawaredate
Column('tzoffset', Integer)) # for tzawaredate
# setup mappings
mapper(InfoMatic, table_infomatic, properties={
'info': table_infomatic.c.info,
'expectedoffset': table_infomatic.c.expectedoffset,
'tzawaredate': composite(tzaware_datetime.TZAwareDateTime,
table_infomatic.c.utcdate,
table_infomatic.c.tzname,
table_infomatic.c.tzoffset)
})
# create all tables
self.db_metadata.create_all(self.db_myengine)
# create session
self.session = create_session(bind=self.db_myengine, autocommit=True, autoflush=True)
开发者ID:tephyr,项目名称:sqlalchemy_tzaware,代码行数:30,代码来源:test_tzaware_datetime.py
示例9: setup_mappers
def setup_mappers(cls):
foo = cls.tables.foo
Point = cls._type_fixture()
mapper(Foo, foo, properties={
'data': composite(Point, foo.c.x, foo.c.y)
})
开发者ID:Daniel-B-Smith,项目名称:sqlalchemy,代码行数:8,代码来源:test_mutable.py
示例10: _fixture
def _fixture(self):
class AB(object):
def __init__(self, a, b, cd):
self.a = a
self.b = b
self.cd = cd
@classmethod
def generate(cls, a, b, c, d):
return AB(a, b, CD(c, d))
def __composite_values__(self):
return (self.a, self.b) + self.cd.__composite_values__()
def __eq__(self, other):
return (
isinstance(other, AB)
and self.a == other.a
and self.b == other.b
and self.cd == other.cd
)
def __ne__(self, other):
return not self.__eq__(other)
class CD(object):
def __init__(self, c, d):
self.c = c
self.d = d
def __composite_values__(self):
return (self.c, self.d)
def __eq__(self, other):
return (
isinstance(other, CD)
and self.c == other.c
and self.d == other.d
)
def __ne__(self, other):
return not self.__eq__(other)
class Thing(object):
def __init__(self, ab):
self.ab = ab
stuff = self.tables.stuff
mapper(
Thing,
stuff,
properties={
"ab": composite(
AB.generate, stuff.c.a, stuff.c.b, stuff.c.c, stuff.c.d
)
},
)
return Thing, AB, CD
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:58,代码来源:test_composites.py
示例11: setup_mappers
def setup_mappers(cls):
foo = cls.tables.foo
cls.Point = cls._type_fixture()
mapper(
FooWithEq,
foo,
properties={"data": composite(cls.Point, foo.c.x, foo.c.y)},
)
开发者ID:BY-jk,项目名称:sqlalchemy,代码行数:10,代码来源:test_mutable.py
示例12: assert_composite_conversion
def assert_composite_conversion(composite_class, composite_columns, graphene_field,
registry, **kwargs):
composite_column = composite(composite_class, *composite_columns,
doc='Custom Help Text', **kwargs)
graphene_type = convert_sqlalchemy_composite(composite_column, registry)
assert isinstance(graphene_type, graphene_field)
field = graphene_type.Field()
# SQLAlchemy currently does not persist the doc onto the column, even though
# the documentation says it does....
# assert field.description == 'Custom Help Text'
return field
开发者ID:marcosptf,项目名称:fedora,代码行数:11,代码来源:test_converter.py
示例13: InitMapper
def InitMapper( cls, metadata, Parameter, ParameterType ):
cls.__table__ = Table( cls.__tablename__, metadata,
Column('param_id', ForeignKey( Parameter.id ), index = True, primary_key = True ),
Column('x', Integer, nullable = False ),
Column('y', Integer, nullable = False ),
Column('z', Integer, nullable = False ))
cols = cls.__table__.c
mapper( cls, cls.__table__, inherits = Parameter, polymorphic_identity = ParameterType,
exclude_properties = [ 'param_id', 'x', 'y', 'z' ],
properties = {
'position': composite( Vector3D, cols.x, cols.y, cols.z ),
})
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:14,代码来源:AbsCoord.py
示例14: InitMapper
def InitMapper( cls, metadata, Parameter, ParameterType, Object ):
cls.__table__ = Table( cls.__tablename__, metadata,
Column('param_id', ForeignKey( Parameter.id ), index = True, primary_key = True ),
Column('x', Integer, default = 0, nullable = False ),
Column('y', Integer, default = 0, nullable = False ),
Column('z', Integer, default = 0, nullable = False ),
Column('parent_id', ForeignKey( Object.id ), nullable = True ))
cols = cls.__table__.c
mapper( cls, cls.__table__, inherits = Parameter, polymorphic_identity = ParameterType, properties = {
'parent' : relation( Object,
uselist = False ),
# Object position in 3D space
'vector': composite( Vector3D, cols.x, cols.y, cols.z ),
})
开发者ID:cahirwpz,项目名称:tpserver-py,代码行数:16,代码来源:RelCoord.py
示例15: i18nText
def i18nText(name, **kwargs):
"""
Translatable Text
:param name: Prefix of the Column
:param kwargs: Additional Parameters passed to Column Instance
:rtype: :class:`_i18nObject` as :class:`MutableObject(**environment.langs)`
"""
dwargs = dict(nullable=False, server_default='')
dwargs.update(kwargs)
columns = []
for lang in environment.langs:
columns.append(Column('%s_%s' % (name, lang), sqUnicodeText, **dwargs))
cls = composite(_i18nObject, *columns, comparator_factory=_i18nObjectComparator)
return cls
开发者ID:MartinMartimeo,项目名称:avalon,代码行数:20,代码来源:i18n.py
示例16: get_mapper_definition
def get_mapper_definition(newtable, columnname):
"""Given a Table object, return the Mapper definition for a TZAwareDateTime column"""
# cycle through columns, find the utcdate, tzname, tzoffset columns
column_utcdate, column_tzname, column_tzoffset = None, None, None
new_column_names = {'utcdate': '%s_%s' % (columnname, TZAwareDateTimeColumnNames[0]),
'tzname': '%s_%s' % (columnname, TZAwareDateTimeColumnNames[1]),
'tzoffset': '%s_%s' % (columnname, TZAwareDateTimeColumnNames[2])
}
for c in newtable.c:
assert isinstance(c, Column)
if c.key == new_column_names['utcdate']:
column_utcdate = c
elif c.key == new_column_names['tzname']:
column_tzname = c
elif c.key == new_column_names['tzoffset']:
column_tzoffset = c
if column_utcdate != column_tzname != column_tzoffset != None:
break
return composite(TZAwareDateTime,
column_utcdate,
column_tzname,
column_tzoffset)
开发者ID:tephyr,项目名称:sqlalchemy_tzaware,代码行数:24,代码来源:tzaware_datetime.py
示例17: len
"""Ensure that modifications to the enable_feed prop won't break things.
You cannot disable the last feed-enable file of a podcast episode.
"""
if (not on and self.media and self.media.podcast_id
and len([f for f in self.media.files if f.enable_feed]) == 1):
raise MediaException, ('Published podcast media requires '
'at least one file be feed-enabled.')
return on
mapper(MediaFile, media_files)
_media_mapper = mapper(Media, media, properties={
'status': status_column_property(media.c.status),
'author': composite(Author, media.c.author_name, media.c.author_email),
'rating': composite(Rating, media.c.rating_sum, media.c.rating_votes),
'files': relation(MediaFile, backref='media', order_by=media_files.c.position.asc(), passive_deletes=True),
'tags': relation(Tag, secondary=media_tags, backref='media', collection_class=TagList),
'topics': relation(Topic, secondary=media_topics, backref='media', collection_class=TopicList),
'comments': relation(Comment, secondary=media_comments, backref=backref('media', uselist=False),
extension=CommentTypeExtension('media'), single_parent=True, passive_deletes=True),
})
# Add comment_count, comment_count_published, ... column properties to Media
_media_mapper.add_properties(_properties_dict_from_labels(
comment_count_property('comment_count', media_comments),
comment_count_property('comment_count_published', media_comments, status_where(
comments.c.status, include='publish', exclude='trash'
)),
comment_count_property('comment_count_unreviewed', media_comments, status_where(
开发者ID:SergeyLashin,项目名称:mediacore,代码行数:31,代码来源:media.py
示例18: MediaFullText
else:
return helpers.url_for(controller='/media', action='serve',
slug=self.media.slug, id=self.id,
container=self.container, qualified=qualified)
class MediaFullText(object):
query = DBSession.query_property()
mapper(MediaFile, media_files)
mapper(MediaFullText, media_fulltext)
_media_mapper = mapper(Media, media, order_by=media.c.title, properties={
'fulltext': relation(MediaFullText, uselist=False, passive_deletes=True),
'author': composite(Author, media.c.author_name, media.c.author_email),
'files': relation(MediaFile, backref='media', order_by=media_files.c.type.asc(), passive_deletes=True),
'tags': relation(Tag, secondary=media_tags, backref=backref('media', lazy='dynamic', query_class=MediaQuery), collection_class=TagList, passive_deletes=True),
'categories': relation(Category, secondary=media_categories, backref=backref('media', lazy='dynamic', query_class=MediaQuery), collection_class=CategoryList, passive_deletes=True),
'comments': dynamic_loader(Comment, backref='media', query_class=CommentQuery, passive_deletes=True),
'comment_count': column_property(
sql.select([sql.func.count(comments.c.id)],
media.c.id == comments.c.media_id).label('comment_count'),
deferred=True),
'comment_count_published': column_property(
sql.select([sql.func.count(comments.c.id)],
sql.and_(comments.c.media_id == media.c.id,
comments.c.publishable == True)).label('comment_count_published'),
deferred=True),
})
开发者ID:RadioErewan,项目名称:mediacore,代码行数:31,代码来源:media.py
示例19: MarkdownColumn
def MarkdownColumn(name, deferred=False, group=None, **kwargs):
return composite(MarkdownComposite,
Column(name + '_text', UnicodeText, **kwargs),
Column(name + '_html', UnicodeText, **kwargs),
deferred=deferred, group=group or name
)
开发者ID:rautarchana9,项目名称:coaster,代码行数:6,代码来源:sqlalchemy.py
示例20: __repr__
query = DBSession.query_property(CommentQuery)
def __repr__(self):
return '<Comment: %s subject="%s">' % (self.id, self.subject)
def __unicode__(self):
return self.subject
@property
def type(self):
if self.media_id:
return 'media'
return None
def _get_parent(self):
return self.media or None
def _set_parent(self, parent):
self.media = parent
parent = property(_get_parent, _set_parent, None, """
The object this Comment belongs to, provided for convenience mostly.
If the parent has not been eagerloaded, a query is executed automatically.
""")
mapper(Comment, comments, order_by=comments.c.created_on, properties={
'author': composite(AuthorWithIP,
comments.c.author_name,
comments.c.author_email,
comments.c.author_ip),
})
开发者ID:RadioErewan,项目名称:mediacore,代码行数:30,代码来源:comments.py
注:本文中的sqlalchemy.orm.composite函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论