def get_search_results(userid): """Run search query and return results.""" search_query = request.args.get("searchQuery") if search_query != '': ##returns list of tuples ##index[0] = recipe_id ##index[1] = recipe_title ##index[2] = rank search_recipes = Recipe.run_search_query(userid, search_query) else: #gets all user recipes if the search query field is blank search_recipes = Recipe.get_user_recipe_list(userid) #creates dictionary from search results #key = recipeid #value = {dictionary of recipe title and userid} recipes_list = [] for recipe in search_recipes: recipe = list(recipe) recipes_list.append(recipe) return json.dumps(recipes_list)
def display_recipe_list(userid): """Display a list of recipes for a given user.""" user_recipes = Recipe.get_user_recipe_list(userid) return render_template("recipe_list.html", userid=userid, user_recipes=user_recipes)
def get(self, userid): """Get a list of user recipes. Returns JSON as {recipe_id: recipe_title}.""" user_recipes = Recipe.get_user_recipe_list(userid) recipes_dict = {} for r in user_recipes: recipes_dict[r[0]] = r[1] return recipes_dict
def get_suggestions(): """Get user data for typeahead suggestions.""" userid = session['User'] #### Hashtag Data #### hashtag_data = Hashtag.get_hashtags_by_user(userid) hashtag_list = [h[0] for h in hashtag_data] #### Recipe Data #### recipe_data = Recipe.get_user_recipe_list(userid) recipe_list = [r[1] for r in recipe_data] #### Ingredient Data #### ingredient_data = Ingredient.get_ingredients_by_user(userid) # convert to set then back to list to remove duplicates ingredient_list = list(set([i[0] for i in ingredient_data])) #### Combined Data #### data_list = hashtag_list + recipe_list + ingredient_list return jsonify({"userdata": data_list})