• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python Box.Box类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: 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:sigma-random,项目名称:RootTheBox,代码行数:13,代码来源:AdminGameHandlers.py


示例17: to_dict

 def to_dict(self):
     flag = Flag.by_id(self.flag_id)
     if flag:
         flag_uuid = flag.uuid
     else:
         flag_uuid = ""
     return {
         'price': str(self.price),
         'description': self.description,
         'flag_uuid': flag_uuid,
         'uuid': self.uuid,
         'flaglist': Box.flaglist(self.box_id)
     }
开发者ID:moloch--,项目名称:RootTheBox,代码行数:13,代码来源:Hint.py


示例18: box_level

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


示例19: get

 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:AnarKyx01,项目名称:RootTheBox,代码行数:14,代码来源:MissionsHandler.py


示例20: create_hint

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python Corporation.Corporation类代码示例发布时间:2022-05-27
下一篇:
Python models.WorkshopGame类代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap