當前位置: 首頁>>代碼示例>>Python>>正文


Python Session.object_session方法代碼示例

本文整理匯總了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))
開發者ID:giomasce,項目名稱:liturgy,代碼行數:49,代碼來源:liturgy.py


注:本文中的database.Session.object_session方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。