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


Python Box.by_uuid方法代码示例

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


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

示例1: edit_ipv6

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def edit_ipv6(self):
     ''' Add ipv6 addresses to a box (sorta edits the box object) '''
     form = Form(box_uuid="Select a box", ipv6="Please provide a list of IPv6 addresses")
     if form.validate(self.request.arguments):
         errors = []
         box = Box.by_uuid(self.get_argument('box_uuid'))
         if box is not None:
             ips_string = self.get_argument('ipv6').replace('\n', ',').lower()
             ips = filter(lambda char: char in "1234567890abcdef:,", ips_string).split(",")
             for ip in filter(lambda ip: 0 < len(ip), ips):
                 try:
                     box = Box.by_ip_address(ip)
                     if box is None:
                         addr = IpAddress(box_id=box.id, v6=ip)
                         dbsession.add(addr)
                     else:
                         errors.append(
                             "%s has already been assigned to %s." % (ip, box.name,)
                         )
                 except ValueError:
                     errors.append(
                         "'%s' is not a valid IPv6 address" % str(ip[:39])
                     )
             dbsession.flush()
         else:
             errors.append("Box does not exist")
         self.render("admin/view/game_objects.html", errors=errors)
     else:
         self.render("admin/view/game_objects.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:31,代码来源:AdminHandlers.py

示例2: add_source_code

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def add_source_code(self):
     form = Form(
         box_uuid="Please select a box",
         price="Please input a price for the source code",
         description="Please enter a description",
     )
     if form.validate(self.request.arguments):
         box = Box.by_uuid(self.get_argument('box_uuid'))
         if box is not None:
             if not 'source_archive' in self.request.files and 0 < len(self.request.files['source_archive']):
                 self.render('admin/upgrades/source_code_market.html',
                     errors=["No file data"]
                 )
             else:
                 try:
                     price = abs(int(self.get_argument('price', 'NaN')))
                     self.create_source_code(box, price)
                     self.render('admin/upgrades/source_code_market.html',
                         errors=None
                     )
                 except ValueError:
                     self.render('admin/upgrades/source_code_market.html',
                         errors=["Price must be an integer"]
                     )
         else:
             self.render('admin/upgrades/source_code_market.html',
                 errors=["The selected box does not exist"]
             )
     else:
         self.render('admin/upgrades/source_code_market.html',
             errors=form.errors
         )
开发者ID:mach327,项目名称:RootTheBox,代码行数:34,代码来源:AdminHandlers.py

示例3: create_flag

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def create_flag(self):
     ''' Create a flag '''
     form = Form(
         box_uuid="Please select a box",
         flag_name="Please enter a name",
         token="Please enter a token value",
         reward="Please enter a reward value",
         is_file="Please select a file setting",
         description="Please enter a flag description",
     )
     if form.validate(self.request.arguments):
         try:
             if Flag.by_name(self.get_argument('flag_name')) is not None:
                 self.render('admin/create/flag.html',
                     errors=["Name already exists"]
                 )
             elif Flag.by_token(self.get_argument('token')) is not None:
                 self.render('admin/create/flag.html',
                     errors=["Token value is not unique"]
                 )
             elif Box.by_uuid(self.get_argument('box_uuid')) is None:
                 self.render('admin/create/flag.html',
                     errors=["Box does not exist"]
                 )
             else:
                 reward = int(self.get_argument('reward', 'NaN'))
                 self.__mkflag__(reward)
                 self.redirect('/admin/view/game_objects')
         except ValueError:
             self.render('admin/create/flag.html',
                 errors=["Invalid reward value"]
             )
     else:
         self.render("admin/create/flag.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:36,代码来源:AdminHandlers.py

示例4: get

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.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')
开发者ID:lavalamp-,项目名称:RootTheBox,代码行数:15,代码来源:MissionsHandler.py

示例5: __mkflag__

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def __mkflag__(self, reward):
     ''' Creates a flag in the database '''
     box = Box.by_uuid(self.get_argument('box_uuid'))
     flag = Flag(
         name=unicode(self.get_argument('flag_name')),
         token=unicode(self.get_argument('token')),
         description=unicode(self.get_argument('description')),
         is_file=bool(self.get_argument('is_file', 'false') == 'true'),
         box_id=box.id,
         value=reward,
     )
     dbsession.add(flag)
     dbsession.flush()
开发者ID:mach327,项目名称:RootTheBox,代码行数:15,代码来源:AdminHandlers.py

示例6: post

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def post(self, *args, **kwargs):
     form = Form(box_uuid="Please select leaked code to buy")
     if form.validate(self.request.arguments):
         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"])
     else:
         self.render_page(form.errors)
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:17,代码来源:UpgradeHandlers.py

示例7: edit_boxes

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def edit_boxes(self):
     ''' Edit existing boxes in the database '''
     form = Form(
         uuid="Object not selected",
         name="Missing box name",
         corporation_uuid="Please select a corporation",
         description="Please enter a description",
         difficulty="Please enter a difficulty",
     )
     if form.validate(self.request.arguments):
         box = Box.by_uuid(self.get_argument('uuid'))
         if box is not None:
             errors = []
             if self.get_argument('name') != box.name:
                 if Box.by_name(self.get_argument('name')) is None:
                     logging.info("Updated box name %s -> %s" %
                         (box.name, self.get_argument('name'),)
                     )
                     box.name = unicode(self.get_argument('name'))
                 else:
                     errors.append("Box name already exists")
             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:
                 errors.append("Corporation does not exist")
             if self.get_argument('description') != box.description:
                 logging.info("Updated %s's description %s -> %s" %
                     (box.name, box.description, self.get_argument('description'),)
                 )
                 box.description = unicode(self.get_argument('description'))
             if self.get_argument('difficulty') != box.difficulty:
                 logging.info("Updated %s's difficulty %s -> %s" %
                     (box.name, box.difficulty, self.get_argument('difficulty'),)
                 )
                 box.difficulty = unicode(self.get_argument('difficulty'))
             dbsession.add(box)
             dbsession.flush()
             self.render("admin/view/game_objects.html", errors=errors)
         else:
             self.render("admin/view/game_objects.html",
                 errors=["Box does not exist"]
             )
     else:
         self.render("admin/view/game_objects.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:49,代码来源:AdminHandlers.py

示例8: box_level

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def box_level(self):
     ''' Changes a boxs level '''
     form = Form(box_uuid="No box selected", level_uuid="No level selected")
     if form.validate(self.request.arguments):
         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
             dbsession.add(box)
             dbsession.flush()
         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)
     else:
         self.render("admin/view/game_levels.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:20,代码来源:AdminHandlers.py

示例9: delete_source_code

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.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:
         source_code_uuid = box.source_code.uuid
         dbsession.delete(box.source_code)
         dbsession.flush()
         root = self.application.settings['source_code_market_dir']
         source_code_path = root + '/' + source_code_uuid
         logging.info("Delete souce code market file: %s (box: %s)" %
             (source_code_path, box.name,)
         )
         if os.path.exists(source_code_path):
             os.unlink(source_code_path)
         errors = None
     else:
         errors = ["Box does not exist, or contains no source code"]
     self.render('admin/upgrades/source_code_market.html', errors=errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:21,代码来源:AdminHandlers.py

示例10: get

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.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))
             self.set_header('Content-Disposition', 
                 'attachment; filename=%s' % box.source_code.file_name
             )
             self.write(src_data)
             self.finish()
         else:
             self.render('public/404.html')
     else:
         self.render('public/404.html')
开发者ID:brutalhonesty,项目名称:RootTheBox,代码行数:26,代码来源:UpgradeHandlers.py

示例11: edit_flags

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_uuid [as 别名]
 def edit_flags(self):
     ''' Super ugly code, yes - Edit existing flags in the database '''
     form = Form(
         uuid="Object not selected",
         name="Please enter a name",
         token="Please enter a toke value",
         description="Please provide a description",
         value="Please enter a reward value",
         box_uuid="Please select a box",
     )
     if form.validate(self.request.arguments):
         flag = Flag.by_uuid(self.get_argument('uuid'))
         if flag is not None:
             errors = []
             if flag.name != self.get_argument('name'):
                 if Flag.by_name(unicode(self.get_argument('name'))) is None:
                     logging.info("Updated flag name %s -> %s" %
                         (flag.name, self.get_argument('name'),)
                     )
                     flag.name = unicode(self.get_argument('name'))
                 else:
                     errors.append("Flag name already exists")
             if flag.token != self.get_argument('token'):
                 if Flag.by_token(unicode(self.get_argument('token'))) is None:
                     logging.info("Updated %s's token %s -> %s" %
                         (flag.name, flag.token, self.get_argument('token'),)
                     )
                     flag.token = unicode(self.get_argument('token'))
                 else:
                     errors.append("Token is not unique")
             if flag.description != self.get_argument('description'):
                 logging.info("Updated %s's description %s -> %s" %
                     (flag.name, flag.description, self.get_argument('description'),)
                 )
                 flag.description = unicode(self.get_argument('description'))
             try:
                 reward_value = int(self.get_argument('value'))
                 if reward_value != flag.value:
                     logging.info("Updated %s's value %d -> %d" %
                         (flag.name, flag.value, reward_value,)
                     )
                     flag.value = reward_value
             except ValueError:
                 errors.append("Invalid reward amount")
             box = Box.by_uuid(self.get_argument('box_uuid'))
             if box is not None and box.id != flag.box_id:
                 logging.info("Updated %s's box %d -> %d" %
                     (flag.name, flag.box_id, box.id)
                 )
                 flag.box_id = box.id
             elif box is None:
                 errors.append("Box does not exist")
             dbsession.add(flag)
             dbsession.flush()
             self.render("admin/view/game_objects.html", errors=errors)
         else:
             self.render("admin/view/game_objects.html",
                 errors=["Flag does not exist"]
             )
     else:
         self.render("admin/view/game_objects.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:63,代码来源:AdminHandlers.py


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