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 GameLevel.by_number(game_level) is None:
             raise ValidationError("Game level does not exist")
         else:
             if Corporation.by_uuid(corp_uuid) is None:
                 if len(Corporation.all()) == 0:
                     # Create a empty Corp
                     corporation = Corporation()
                     corporation.name = ""
                     self.dbsession.add(corporation)
                     self.dbsession.commit()
                     corp_uuid = corporation.uuid
                 else:
                     raise ValidationError("Corporation does not exist")
             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)])
Beispiel #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.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),
         ])
 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), ])