本文整理汇总了Python中models.Corporation.Corporation.by_uuid方法的典型用法代码示例。如果您正苦于以下问题:Python Corporation.by_uuid方法的具体用法?Python Corporation.by_uuid怎么用?Python Corporation.by_uuid使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Corporation.Corporation
的用法示例。
在下文中一共展示了Corporation.by_uuid方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: create_box
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [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: del_corp
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [as 别名]
def del_corp(self):
''' Delete a corporation '''
corp = Corporation.by_uuid(self.get_argument('uuid', ''))
if corp is not None:
logging.info("Delete corporation: %s" % corp.name)
self.dbsession.delete(corp)
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
else:
self.render('admin/view/game_objects.html',
errors=["Corporation does not exist in database."]
)
示例3: _make_box
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [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
示例4: edit_boxes
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [as 别名]
def edit_boxes(self):
'''
Edit existing boxes in the database, and log the changes
'''
try:
box = Box.by_uuid(self.get_argument('uuid', ''))
if box is None:
raise ValidationError("Box does not exist")
# Name
name = self.get_argument('name', '')
if name != box.name:
if Box.by_name(name) is None:
logging.info("Updated box name %s -> %s" % (
box.name, name,
))
box.name = name
else:
raise ValidationError("Box name already exists")
# Corporation
corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
if corp is not None and corp.id != box.corporation_id:
logging.info("Updated %s's corporation %s -> %s" % (
box.name, box.corporation_id, corp.id,
))
box.corporation_id = corp.id
elif corp is None:
raise ValidationError("Corporation does not exist")
# Description
description = self.get_argument('description', '')
if description != box._description:
logging.info("Updated %s's description %s -> %s" % (
box.name, box.description, description,
))
box.description = description
# Difficulty
difficulty = self.get_argument('difficulty', '')
if difficulty != box.difficulty:
logging.info("Updated %s's difficulty %s -> %s" % (
box.name, box.difficulty, difficulty,
))
box.difficulty = difficulty
# Avatar
if '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")
except ValidationError as error:
self.render("admin/view/game_objects.html", errors=[str(error), ])
示例5: create_box
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [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), ])
示例6: edit_corporations
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [as 别名]
def edit_corporations(self):
''' Updates corporation object in the database '''
try:
corp = Corporation.by_uuid(self.get_argument('uuid', ''))
if corp is None:
raise ValidationError("Corporation does not exist")
name = self.get_argument('name', '')
if name != corp.name:
logging.info("Updated corporation name %s -> %s" % (
corp.name, name
))
corp.name = name
self.dbsession.add(corp)
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
except ValidationError as error:
self.render("admin/view/game_objects.html", errors=[str(error), ])
示例7: create_box
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [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])
示例8: edit_boxes
# 需要导入模块: from models.Corporation import Corporation [as 别名]
# 或者: from models.Corporation.Corporation import by_uuid [as 别名]
def edit_boxes(self):
'''
Edit existing boxes in the database, and log the changes
'''
try:
box = Box.by_uuid(self.get_argument('uuid', ''))
if box is None:
raise ValidationError("Box does not exist")
# Name
name = self.get_argument('name', '')
if name != box.name:
if Box.by_name(name) is None:
logging.info("Updated box name %s -> %s" % (
box.name, name,
))
box.name = name
else:
raise ValidationError("Box name already exists")
# Corporation
corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
if corp is not None and corp.id != box.corporation_id:
logging.info("Updated %s's corporation %s -> %s" % (
box.name, box.corporation_id, corp.id,
))
box.corporation_id = corp.id
elif corp is None:
raise ValidationError("Corporation does not exist")
# Category
cat = Category.by_uuid(self.get_argument('category_uuid'))
if cat is not None and cat.id != box.category_id:
logging.info("Updated %s's category %s -> %s" % (
box.name, box.category_id, cat.id,
))
box.category_id = cat.id
elif cat is None and cat != box.category_id:
logging.info("Updated %s's category %s -> None" % (
box.name, box.category_id,
))
box.category_id = None
# System Type
ostype = self.get_argument('operating_system')
if ostype is not None and ostype != box.operating_system:
logging.info("Updated %s's system type %s -> %s" % (
box.name, box.operating_system, ostype,
))
box.operating_system = ostype
# Description
description = self.get_argument('description', '')
if description != box._description:
logging.info("Updated %s's description %s -> %s" % (
box.name, box.description, description,
))
box.description = description
# Difficulty
difficulty = self.get_argument('difficulty', '')
if difficulty != box.difficulty:
logging.info("Updated %s's difficulty %s -> %s" % (
box.name, box.difficulty, difficulty,
))
box.difficulty = difficulty
# Flag submission type
flag_submission_type = self.get_argument('flag_submission_type', '')
if flag_submission_type is not None and flag_submission_type != box.flag_submission_type:
logging.info("Updated %s's flag submission type %s -> %s" % (
box.name, box.flag_submission_type, flag_submission_type
))
box.flag_submission_type = flag_submission_type
# Avatar
avatar_select = self.get_argument('box_avatar_select', '')
if avatar_select and len(avatar_select) > 0:
box._avatar = avatar_select
elif '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/view/game_objects.html", errors=[str(error), ])