コード例 #1
0
 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), ])
コード例 #2
0
 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),
         ])
コード例 #3
0
 def export_game_objects(self, root):
     '''
     Exports the game objects to an XML doc.
     For the record, I hate XML with a passion.
     '''
     levels_elem = ET.SubElement(root, "gamelevels")
     levels_elem.set("count", str(GameLevel.count()))
     for level in GameLevel.all()[1:]:
         level.to_xml(levels_elem)
     corps_elem = ET.SubElement(root, "corporations")
     corps_elem.set("count", str(Corporation.count()))
     for corp in Corporation.all():
         corp.to_xml(corps_elem)
コード例 #4
0
 def export_game_objects(self, root):
     '''
     Exports the game objects to an XML doc.
     For the record, I hate XML with a passion.
     '''
     levels_elem = ET.SubElement(root, "gamelevels")
     levels_elem.set("count", str(GameLevel.count()))
     for level in GameLevel.all()[1:]:
         level.to_xml(levels_elem)
     corps_elem = ET.SubElement(root, "corporations")
     corps_elem.set("count", str(Corporation.count()))
     for corp in Corporation.all():
         corp.to_xml(corps_elem)
コード例 #5
0
 def create_corporation(self):
     ''' Add a new corporation to the database '''
     try:
         corp_name = self.get_argument('corporation_name', '')
         if Corporation.by_name(corp_name) is not None:
             raise ValueError("Corporation name already exists")
         else:
             corporation = Corporation()
             corporation.name = corp_name
             self.dbsession.add(corporation)
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
     except ValueError as error:
         self.render("admin/create/corporation.html", errors=["%s" % error])
コード例 #6
0
 def create_corporation(self):
     """ Add a new corporation to the database """
     try:
         corp_name = self.get_argument("corporation_name", "")
         if Corporation.by_name(corp_name) is not None:
             raise ValidationError("Corporation name already exists")
         else:
             corporation = Corporation()
             corporation.name = corp_name
             self.dbsession.add(corporation)
             self.dbsession.commit()
             self.redirect("/admin/view/game_objects")
     except ValidationError as error:
         self.render("admin/create/corporation.html", errors=[str(error)])
コード例 #7
0
    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),
            ])
コード例 #8
0
 def del_corp(self):
     ''' Delete a corporation '''
     corp = Corporation.by_uuid(self.get_argument('uuid', ''))
     if corp is not None:
         logging.info("Delete corporation: %s" % corp.name)
         self.dbsession.delete(corp)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     else:
         self.render('admin/view/game_objects.html',
                     errors=["Corporation does not exist in database."])
コード例 #9
0
 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.flag_submission_type = FlagsSubmissionType[
                 self.get_argument('flag_submission_type', '')]
             box.difficulty = self.get_argument('difficulty', '')
             box.operating_system = self.get_argument(
                 'operating_system', '?')
             cat = Category.by_uuid(self.get_argument('category_uuid', ''))
             if cat is not None:
                 box.category_id = cat.id
             else:
                 box.category_id = None
             # Avatar
             avatar_select = self.get_argument('box_avatar_select', '')
             if avatar_select and len(avatar_select) > 0:
                 box._avatar = avatar_select
             elif hasattr(self.request,
                          'files') and '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#%s" % box.uuid)
     except ValidationError as error:
         self.render('admin/create/box.html', errors=[
             str(error),
         ])
コード例 #10
0
 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.flag_submission_type = FlagsSubmissionType[
                 self.get_argument("flag_submission_type", "")]
             box.difficulty = self.get_argument("difficulty", "")
             box.operating_system = self.get_argument(
                 "operating_system", "?")
             box.capture_message = self.get_argument("capture_message", "")
             box.value = self.get_argument("reward", 0)
             cat = Category.by_uuid(self.get_argument("category_uuid", ""))
             if cat is not None:
                 box.category_id = cat.id
             else:
                 box.category_id = None
             # Avatar
             avatar_select = self.get_argument("box_avatar_select", "")
             if avatar_select and len(avatar_select) > 0:
                 box._avatar = avatar_select
             elif hasattr(self.request,
                          "files") and "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#%s" % box.uuid)
     except ValidationError as error:
         self.render("admin/create/box.html", errors=[str(error)])
コード例 #11
0
 def to_dict(self):
     ''' Returns editable data as a dictionary '''
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     return {
         'name': self.name,
         'uuid': self.uuid,
         'corporation': corp.uuid,
         'description': self._description,
         'difficulty': self.difficulty,
         'game_level': game_level.uuid,
     }
コード例 #12
0
ファイル: Box.py プロジェクト: AdaFormacion/RootTheBox
 def to_dict(self):
     ''' Returns editable data as a dictionary '''
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     return {
         'name': self.name,
         'uuid': self.uuid,
         'corporation': corp.uuid,
         'description': self._description,
         'difficulty': self.difficulty,
         'game_level': game_level.uuid,
     }
コード例 #13
0
 def del_corp(self):
     ''' Delete a corporation '''
     corp = Corporation.by_uuid(self.get_argument('uuid', ''))
     if corp is not None:
         logging.info("Delete corporation: %s" % corp.name)
         self.dbsession.delete(corp)
         self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     else:
         self.render('admin/view/game_objects.html',
             errors=["Corporation does not exist in database."]
         )
コード例 #14
0
 def del_corp(self):
     """ Delete a corporation """
     corp = Corporation.by_uuid(self.get_argument("uuid", ""))
     if corp is not None:
         logging.info("Delete corporation: %s" % corp.name)
         self.dbsession.delete(corp)
         self.dbsession.commit()
         self.redirect("/admin/view/game_objects")
     else:
         self.render(
             "admin/view/game_objects.html",
             errors=["Corporation does not exist in database."],
         )
コード例 #15
0
 def _make_box(self, level_number):
     ''' Creates a box in the database '''
     corp = Corporation.by_uuid(self.get_argument('corporation_uuid'))
     level = GameLevel.by_number(level_number)
     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 'avatar' in self.request.files:
         box.avatar = self.request.files['avatar'][0]['body']
     return box
コード例 #16
0
    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), ])
コード例 #17
0
def has_box_materials(box):
    if not options.use_box_materials_dir:
        return False

    d = options.game_materials_dir
    path = os.path.join(d, box.name)
    if os.path.isdir(path):
        return box.name
    else:
        corp = Corporation.by_id(box.corporation_id)
        path = os.path.join(d, corp.name, box.name)
    if os.path.isdir(path):
        return os.path.join(corp.name, box.name)
    return False
コード例 #18
0
def has_box_materials(box):
    if not options.use_box_materials_dir:
        return False

    d=options.game_materials_dir
    path = os.path.join(d, box.name)
    if os.path.isdir(path):
        return box.name
    else:
        corp = Corporation.by_id(box.corporation_id)
        path = os.path.join(d, corp.name, box.name)
    if os.path.isdir(path):
        return os.path.join(corp.name, box.name)
    return False
コード例 #19
0
 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.flag_submission_type = FlagsSubmissionType[self.get_argument('flag_submission_type','')]
             box.difficulty = self.get_argument('difficulty', '')
             box.operating_system = self.get_argument('operating_system', '?')
             cat = Category.by_uuid(self.get_argument('category_uuid', ''))
             if cat is not None:
                 box.category_id = cat.id
             else:
                 box.category_id = None
             # Avatar
             avatar_select = self.get_argument('box_avatar_select', '')
             if avatar_select and len(avatar_select) > 0:
                 box._avatar = avatar_select
             elif hasattr(self.request, 'files') and '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#%s" % box.uuid)
     except ValidationError as error:
         self.render('admin/create/box.html', errors=[str(error), ])
コード例 #20
0
 def edit_corporations(self):
     """ Updates corporation object in the database """
     try:
         corp = Corporation.by_uuid(self.get_argument("uuid", ""))
         if corp is None:
             raise ValidationError("Corporation does not exist")
         name = self.get_argument("name", "")
         if name != corp.name:
             logging.info("Updated corporation name %s -> %s" % (corp.name, name))
             corp.name = name
             self.dbsession.add(corp)
             self.dbsession.commit()
         self.redirect("/admin/view/game_objects")
     except ValidationError as error:
         self.render("admin/view/game_objects.html", errors=[str(error)])
コード例 #21
0
 def edit_corporations(self):
     ''' Updates corporation object in the database '''
     try:
         corp = Corporation.by_uuid(self.get_argument('uuid', ''))
         if corp is None:
             raise ValidationError("Corporation does not exist")
         name = self.get_argument('name', '')
         if name != corp.name:
             logging.info("Updated corporation name %s -> %s" % (
                 corp.name, name
             ))
             corp.name = name
             self.dbsession.add(corp)
             self.dbsession.commit()
         self.redirect('/admin/view/game_objects')
     except ValidationError as error:
         self.render("admin/view/game_objects.html", errors=[str(error), ])
コード例 #22
0
 def edit_corporations(self):
     ''' Updates corporation object in the database '''
     corp = Corporation.by_uuid(self.get_argument('uuid', ''))
     if corp is not None:
         try:
             name = self.get_argument('name', '')
             if name != corp.name:
                 logging.info("Updated corporation name %s -> %s" % (corp.name, name))
                 corp.name = name
                 self.dbsession.add(corp)
                 self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
         except ValueError as error:
             self.render("admin/view/game_objects.html", errors=["%s" % error])
     else:
         self.render("admin/view/game_objects.html",
             errors=["Corporation does not exist"]
         )
コード例 #23
0
ファイル: Box.py プロジェクト: carlocaserta/RootTheBox
 def to_dict(self):
     ''' Returns editable data as a dictionary '''
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     cat = Category.by_id(self.category_id)
     if cat:
         category = cat.uuid
     else:
         category = ""
     return {
         'name': self.name,
         'uuid': self.uuid,
         'corporation': corp.uuid,
         'category': category,
         'operating_system': self.operating_system,
         'description': self._description,
         'difficulty': self.difficulty,
         'game_level': game_level.uuid,
         'flaglist': self.flaglist(self.id)
     }
コード例 #24
0
 def create_box(self):
     ''' Create a box object '''
     try:
         lvl = self.get_argument('game_level', '')
         game_level = abs(int(lvl)) if lvl.isdigit() else 0
         corp_uuid = self.get_argument('corporation_uuid', '')
         if Box.by_name(self.get_argument('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:
             box = self._make_box(game_level)
             self.dbsession.commit()
             self.redirect('/admin/view/game_objects')
     except ValueError as error:
         self.render('admin/create/box.html', errors=["%s" % error])
コード例 #25
0
ファイル: Box.py プロジェクト: moloch--/RootTheBox
 def to_dict(self):
     ''' Returns editable data as a dictionary '''
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     cat = Category.by_id(self.category_id)
     if cat:
         category = cat.uuid
     else:
         category = ""
     return {
         'name': self.name,
         'uuid': self.uuid,
         'corporation': corp.uuid,
         'category': category,
         'operating_system': self.operating_system,
         'description': self._description,
         'difficulty': self.difficulty,
         'game_level': game_level.uuid,
         'flag_submission_type': self.flag_submission_type,
         'flaglist': self.flaglist(self.id)
     }
コード例 #26
0
 def to_dict(self):
     """ Returns editable data as a dictionary """
     corp = Corporation.by_id(self.corporation_id)
     game_level = GameLevel.by_id(self.game_level_id)
     cat = Category.by_id(self.category_id)
     if cat:
         category = cat.uuid
     else:
         category = ""
     return {
         "name": self.name,
         "uuid": self.uuid,
         "corporation": corp.uuid,
         "category": category,
         "operating_system": self.operating_system,
         "description": self._description,
         "difficulty": self.difficulty,
         "game_level": game_level.uuid,
         "flag_submission_type": self.flag_submission_type,
         "flaglist": self.flaglist(self.id),
     }
コード例 #27
0
def create_corp():
    corp = Corporation()
    corp.name = "TestCorp"
    dbsession.add(corp)
    dbsession.commit()
    return corp
コード例 #28
0
    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")
            # Category
            cat = Category.by_uuid(self.get_argument("category_uuid", ""))
            if cat is not None and cat.id != box.category_id:
                logging.info("Updated %s's category %s -> %s" %
                             (box.name, box.category_id, cat.id))
                box.category_id = cat.id
            elif cat is None and cat != box.category_id:
                logging.info("Updated %s's category %s -> None" %
                             (box.name, box.category_id))
                box.category_id = None
            # System Type
            ostype = self.get_argument("operating_system", "")
            if ostype is not None and ostype != box.operating_system:
                logging.info("Updated %s's system type %s -> %s" %
                             (box.name, box.operating_system, ostype))
                box.operating_system = ostype
            # 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
            # Flag submission type
            flag_submission_type = self.get_argument("flag_submission_type",
                                                     "")
            if (flag_submission_type is not None
                    and flag_submission_type != box.flag_submission_type):
                logging.info(
                    "Updated %s's flag submission type %s -> %s" %
                    (box.name, box.flag_submission_type, flag_submission_type))
                box.flag_submission_type = flag_submission_type
            # Capture Message
            capture_message = self.get_argument("capture_message", "")
            if capture_message != box.capture_message:
                logging.info("Updated %s's capture message %s -> %s" %
                             (box.name, box.capture_message, capture_message))
                box.capture_message = capture_message
            # Reward Value
            reward = self.get_argument("value", 0)
            if reward != box.value:
                logging.info("Updated %s's capture value %s -> %s" %
                             (box.name, box.value, reward))
                box.value = reward
            # Avatar
            avatar_select = self.get_argument("box_avatar_select", "")
            if avatar_select and len(avatar_select) > 0:
                box._avatar = avatar_select
            elif "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#%s" % box.uuid)
        except ValidationError as error:
            self.render("admin/view/game_objects.html",
                        success=None,
                        errors=[str(error)])
コード例 #29
0
    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")
            # Category
            cat = Category.by_uuid(self.get_argument('category_uuid'))
            if cat is not None and cat.id != box.category_id:
                logging.info("Updated %s's category %s -> %s" % (
                    box.name, box.category_id, cat.id,
                ))
                box.category_id = cat.id
            elif cat is None and cat != box.category_id:
                logging.info("Updated %s's category %s -> None" % (
                    box.name, box.category_id,
                ))
                box.category_id = None
            # System Type
            ostype = self.get_argument('operating_system')
            if ostype is not None and ostype != box.operating_system:
                logging.info("Updated %s's system type %s -> %s" % (
                    box.name, box.operating_system, ostype,
                ))
                box.operating_system = ostype
            # 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
            # Flag submission type
            flag_submission_type = self.get_argument('flag_submission_type', '')
            if flag_submission_type is not None and flag_submission_type != box.flag_submission_type:
                logging.info("Updated %s's flag submission type %s -> %s" % (
                    box.name, box.flag_submission_type, flag_submission_type
                ))
                box.flag_submission_type = flag_submission_type
            # Avatar
            avatar_select = self.get_argument('box_avatar_select', '')
            if avatar_select and len(avatar_select) > 0:
                box._avatar = avatar_select
            elif '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#%s" % box.uuid)
        except ValidationError as error:
            self.render("admin/view/game_objects.html", errors=[str(error), ])
コード例 #30
0
ファイル: Helpers.py プロジェクト: AdaFormacion/RootTheBox
def create_corp():
    corp = Corporation()
    corp.name = "TestCorp"
    dbsession.add(corp)
    dbsession.commit()
    return corp
コード例 #31
0
    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")
            # Category
            cat = Category.by_uuid(self.get_argument('category_uuid'))
            if cat is not None and cat.id != box.category_id:
                logging.info("Updated %s's category %s -> %s" % (
                    box.name,
                    box.category_id,
                    cat.id,
                ))
                box.category_id = cat.id
            elif cat is None and cat != box.category_id:
                logging.info("Updated %s's category %s -> None" % (
                    box.name,
                    box.category_id,
                ))
                box.category_id = None
            # System Type
            ostype = self.get_argument('operating_system')
            if ostype is not None and ostype != box.operating_system:
                logging.info("Updated %s's system type %s -> %s" % (
                    box.name,
                    box.operating_system,
                    ostype,
                ))
                box.operating_system = ostype
            # 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
            avatar_select = self.get_argument('box_avatar_select', '')
            if avatar_select and len(avatar_select) > 0:
                box._avatar = avatar_select
            elif '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#%s" % box.uuid)
        except ValidationError as error:
            self.render("admin/view/game_objects.html", errors=[
                str(error),
            ])
コード例 #32
0
ファイル: Box.py プロジェクト: brutalhonesty/RootTheBox
 def corporation(self):
     return Corporation.by_id(self.corporation_id)
コード例 #33
0
 def corporation(self):
     return Corporation.by_id(self.corporation_id)