本文整理汇总了Python中models.Box.Box.by_uuid方法的典型用法代码示例。如果您正苦于以下问题:Python Box.by_uuid方法的具体用法?Python Box.by_uuid怎么用?Python Box.by_uuid使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Box.Box
的用法示例。
在下文中一共展示了Box.by_uuid方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def get(self, *args, **kwargs):
''' Send file to user if their team owns it '''
uuid = self.get_argument('uuid', '')
box = Box.by_uuid(uuid)
if box is not None and box.source_code is not None:
user = self.get_current_user()
if box.source_code in user.team.purchased_source_code:
root = self.application.settings['source_code_market_dir']
src_file = open(root + '/' + box.source_code.uuid, 'r')
src_data = b64decode(src_file.read())
src_file.close()
content_type = guess_type(box.source_code.file_name)[0]
if content_type is None: content_type = 'unknown/data'
self.set_header('Content-Type', content_type)
self.set_header('Content-Length', len(src_data))
fname = filter(lambda char: char in self.goodchars, box.source_code.file_name)
self.set_header('Content-Disposition',
'attachment; filename=%s' % fname
)
self.write(src_data)
self.finish()
else:
self.render('public/404.html')
else:
self.render('public/404.html')
示例2: _mkflag
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def _mkflag(self, flag_type, is_file=False):
''' Creates the flag in the database '''
box = Box.by_uuid(self.get_argument('box_uuid', ''))
if box is None:
raise ValidationError('Box does not exist')
if is_file:
if not hasattr(self.request, 'files') or not 'flag' in self.request.files:
raise ValidationError('No file in request')
token = self.request.files['flag'][0]['body']
else:
token = self.get_argument('token', '')
name = self.get_argument('flag_name', '')
description = self.get_argument('description', '')
reward = self.get_argument('reward', '')
flag = Flag.create_flag(
flag_type, box, name, token, description, reward)
flag.capture_message = self.get_argument('capture_message', '')
flag.case_sensitive = self.get_argument('case-sensitive', 1)
lock = Flag.by_uuid(self.get_argument('lock_uuid', ''))
if lock:
flag.lock_id = lock.id
else:
flag.lock_id = None
self.add_attachments(flag)
self.dbsession.add(flag)
self.dbsession.commit()
choices = self.get_arguments('addmore[]', strip=True)
if choices is not None:
for item in choices:
FlagChoice.create_choice(flag, item)
self.redirect("/admin/view/game_objects#%s" % box.uuid)
示例3: post
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def post(self, *args, **kwargs):
box = Box.by_uuid(self.get_argument('box_uuid', ''))
if box is not None and box.source_code is not None:
user = self.get_current_user()
if box.source_code.price <= user.team.money:
self.purchase_code(box)
self.redirect("/source_code_market")
else:
self.render_page(["You cannot afford to purchase this code"])
else:
self.render_page(["Box does not exist"])
示例4: delete_source_code
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def delete_source_code(self):
''' Delete source code file '''
uuid = self.get_argument('box_uuid', '')
box = Box.by_uuid(uuid)
if box is not None and box.source_code is not None:
box.source_code.delete_data()
self.dbsession.delete(box.source_code)
self.dbsession.commit()
else:
raise ValidationError("Box/source code does not exist")
self.render('admin/upgrades/source_code_market.html', errors=None)
示例5: get
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def get(self, *args, **kwargs):
''' Download a Box's garbage file '''
box = Box.by_uuid(self.get_argument('uuid', ''))
if box is not None:
data = box.get_garbage_cfg()
self.set_header('Content-Type', 'text/plain')
self.set_header(
"Content-disposition", "attachment; filename=%s.garbage" % (
filter(lambda char: char in printable[:-38], box.name),
))
self.set_header('Content-Length', len(data))
self.write(data)
示例6: add_source_code
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def add_source_code(self):
box = Box.by_uuid(self.get_argument("box_uuid", ""))
if box is not None:
file_count = len(self.request.files["source_archive"])
if not "source_archive" in self.request.files and 0 < file_count:
raise ValidationError("No file data")
else:
price = self.get_argument("price", "")
self.create_source_code(box, price)
self.render("admin/upgrades/source_code_market.html", errors=None)
else:
raise ValidationError("The selected box does not exist")
示例7: del_box
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def del_box(self):
''' Delete a box '''
box = Box.by_uuid(self.get_argument('uuid', ''))
if box is not None:
logging.info("Delete box: %s" % box.name)
self.dbsession.delete(box)
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
else:
self.render('admin/view/game_objects.html',
errors=["Box does not exist in database."]
)
示例8: get
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def get(self, *args, **kwargs):
""" Download a Box's garbage file """
box = Box.by_uuid(self.get_argument("uuid", ""))
if box is not None:
data = box.get_garbage_cfg()
self.set_header("Content-Type", "text/plain")
self.set_header(
"Content-disposition",
"attachment; filename=%s.garbage" % (filter(lambda char: char in printable[:-38], box.name),),
)
self.set_header("Content-Length", len(data))
self.write(data)
示例9: add_source_code
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def add_source_code(self):
box = Box.by_uuid(self.get_argument('box_uuid'), '')
if box is not None:
file_count = len(self.request.files['source_archive'])
if not 'source_archive' in self.request.files and 0 < file_count:
raise ValidationError("No file data")
else:
price = self.get_argument('price', '')
self.create_source_code(box, price)
self.render('admin/upgrades/source_code_market.html',
errors=None)
else:
raise ValidationError("The selected box does not exist")
示例10: create_hint
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def create_hint(self):
''' Add hint to database '''
try:
box = Box.by_uuid(self.get_argument('box_uuid', ''))
if box is None:
raise ValidationError("Box does not exist")
hint = Hint(box_id=box.id)
hint.price = self.get_argument('price', '')
hint.description = self.get_argument('description', '')
self.dbsession.add(hint)
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
except ValidationError as error:
self.render('admin/create/hint.html', errors=[str(error), ])
示例11: get
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def get(self, *args, **kwargs):
'''
Renders the box details page.
'''
uuid = self.get_argument('uuid', '')
box = Box.by_uuid(uuid)
if box is not None:
user = self.get_current_user()
self.render('missions/box.html',
box=box,
team=user.team,
errors=[])
else:
self.render('public/404.html')
示例12: edit_boxes
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box 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), ])
示例13: box_level
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def box_level(self):
''' Changes a boxs level '''
errors = []
box = Box.by_uuid(self.get_argument('box_uuid'))
level = GameLevel.by_uuid(self.get_argument('level_uuid'))
if box is not None and level is not None:
box.game_level_id = level.id
self.dbsession.add(box)
self.dbsession.commit()
elif box is None:
errors.append("Box does not exist")
elif level is None:
errors.append("GameLevel does not exist")
self.render("admin/view/game_levels.html", errors=errors)
示例14: edit_flags
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def edit_flags(self):
''' Edit existing flags in the database '''
try:
flag = Flag.by_uuid(self.get_argument('uuid', ''))
if flag is None:
raise ValidationError("Flag does not exist")
# Name
name = self.get_argument('name', '')
if flag.name != name:
logging.info("Updated flag name %s -> %s" % (
flag.name, name,
))
flag.name = name
token = self.get_argument('token', '')
if flag.token != token:
flag.token = token
# Description
description = self.get_argument('description', '')
if flag._description != description:
logging.info("Updated %s's description %s -> %s" % (
flag.name, flag._description, description,
))
flag.description = description
# Value
flag.value = self.get_argument('value', '')
flag.original_value = self.get_argument('value', '')
flag.capture_message = self.get_argument('capture_message', '')
flag.case_sensitive = self.get_argument('case-sensitive', 1)
# Dependency Lock
lock = Flag.by_uuid(self.get_argument('lock_uuid', ''))
if lock:
flag.lock_id = lock.id
else:
flag.lock_id = None
box = Box.by_uuid(self.get_argument('box_uuid', ''))
if box is not None and flag not in box.flags:
logging.info("Updated %s's box %d -> %d" % (
flag.name, flag.box_id, box.id
))
flag.box_id = box.id
elif box is None:
raise ValidationError("Box does not exist")
self.dbsession.add(flag)
self.dbsession.commit()
if flag.type == FLAG_CHOICE:
self.edit_choices(flag, self.request.arguments)
self.redirect("/admin/view/game_objects#%s" % box.uuid)
except ValidationError as error:
self.render("admin/view/game_objects.html", errors=["%s" % error])
示例15: create_hint
# 需要导入模块: from models.Box import Box [as 别名]
# 或者: from models.Box.Box import by_uuid [as 别名]
def create_hint(self):
''' Add hint to database '''
box = Box.by_uuid(self.get_argument('box_uuid', ''))
if box is not None:
try:
hint = Hint(box_id=box.id)
hint.price = self.get_argument('price', '')
hint.description = self.get_argument('description', '')
self.dbsession.add(hint)
self.dbsession.commit()
self.redirect('/admin/view/game_objects')
except ValueError as error:
self.render('admin/create/hint.html', errors=["%s" % error])
else:
self.render('admin/create/hint.html', errors=["Box does not exist"])