當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。