本文整理汇总了Python中models.GameLevel.GameLevel.by_number方法的典型用法代码示例。如果您正苦于以下问题:Python GameLevel.by_number方法的具体用法?Python GameLevel.by_number怎么用?Python GameLevel.by_number使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.GameLevel.GameLevel
的用法示例。
在下文中一共展示了GameLevel.by_number方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_box
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [as 别名]
def create_box(self):
''' Create a box object '''
try:
game_level = self.get_argument('game_level', '')
corp_uuid = self.get_argument('corporation_uuid', '')
if Box.by_name(self.get_argument('name', '')) is not None:
raise ValidationError("Box name already exists")
elif Corporation.by_uuid(corp_uuid) is None:
raise ValidationError("Corporation does not exist")
elif GameLevel.by_number(game_level) is None:
raise ValidationError("Game level does not exist")
else:
corp = Corporation.by_uuid(corp_uuid)
level = GameLevel.by_number(game_level)
box = Box(corporation_id=corp.id, game_level_id=level.id)
box.name = self.get_argument('name', '')
box.description = self.get_argument('description', '')
box.autoformat = self.get_argument('autoformat', '') == 'true'
box.difficulty = self.get_argument('difficulty', '')
self.dbsession.add(box)
self.dbsession.commit()
if hasattr(self.request, 'files') and 'avatar' in self.request.files:
box.avatar = self.request.files['avatar'][0]['body']
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
except ValidationError as error:
self.render('admin/create/box.html', errors=[str(error), ])
示例2: edit_game_level
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [as 别名]
def edit_game_level(self):
''' Update game level objects '''
errors = []
level = GameLevel.by_uuid(self.get_argument('uuid'))
try:
new_number = int(self.get_argument('number', ''))
new_buyout = int(self.get_argument('buyout', ''))
if level.number != new_number and GameLevel.by_number(new_number) is None:
level.number = new_number
self.dbsession.add(level)
# Fix the linked-list
game_levels = sorted(GameLevel.all())
index = 0
for game_level in game_levels[:-1]:
game_level.next_level_id = game_levels[index + 1].id
self.dbsession.add(game_level)
index += 1
game_levels[0].number = 0
self.dbsession.add(game_levels[0])
game_levels[-1].next_level_id = None
self.dbsession.add(game_levels[-1])
if GameLevel.by_number(new_number) is not None:
errors.append("GameLevel number is not unique")
if level.buyout != new_buyout:
level.buyout = new_buyout
self.dbsession.add(level)
self.dbsession.commit()
except ValueError:
errors.append("That was not a number ...")
self.render("admin/view/game_levels.html", errors=errors)
示例3: create_team
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [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), ])
示例4: create_team
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [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: _make_box
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [as 别名]
def _make_box(self, level_number):
''' Creates a box in the database '''
corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
level = GameLevel.by_number(level_number)
box = Box(corporation_id=corp.id, game_level_id=level.id)
box.name = self.get_argument('name', '')
box.description = self.get_argument('description', '')
box.autoformat = self.get_argument('autoformat', '') == 'true'
box.difficulty = self.get_argument('difficulty', '')
self.dbsession.add(box)
self.dbsession.commit()
if 'avatar' in self.request.files:
box.avatar = self.request.files['avatar'][0]['body']
return box
示例6: create_box
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [as 别名]
def create_box(self):
''' Create a box object '''
try:
game_level = self.get_argument('game_level', '')
corp_uuid = self.get_argument('corporation_uuid', '')
if Box.by_name(self.get_argument('name', '')) is not None:
raise ValidationError("Box name already exists")
elif Corporation.by_uuid(corp_uuid) is None:
raise ValidationError("Corporation does not exist")
elif GameLevel.by_number(game_level) is None:
raise ValidationError("Game level does not exist")
else:
corp = Corporation.by_uuid(corp_uuid)
level = GameLevel.by_number(game_level)
box = Box(corporation_id=corp.id, game_level_id=level.id)
box.name = self.get_argument('name', '')
box.description = self.get_argument('description', '')
box.flag_submission_type = FlagsSubmissionType[self.get_argument('flag_submission_type','')]
box.difficulty = self.get_argument('difficulty', '')
box.operating_system = self.get_argument('operating_system', '?')
cat = Category.by_uuid(self.get_argument('category_uuid', ''))
if cat is not None:
box.category_id = cat.id
else:
box.category_id = None
# Avatar
avatar_select = self.get_argument('box_avatar_select', '')
if avatar_select and len(avatar_select) > 0:
box._avatar = avatar_select
elif hasattr(self.request, 'files') and 'avatar' in self.request.files:
box.avatar = self.request.files['avatar'][0]['body']
self.dbsession.add(box)
self.dbsession.commit()
self.redirect("/admin/view/game_objects#%s" % box.uuid)
except ValidationError as error:
self.render('admin/create/box.html', errors=[str(error), ])
示例7: create_game_level
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [as 别名]
def create_game_level(self):
''' Creates a game level '''
try:
lvl = self.get_argument('level_number', '')
game_level = abs(int(lvl)) if lvl.isdigit() else 0
if GameLevel.by_number(game_level) is not None:
self.render('admin/create/game_level.html',
errors=["Game level number must be unique"]
)
else:
self._make_level(game_level)
self.redirect('/admin/view/game_levels')
except ValueError:
self.render('admin/create/game_level.html',
errors=["Invalid level number"]
)
示例8: create_box
# 需要导入模块: from models.GameLevel import GameLevel [as 别名]
# 或者: from models.GameLevel.GameLevel import by_number [as 别名]
def create_box(self):
''' Create a box object '''
try:
lvl = self.get_argument('game_level', '')
game_level = abs(int(lvl)) if lvl.isdigit() else 0
corp_uuid = self.get_argument('corporation_uuid', '')
if Box.by_name(self.get_argument('name', '')) is not None:
self.render("admin/create/box.html",
errors=["Box name already exists"]
)
elif Corporation.by_uuid(corp_uuid) is None:
self.render("admin/create/box.html", errors=["Corporation does not exist"])
elif GameLevel.by_number(game_level) is None:
self.render("admin/create/box.html", errors=["Game level does not exist"])
else:
box = self._make_box(game_level)
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
except ValueError as error:
self.render('admin/create/box.html', errors=["%s" % error])