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


Python Box.Box类代码示例

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


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

示例1: create_box

def create_box(corp=None):
    if corp is None:
        corp = create_corp()
    game_level = GameLevel.all()[0]
    box = Box(corporation_id=corp.id, game_level_id=game_level.id)
    box.name = "TestBox"
    box.description = "Some description"
    box.difficuly = "Easy"
    corp.boxes.append(box)
    dbsession.add(box)
    dbsession.commit()
    return box, corp
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:12,代码来源:Helpers.py

示例2: edit_boxes

    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), ])
开发者ID:jinghli,项目名称:RootTheBox,代码行数:50,代码来源:AdminGameObjectHandlers.py

示例3: get

 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')
开发者ID:ElmoArmy,项目名称:RootTheBox,代码行数:25,代码来源:UpgradeHandlers.py

示例4: _mkflag

 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)
开发者ID:moloch--,项目名称:RootTheBox,代码行数:31,代码来源:AdminGameObjectHandlers.py

示例5: render_page

 def render_page(self, errors=None):
     ''' Addes extra params to render() '''
     user = self.get_current_user()
     boxes = filter(lambda box: box.source_code is not None, Box.all())
     self.render('upgrades/source_code_market.html',
         user=user, boxes=boxes, errors=errors
     )
开发者ID:ElmoArmy,项目名称:RootTheBox,代码行数:7,代码来源:UpgradeHandlers.py

示例6: render_page

 def render_page(self, flag, errors=[]):
     ''' Wrapper to .render() to avoid duplicate code '''
     user = self.get_current_user()
     box = Box.by_id(flag.box_id)
     self.render('missions/box.html',
                 box=box,
                 team=user.team,
                 errors=errors)
开发者ID:AnarKyx01,项目名称:RootTheBox,代码行数:8,代码来源:MissionsHandler.py

示例7: create_box

 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), ])
开发者ID:jinghli,项目名称:RootTheBox,代码行数:27,代码来源:AdminGameObjectHandlers.py

示例8: post

 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"])
开发者ID:moloch--,项目名称:RootTheBox,代码行数:11,代码来源:UpgradeHandlers.py

示例9: delete_source_code

 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)
开发者ID:jinghli,项目名称:RootTheBox,代码行数:11,代码来源:AdminGameHandlers.py

示例10: to_dict

 def to_dict(self):
     """ Returns public data as a dict """
     box = Box.by_id(self.box_id)
     return {
         "name": self.name,
         "uuid": self.uuid,
         "description": self.description,
         "capture_message": self.capture_message,
         "value": self.value,
         "box": box.uuid,
         "token": self.token,
     }
开发者ID:liorvh,项目名称:RootTheBox,代码行数:12,代码来源:Flag.py

示例11: get

 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)
开发者ID:jinghli,项目名称:RootTheBox,代码行数:12,代码来源:AdminGameHandlers.py

示例12: add_source_code

 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")
开发者ID:ossolution,项目名称:RootTheBox,代码行数:12,代码来源:AdminGameHandlers.py

示例13: del_box

 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."]
         )
开发者ID:AdaFormacion,项目名称:RootTheBox,代码行数:12,代码来源:AdminHandlers.py

示例14: get

 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)
开发者ID:ossolution,项目名称:RootTheBox,代码行数:12,代码来源:AdminGameHandlers.py

示例15: to_dict

 def to_dict(self):
     ''' Returns public data as a dict '''
     box = Box.by_id(self.box_id)
     return {
         'name': self.name,
         'uuid': self.uuid,
         'description': self.description,
         'capture_message': self.capture_message,
         'value': self.value,
         'box': box.uuid,
         'token': self.token,
     }
开发者ID:bincker,项目名称:RootTheBox,代码行数:12,代码来源:Flag.py


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