本文整理汇总了Python中models.Team.Team.by_name方法的典型用法代码示例。如果您正苦于以下问题:Python Team.by_name方法的具体用法?Python Team.by_name怎么用?Python Team.by_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Team.Team
的用法示例。
在下文中一共展示了Team.by_name方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_team
# 需要导入模块: from models.Team import Team [as 别名]
# 或者: from models.Team.Team import by_name [as 别名]
def create_team(self):
''' Admins can create teams manually '''
try:
name = self.get_argument('team_name', '')
if Team.by_name(name) is not None:
raise ValidationError("Team already exists")
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
if not self.config.banking:
team.money = 0
level_0 = GameLevel.by_number(0)
if not level_0:
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
self.dbsession.add(team)
self.dbsession.commit()
# Avatar
avatar_select = self.get_argument('team_avatar_select', '')
if avatar_select and len(avatar_select) > 0:
team._avatar = avatar_select
elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
team.avatar = self.request.files['avatar'][0]['body']
self.dbsession.add(team)
self.dbsession.commit()
self.redirect('/admin/users')
except ValidationError as error:
self.render("admin/create/team.html", errors=[str(error), ])
示例2: transfer
# 需要导入模块: from models.Team import Team [as 别名]
# 或者: from models.Team.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 victim_user not 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_bank_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, password)
self.write({
"success":
"Confirmed transfer to '%s' for $%d (15%s commission)" % (
destination.name, xfer, '%'
)
})
else:
self.write({"error": "Incorrect password for account, try again"})
self.finish()
示例3: info
# 需要导入模块: from models.Team import Team [as 别名]
# 或者: from models.Team.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()
示例4: create_team
# 需要导入模块: from models.Team import Team [as 别名]
# 或者: from models.Team.Team import by_name [as 别名]
def create_team(self):
''' Create a new team '''
if not self.config.teams:
team = Team.by_name(self.get_argument('handle', ''))
if team is None:
team = Team()
team.name = self.get_argument('handle', '')
else:
logging.info("Team %s already exists - Player Mode: reset team." % team.name)
team.flags = []
team.hints = []
team.boxes = []
team.items = []
team.game_levels = []
team.purchased_source_code = []
team.motto = self.get_argument('motto', '')
if self.config.banking:
team.money = self.config.starting_team_money
else:
team.money = 0
level_0 = GameLevel.by_number(0)
if not level_0:
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
return team
elif self.config.public_teams:
if Team.by_name(self.get_argument('team_name', '')) is not None:
raise ValidationError("This team name is already registered. Use team code to join that team.")
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
if not self.config.banking:
team.money = 0
level_0 = GameLevel.by_number(0)
if not level_0:
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
return team
else:
raise ValidationError("Public teams are not enabled")
示例5: create_team
# 需要导入模块: from models.Team import Team [as 别名]
# 或者: from models.Team.Team import by_name [as 别名]
def create_team(self):
''' Admins can create teams manually '''
try:
name = self.get_argument('team_name', '')
motto = self.get_argument('motto', '')
if Team.by_name(name) is not None:
raise ValidationError("Team already exists")
team = Team(name=name, motto=motto)
self.dbsession.add(team)
self.dbsession.commit()
self.redirect('/admin/users')
except ValidationError as error:
self.render("admin/create/team.html", errors=[str(error), ])
示例6: create_team
# 需要导入模块: from models.Team import Team [as 别名]
# 或者: from models.Team.Team import by_name [as 别名]
def create_team(self):
''' Create a new team '''
if self.config.public_teams:
if Team.by_name(self.get_argument('team_name', '')) is not None:
raise ValidationError("This team name is already registered")
team = Team()
team.name = self.get_argument('team_name', '')
team.motto = self.get_argument('motto', '')
level_0 = GameLevel.all()[0]
team.game_levels.append(level_0)
return team
else:
raise ValidationError("Public teams are not enabled")