def post(self, *args, **kwargs): game_objects = { "game_level": GameLevel, "corporation": Corporation, "flag": Flag, "box": Box, "hint": Hint, } obj_name = self.get_argument("obj", "") uuid = self.get_argument("uuid", "") if obj_name in game_objects.keys(): obj = game_objects[obj_name].by_uuid(uuid) if obj is not None: self.write(obj.to_dict()) else: self.write({"Error": "Invalid uuid."}) elif obj_name == "stats": flag = Flag.by_uuid(uuid) if flag is not None: if options.banking: price = "$" + str(flag.value) else: price = str(flag.value) + " points" flaginfo = [ { "name": flag.name, "description": flag.description, "token": flag.token, "price": price, } ] captures = [] for item in Flag.captures(flag.id): team = Team.by_id(item[0]) if team: captures.append({"name": team.name}) attempts = self.attempts(flag) hints = [] for item in Hint.taken_by_flag(flag.id): team = Team.by_id(item.team_id) hint = Hint.by_id(item.hint_id) if team: if options.banking: price = "$" + str(hint.price) else: price = str(hint.price) + " points" hints.append({"name": team.name, "price": price}) obj = { "flag": flaginfo, "captures": captures, "attempts": attempts, "hints": hints, } self.write(obj) else: self.write({"Error": "Invalid uuid."}) else: self.write({"Error": "Invalid object type."}) self.finish()
def post(self, *args, **kwargs): game_objects = { 'game_level': GameLevel, 'corporation': Corporation, 'flag': Flag, 'box': Box, 'hint': Hint, } obj_name = self.get_argument('obj', '') uuid = self.get_argument('uuid', '') if obj_name in game_objects.keys(): obj = game_objects[obj_name].by_uuid(uuid) if obj is not None: self.write(obj.to_dict()) else: self.write({'Error': 'Invalid uuid.'}) elif obj_name == "stats": flag = Flag.by_uuid(uuid) if flag is not None: if options.banking: flaginfo = [{"name": flag.name, "token": flag.token, "price": "$" + str(flag.value)}] else: flaginfo = [{"name": flag.name, "token": flag.token, "price": str(flag.value) + " points"}] captures = [] for item in Flag.captures(flag.id): team = Team.by_id(item[0]) if team: captures.append({"name": team.name}) attempts = [] for item in Penalty.by_flag_id(flag.id): team = Team.by_id(item.team_id) if team: attempts.append({"name": team.name, "token": item.token}) hints = [] for item in Hint.taken_by_flag(flag.id): team = Team.by_id(item.team_id) hint = Hint.by_id(item.hint_id) if team: if options.banking: hints.append({"name": team.name, "price": "$" + str(hint.price)}) else: hints.append({"name": team.name, "price": str(hint.price) + " points"}) obj = { "flag": flaginfo, "captures": captures, "attempts": attempts, "hints": hints, } self.write(obj) else: self.write({'Error': 'Invalid uuid.'}) else: self.write({'Error': 'Invalid object type.'}) self.finish()