本文整理汇总了Python中package_relationship.PackageRelationship.reverse_type方法的典型用法代码示例。如果您正苦于以下问题:Python PackageRelationship.reverse_type方法的具体用法?Python PackageRelationship.reverse_type怎么用?Python PackageRelationship.reverse_type使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类package_relationship.PackageRelationship
的用法示例。
在下文中一共展示了PackageRelationship.reverse_type方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_relationships
# 需要导入模块: from package_relationship import PackageRelationship [as 别名]
# 或者: from package_relationship.PackageRelationship import reverse_type [as 别名]
def get_relationships(self, with_package=None, type=None, active=True,
direction='both'):
'''Returns relationships this package has.
Keeps stored type/ordering (not from pov of self).'''
assert direction in ('both', 'forward', 'reverse')
if with_package:
assert isinstance(with_package, Package)
from package_relationship import PackageRelationship
forward_filters = [PackageRelationship.subject==self]
reverse_filters = [PackageRelationship.object==self]
if with_package:
forward_filters.append(PackageRelationship.object==with_package)
reverse_filters.append(PackageRelationship.subject==with_package)
if active:
forward_filters.append(PackageRelationship.state==core.State.ACTIVE)
reverse_filters.append(PackageRelationship.state==core.State.ACTIVE)
if type:
forward_filters.append(PackageRelationship.type==type)
reverse_type = PackageRelationship.reverse_type(type)
reverse_filters.append(PackageRelationship.type==reverse_type)
q = meta.Session.query(PackageRelationship)
if direction == 'both':
q = q.filter(or_(
and_(*forward_filters),
and_(*reverse_filters),
))
elif direction == 'forward':
q = q.filter(and_(*forward_filters))
elif direction == 'reverse':
q = q.filter(and_(*reverse_filters))
return q.all()
示例2: get_relationships
# 需要导入模块: from package_relationship import PackageRelationship [as 别名]
# 或者: from package_relationship.PackageRelationship import reverse_type [as 别名]
def get_relationships(self, with_package=None, type=None, active=True, direction="both"):
"""Returns relationships this package has.
Keeps stored type/ordering (not from pov of self)."""
assert direction in ("both", "forward", "reverse")
if with_package:
assert isinstance(with_package, Package)
from package_relationship import PackageRelationship
forward_filters = [PackageRelationship.subject == self]
reverse_filters = [PackageRelationship.object == self]
if with_package:
forward_filters.append(PackageRelationship.object == with_package)
reverse_filters.append(PackageRelationship.subject == with_package)
if active:
forward_filters.append(PackageRelationship.state == State.ACTIVE)
reverse_filters.append(PackageRelationship.state == State.ACTIVE)
if type:
forward_filters.append(PackageRelationship.type == type)
reverse_type = PackageRelationship.reverse_type(type)
reverse_filters.append(PackageRelationship.type == reverse_type)
q = Session.query(PackageRelationship)
if direction == "both":
q = q.filter(or_(and_(*forward_filters), and_(*reverse_filters)))
elif direction == "forward":
q = q.filter(and_(*forward_filters))
elif direction == "reverse":
q = q.filter(and_(*reverse_filters))
return q.all()