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


Python Team.by_name方法代码示例

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


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

示例1: create_team

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import by_name [as 别名]
def create_team(name, motto):
    if Team.by_name(name) is not None:
        logging.info("Team with name '%s' already exists, skipping" % (name))
        return Team.by_name(name)
    logging.info("Create Team: %s" % name)
    team = Team(
        name=unicode(name[:16]),
        motto=unicode(motto[:32]),
    )
    level_0 = GameLevel.all()[0]
    team.game_levels.append(level_0)
    dbsession.add(team)
    dbsession.flush()
    return team
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:16,代码来源:helpers.py

示例2: transfer

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import by_name [as 别名]
 def transfer(self):
     user = self.get_current_user()
     source = Team.by_name(self.get_argument('source', ''))
     destination = Team.by_name(self.get_argument('destination', ''))
     try:
         amount = int(self.get_argument('amount', 0))
     except ValueError:
         amount = 0
     victim_user = User.by_handle(self.get_argument('user', None))
     password = self.get_argument('password', '')
     user = self.get_current_user()
     # Validate what we got from the user
     if source is None:
         self.write({"error": "Source account does not exist"})
     elif destination is None:
         self.write({"error": "Destination account does not exist"})
     elif victim_user is None or not victim_user in source.members:
         self.write({"error": "User is not authorized for this account"})
     elif victim_user in user.team.members:
         self.write({"error": "You cannot steal from your own team"})
     elif not 0 < amount <= source.money:
         self.write({
             "error": 
             "Invalid transfer amount; must be greater than 0 and less than $%d" % source.money
         })
     elif destination == source:
         self.write({
             "error": "Source and destination are the same account"
         })
     elif victim_user.validate_password(password):
         logging.info("Transfer request from %s to %s for $%d by %s" % (
             source.name, destination.name, amount, user.handle
         ))
         xfer = self.theft(victim_user, destination, amount)
         self.write({
             "success":
             "Confirmed transfer to '%s' for $%d (after 15%s commission)" % (destination.name, xfer, '%',)
         })
     else:
         self.write({"error": "Incorrect password for account, try again"})
     self.finish()
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:43,代码来源:UpgradeHandlers.py

示例3: info

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import by_name [as 别名]
 def info(self):
     team_name = self.get_argument('account')
     team = Team.by_name(team_name)
     if team is not None:
         self.write({
             'name': team.name,
             'balance': team.money,
             'users': [user.handle for user in team.members]
         })
     else:
         self.write({'error': 'Account does not exist'})
     self.finish()
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:14,代码来源:UpgradeHandlers.py

示例4: validate_team

# 需要导入模块: from models import Team [as 别名]
# 或者: from models.Team import by_name [as 别名]
 def validate_team(self):
     ''' Validate team arguments '''
     errors = []
     team = Team.by_uuid(self.get_argument('team', ''))
     if team is None:
         if self.config.public_teams:
             team_name = self.get_argument('team_name', '')
             motto = self.get_argument('motto', '')
             if 2 < len(team_name) < 15:
                 if Team.by_name(team_name) is not None:
                     errors.append("A team with that name already exists")
             else:
                 errors.append('Team name must be 3 - 15 characters')
             if not 2 < len(motto) < 255:
                 errors.append('Team motto must be more than 3 characters')  
         else:
             errors.append("You must select a team to join")
     else:
         if not len(team.members) < self.config.max_team_size:
             errors.append("This team is full, please select another to join.")
     return errors
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:23,代码来源:PublicHandlers.py


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