def post(self): try: data = GamesList.parser.parse_args() if Game.find_by_name(data['name']): return msg('A game called "{}" already exists'.format(data['name'])), 400 game = Game(**data) game.save_to_db() return msg('Game created!'), 201 except: return msg('There was an error creating your game')
def search(): app_id = request.args.get("app_id", "").strip() or None query = request.args.get("search", "").strip() or None only_library_vector = request.args.get("only_library_vector", "off") == "on" removed_features = request.args.get("removed_features", "").decode('base64').split(",") or [] removed_features = Game.get_feature_indices(removed_features) if only_library_vector and g.library_vector is not None and g.game_list is not None: return render_ranking_page(None, True, removed_features=removed_features) elif app_id is not None and app_id.isdigit(): game = Game.get(int(app_id)) if game is not None: return render_ranking_page(game, False, removed_features=removed_features) else: return render_search_template(no_such_app_id=True) elif query is not None and len(query) > 0: game = Game.find_by_name(query) if game is not None: return render_ranking_page(game, False, removed_features=removed_features) else: app.logger.info("No result for " + query.encode("ascii", "ignore")) didyoumean1, didyoumean2 = Game.correct_game_name(query, max_results=2) return render_search_template(didyoumean1=didyoumean1, didyoumean2=didyoumean2, query=query) else: return render_search_template()