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


Python Session.add_all方法代码示例

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


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

示例1: addLeagueMatches

# 需要导入模块: from springgrid.lib.base import Session [as 别名]
# 或者: from springgrid.lib.base.Session import add_all [as 别名]
def addLeagueMatches(league, matchRequestQueue, matchResults):
    ais = Session.query(AI).join(LeagueAI).filter(LeagueAI.league_id ==\
                league.league_id).all()
                
    map = Session.query(Map).filter(Map.map_id == league.map_id).first()
    mod = Session.query(Mod).filter(Mod.mod_id == league.mod_id).first()
               
    playAgainstSelf = league.play_against_self
    if league.side_modes == "xvsy":
        sides = [int(i) for i in league.sides.split("vs")]
    else:
        sides = [int(league.sides)]
    
    matchRequests = []    
    for i, ai0 in enumerate(ais[:-1]):
        for j, ai1 in enumerate(ais[i:]):
            if not playAgainstSelf and ai0.ai_id == ai1.ai_id:
                continue
            first = Session.query(ModSide).filter(ModSide.mod_side_id == sides[0]).first()
            if len(sides) == 2:
                second = Session.query(ModSide).filter(ModSide.mod_side_id == sides[1]).first()
                allSides = [(first, second), (second, first)]
            else:
                allSides = [(first, first)]
            for firstSide, secondSide in allSides:
                for k in xrange(league.matches_per_ai_pair):
                    matchRequest = MatchRequest(ai0, ai1, map, mod,\
                        league.speed, league.soft_timeout, league.hard_timeout,\
                        firstSide, secondSide, league.league_id)
                    matchRequests.append(matchRequest)                        
    #save all matches to the database
    Session.add_all(matchRequests)
    Session.commit()
开发者ID:gajop,项目名称:springgrid,代码行数:35,代码来源:matchscheduler.py

示例2: add

# 需要导入模块: from springgrid.lib.base import Session [as 别名]
# 或者: from springgrid.lib.base.Session import add_all [as 别名]
    def add(self):
        if not roles.isInRole(roles.leagueadmin):
            c.message = "You must be logged in as a leagueadmin"
            return render('genericmessage.html')

        leagueName = self.form_result["leagueName"]
        modId = self.form_result["modId"]
        mapId = self.form_result["mapId"]
        speed = self.form_result["speed"]
        softtimeout = self.form_result["softtimeout"]
        hardtimeout = self.form_result["hardtimeout"]
        nummatchesperaipair = self.form_result["nummatchesperaipair"]
        sides = self.form_result["sides"]
        sidemodes = self.form_result["sidemodes"]
        playagainstself = self.form_result["playagainstself"]
        account = Session.query(Account).filter(Account.username == session['user']).first()
        ais = []
        for i in range(Session.query(AI).count()):
            ai_i = 'ai_checkbox_' + str(i)
            if (self.form_result.has_key(ai_i)):
                ais.append(i)

        league = League(leagueName, account, modId, mapId,
                nummatchesperaipair, speed, softtimeout, hardtimeout,
                sides, sidemodes, playagainstself)
        leagueais = [LeagueAI(ai, league) for ai in ais]
        Session.add(league)
        Session.add_all(leagueais)        
        
        matchrequests = Session.query(MatchRequest).filter(MatchRequest.league_id ==\
                league.league_id)         
        matchresults = [req for req in matchrequests if req.matchresult != None] 
        
        matchscheduler.addLeagueMatches(league, matchrequests, matchresults)
        Session.flush()
        Session.commit()
        
        redirect(url(controller='league', action='view', id=league.league_id))
开发者ID:gajop,项目名称:springgrid,代码行数:40,代码来源:league.py


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