本文整理汇总了Python中database.Session.object_session方法的典型用法代码示例。如果您正苦于以下问题:Python Session.object_session方法的具体用法?Python Session.object_session怎么用?Python Session.object_session使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类database.Session
的用法示例。
在下文中一共展示了Session.object_session方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_masses
# 需要导入模块: from database import Session [as 别名]
# 或者: from database.Session import object_session [as 别名]
def get_masses(self, strict=True):
for i in xrange(len(self.competitors)):
priority = self.competitors[i][0]
competitor = self.competitors[i][1]
# If there are conflicts and we are in strict mode, invoke
# the conflict resolution logic
if strict:
choices = filter(lambda x: x[0] == priority, self.competitors)
assert self.competitors[i:i+len(choices)] == choices
if len(choices) > 1:
self.competitors[i:i+len(choices)] = solve_conflict(self, choices)
priority = self.competitors[i][0]
competitor = self.competitors[i][1]
session = Session.object_session(competitor)
# Check whethere there are masses today (there aren't only
# on Holy Saturday)
if competitor.no_masses:
raise SelectingMassException("No masses for today")
# Check if there is at least a mass in the competitor
if session.query(Mass).filter(Mass.event == competitor).count() == 0:
continue
# Select compatible masses
masses = session.query(Mass).filter(Mass.event == competitor). \
filter(or_(Mass.digit == '*', Mass.digit == self.digit)). \
filter(or_(Mass.letter == '*', Mass.letter == self.letter)).order_by(Mass.order.asc()).all()
# Check that the filtered masses are valid
if strict:
order_nums = map(lambda x: x.order, masses)
if order_nums != range(len(order_nums)):
raise SelectingMassException("Wrong masses structure in LiturgyDate %s" % (self))
# If there is at least one mass, emit all of them
if len(masses) > 0:
return masses
# If not, some masses are missing and we report
# accordingly
else:
raise SelectingMassException("Masses missing in LiturgyDate %s" % (self))
raise SelectingMassException("No masses reachable for LiturgyDate %s" % (self))