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


Python Box.by_name方法代码示例

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


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

示例1: create_box

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_name [as 别名]
 def create_box(self):
     ''' Create a box object '''
     form = Form(
         box_name="Enter a box name",
         description="Enter a description",
         difficulty="Select a difficulty",
         corporation_uuid="Please select a corporation",
         game_level="Please select a game level",
     )
     if form.validate(self.request.arguments):
         try:
             game_level = int(self.get_argument('game_level'))
             corp_uuid = self.get_argument('corporation_uuid')
             if Box.by_name(self.get_argument('box_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:
                 self.__mkbox__()
                 self.redirect('/admin/view/game_objects')
         except ValueError:
             self.render('admin/view/create.html',
                 errors=["Invalid level number"]
             )
     else:
         self.render("admin/create/box.html", errors=form.errors)
开发者ID:mach327,项目名称:RootTheBox,代码行数:36,代码来源:AdminHandlers.py

示例2: create_box

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_name [as 别名]
def create_box(name, corporation, difficulty, game_level, description,
        ipv4_addresses=[], ipv6_addresses=[], avatar=None):
    if Box.by_name(name) is not None:
        logging.info("Box with name '%s' already exists, skipping" % (name))
        return Box.by_name(name)
    logging.info("Create Box: %s" % name)
    if isinstance(game_level, int):
        game_level = GameLevel.by_number(game_level)
    box = Box(
        name=unicode(name[:16]),
        corporation_id=corporation.id,
        difficulty=unicode(difficulty[:16]),
        game_level_id=game_level.id,
        _description=unicode(description[:1024]),
    )
    dbsession.add(box)
    dbsession.flush()
    if avatar is not None and os.path.exists(avatar):
        set_avatar(box, avatar)
    for ip_address in ipv4_addresses:
        __mkipv4__(box, ip_address)
    for ip_address in ipv6_addresses:
        __mkipv6__(box, ip_address)
    return box
开发者ID:CRYPTOlab,项目名称:RootTheBox,代码行数:26,代码来源:helpers.py

示例3: edit_boxes

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_name [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

示例4: interrogation_response

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_name [as 别名]
 def interrogation_response(self, msg):
     """ Steps 3 and 4; validate repsonses """
     logging.debug("Recieved interrogate response, validating ...")
     response_xid = msg["rxid"]
     user = User.by_handle(msg["handle"])
     box = Box.by_name(msg["box_name"])
     if self.config.whitelist_box_ips and self.remote_ip not in box.ips:
         self.send_error("Invalid remote IP for this box")
     elif user is None or user.has_permission(ADMIN_PERMISSION):
         self.send_error("User does not exist")
     elif box is None:
         self.send_error("Box does not exist")
     elif not self.is_valid_xid(box, response_xid):
         self.send_error("Invalid xid response")
     else:
         self.team_name = user.team.name
         self.team_uuid = user.team.uuid
         self.box_uuid = box.uuid
         self.box_name = box.name
         self.add_to_botnet()
开发者ID:harite,项目名称:RootTheBox,代码行数:22,代码来源:BotnetHandlers.py

示例5: interrogation_response

# 需要导入模块: from models import Box [as 别名]
# 或者: from models.Box import by_name [as 别名]
 def interrogation_response(self, msg):
     ''' Steps 3 and 4; validate repsonses '''
     logging.debug("Received interrogate response, validating ...")
     response_xid = msg['response_xid']
     user = User.by_handle(msg['handle'])
     box = Box.by_name(msg['box_name'])
     if self.config.whitelist_box_ips and self.remote_ip not in box.ips:
         self.send_error("Invalid remote IP for this box")
     elif user is None or user.is_admin():
         self.send_error("User does not exist")
     elif box is None:
         self.send_error("Box does not exist")
     elif not self.is_valid_xid(box, response_xid):
         self.send_error("Invalid xid response")
     else:
         self.team_name = user.team.name
         self.team_uuid = user.team.uuid
         self.box_uuid = box.uuid
         self.box_name = box.name
         self.add_to_botnet(user)
开发者ID:moloch--,项目名称:RootTheBox,代码行数:22,代码来源:BotnetHandlers.py


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