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')
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)
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"])
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)
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)
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")
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."] )
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)
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")
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), ])
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')
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), ])
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)
def edit_flags(self): ''' Edit existing flags in the database ''' try: flag = Flag.by_uuid(self.get_argument('uuid', '')) if flag is None: raise ValidationError("Flag does not exist") # Name name = self.get_argument('name', '') if flag.name != name: logging.info("Updated flag name %s -> %s" % ( flag.name, name, )) flag.name = name token = self.get_argument('token', '') if flag.token != token: flag.token = token # Description description = self.get_argument('description', '') if flag._description != description: logging.info("Updated %s's description %s -> %s" % ( flag.name, flag._description, description, )) flag.description = description # Value flag.value = self.get_argument('value', '') flag.original_value = self.get_argument('value', '') flag.capture_message = self.get_argument('capture_message', '') flag.case_sensitive = self.get_argument('case-sensitive', 1) # Dependency Lock lock = Flag.by_uuid(self.get_argument('lock_uuid', '')) if lock: flag.lock_id = lock.id else: flag.lock_id = None box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is not None and flag not in box.flags: logging.info("Updated %s's box %d -> %d" % ( flag.name, flag.box_id, box.id )) flag.box_id = box.id elif box is None: raise ValidationError("Box does not exist") self.dbsession.add(flag) self.dbsession.commit() if flag.type == FLAG_CHOICE: self.edit_choices(flag, self.request.arguments) self.redirect("/admin/view/game_objects#%s" % box.uuid) except ValidationError as error: self.render("admin/view/game_objects.html", errors=["%s" % error])
def create_hint(self): ''' Add hint to database ''' box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is not None: try: 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 ValueError as error: self.render('admin/create/hint.html', errors=["%s" % error]) else: self.render('admin/create/hint.html', errors=["Box does not exist"])
def edit_flags(self): ''' Super ugly code, yes - Edit existing flags in the database ''' flag = Flag.by_uuid(self.get_argument('uuid', '')) if flag is not None: try: name = self.get_argument('name', '') if flag.name != name: if Flag.by_name(name) is None: logging.info("Updated flag name %s -> %s" % (flag.name, name,) ) flag.name = name else: raise ValueError("Flag name already exists") token = self.get_argument('token', '') if flag.token != token: if Flag.by_token(token) is None: logging.info("Updated %s's token %s -> %s" % (flag.name, flag.token, token) ) flag.token = token else: raise ValueError("Token is not unique") description = self.get_argument('description', '') if flag._description != description: logging.info("Updated %s's description %s -> %s" % (flag.name, flag._description, description,) ) flag.description = description flag.value = self.get_argument('value', '') flag.capture_message = self.get_argument('capture_message', '') box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is not None and flag not in box.flags: logging.info("Updated %s's box %d -> %d" % (flag.name, flag.box_id, box.id) ) flag.box_id = box.id elif box is None: raise ValueError("Box does not exist") self.dbsession.add(flag) 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=["Flag does not exist"] )
def _mkflag(self, flag_type, is_file=False): name = self.get_argument('flag_name', '') if is_file: if not 'flag' in self.request.files: raise ValueError('No file in request') token = self.request.files['flag'][0]['body'] else: token = self.get_argument('token', '') description = self.get_argument('description', '') reward = int(self.get_argument('reward', '')) box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is None: raise ValueError('Box does not exist') flag = Flag.create_flag(flag_type, box, name, token, description, reward) flag.capture_message = self.get_argument('capture_message', '') self.dbsession.add(flag) self.dbsession.commit() self.redirect('/admin/view/game_objects')
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: source_code_uuid = box.source_code.uuid self.dbsession.delete(box.source_code) self.dbsession.commit() root = self.application.settings['source_code_market_dir'] source_code_path = root + '/' + source_code_uuid logging.info("Delete souce code market file: %s (box: %s)" % (source_code_path, box.name,) ) if os.path.exists(source_code_path): os.unlink(source_code_path) errors = None else: errors = ["Box does not exist, or contains no source code"] self.render('admin/upgrades/source_code_market.html', errors=errors)
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() if self.application.settings['game_started'] or user.is_admin(): self.render('missions/box.html', box=box, user=user, team=user.team, errors=[], success=[], info=[]) else: self.render('missions/status.html', errors=None, info=["The game has not started yet"]) else: self.render('public/404.html')
def edit_ip(self): ''' Add ip addresses to a box (sorta edits the box object) ''' try: box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is None: raise ValidationError("Box does not exist") ip_addr = self.get_argument('ip_address', '') if IpAddress.by_address(ip_addr) is None: ip = IpAddress(box_id=box.id, address=ip_addr) if self.get_argument('visable', '').lower() != 'true': ip.visable = False box.ip_addresses.append(ip) self.dbsession.add(ip) self.dbsession.add(box) self.dbsession.commit() self.redirect("/admin/view/game_objects#%s" % box.uuid) else: raise ValidationError("IP address is already in use") except ValidationError as error: self.render("admin/view/game_objects.html", errors=[str(error), ])
def edit_ip(self): ''' Add ip addresses to a box (sorta edits the box object) ''' errors = [] box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is not None: addr = self.get_argument('ip_address', '') if IpAddress.by_address(addr) is None: try: ip = IpAddress(box_id=box.id, address=addr) box.ip_addresses.append(ip) self.dbsession.add(ip) self.dbsession.add(box) self.dbsession.commit() except Exception as error: errors.append(str(error)) else: errors.append("IP address is already in use") else: errors.append("Box does not exist") self.render("admin/view/game_objects.html", errors=errors)
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: 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(box.source_code.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(box.source_code.data) self.finish() else: self.render('public/404.html') else: self.render('public/404.html')
def edit_flags(self): ''' Edit existing flags in the database ''' try: flag = Flag.by_uuid(self.get_argument('uuid', '')) if flag is None: raise ValidationError("Flag does not exist") # Name name = self.get_argument('name', '') if flag.name != name: logging.info("Updated flag name %s -> %s" % ( flag.name, name, )) flag.name = name token = self.get_argument('token', '') if flag.token != token: flag.token = token # Description description = self.get_argument('description', '') if flag._description != description: logging.info("Updated %s's description %s -> %s" % ( flag.name, flag._description, description, )) flag.description = description # Value flag.value = self.get_argument('value', '') flag.capture_message = self.get_argument('capture_message', '') box = Box.by_uuid(self.get_argument('box_uuid', '')) if box is not None and flag not in box.flags: logging.info("Updated %s's box %d -> %d" % ( flag.name, flag.box_id, box.id )) flag.box_id = box.id elif box is None: raise ValidationError("Box does not exist") self.dbsession.add(flag) self.dbsession.commit() self.redirect("/admin/view/game_objects") except ValidationError as error: self.render("admin/view/game_objects.html", errors=["%s" % error])
def add_source_code(self): box = Box.by_uuid(self.get_argument('box_uuid')) if box is not None: if not 'source_archive' in self.request.files and 0 < len(self.request.files['source_archive']): self.render('admin/upgrades/source_code_market.html', errors=["No file data"] ) else: try: price = abs(int(self.get_argument('price', 'NaN'))) self.create_source_code(box, price) self.render('admin/upgrades/source_code_market.html', errors=None ) except ValueError: self.render('admin/upgrades/source_code_market.html', errors=["Price must be an integer"] ) else: self.render('admin/upgrades/source_code_market.html', errors=["The selected box does not exist"] )
def get(self, *args, **kwargs): ''' Renders Corp/Box/Flag create pages ''' game_objects = { 'corporation': 'admin/create/corporation.html', 'box': 'admin/create/box.html', 'flag': 'admin/create/flag.html', 'flag/regex': 'admin/create/flag-regex.html', 'flag/file': 'admin/create/flag-file.html', 'flag/static': 'admin/create/flag-static.html', 'flag/datetime': 'admin/create/flag-datetime.html', 'flag/choice': 'admin/create/flag-choice.html', 'game_level': 'admin/create/game_level.html', 'hint': 'admin/create/hint.html', 'team': 'admin/create/team.html', 'category': 'admin/create/category.html', } if len(args) and args[0] in game_objects: if args[0] == "hint": box = Box.by_uuid(self.get_argument("box", "")) self.render(game_objects[args[0]], box=box, errors=None) else: self.render(game_objects[args[0]], errors=None) else: self.render("public/404.html")
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), ])
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)])
def edit_flags(self): """ Edit existing flags in the database """ try: flag = Flag.by_uuid(self.get_argument("uuid", "")) if flag is None: raise ValidationError("Flag does not exist") # Name name = self.get_argument("name", "") if flag._name != name: logging.info("Updated flag name %s -> %s" % (flag._name, name)) flag.name = name token = self.get_argument("token", "") if flag.token != token: flag.token = token # Description description = self.get_argument("description", "") if flag._description != description: logging.info( "Updated %s's description %s -> %s" % (flag.name, flag._description, description) ) flag.description = description # Value flag.value = self.get_argument("value", "") flag.capture_message = self.get_argument("capture_message", "") flag.case_sensitive = self.get_argument("case-sensitive", 1) # Type flag_type = self.get_argument("flag_type", None) if flag_type and flag_type != flag.type: logging.info( "Updated %s's type %s -> %s" % (flag.name, flag.type, flag_type) ) flag.type = flag_type # Dependency Lock lock = Flag.by_uuid(self.get_argument("lock_uuid", "")) if lock: flag.lock_id = lock.id else: flag.lock_id = None box = Box.by_uuid(self.get_argument("box_uuid", "")) if box is not None and flag not in box.flags: logging.info( "Updated %s's box %d -> %d" % (flag.name, flag.box_id, box.id) ) flag.box_id = box.id for fl in box.flags: fl.order self.dbsession.add(fl) flag.order = len(box.flags) + 1 # place flag at end for hint in flag.hints: hint.box_id = box.id self.dbsession.add(hint) elif box is None: raise ValidationError("Box does not exist") self.dbsession.add(flag) self.dbsession.commit() if flag.type == FLAG_CHOICE: self.edit_choices(flag, self.request.arguments) self.redirect("/admin/view/game_objects#%s" % box.uuid) except ValidationError as error: self.render( "admin/view/game_objects.html", success=None, errors=["%s" % error] )
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), ])