def get_all_column_group(self, column, value, table, for_user): """ GET GROUP RESULTS FOR SPECIFIC COLUMN, FOR USER OR FOR PUBLIC RECIPES """ if for_user == True: column = QueryReadRecipes().query_count_and_group_column( column, value, table) else: column = QueryReadRecipes().query_count_and_group_column_public( column, value, table) return column
def var_saved_recipes(self, user_id, order_by, direction): result = QueryReadRecipes().query_users_saved_recipes( user_id, order_by, direction) recipes = Get().date_time_converter(result) count = len(recipes) groupings = ViewVariables(self.username).groupings() ### INSERT RECIPE AUTHOR INTO RECIPE DICT ## for recipe in recipes: author = QueryReadRecipes().query_username_or_id( 'Username', 'UserId', int(recipe['UserId'])) recipe['Author'] = author[0]['Username'] return recipes, count, groupings
def var_full_recipe(self, recipe_id): username = [{'Username': self.username}] result = QueryReadRecipes().query_all_mini_recipes( 'Recipe.RecipeId', recipe_id, 'RecipeTitle', 'asc') recipe = Get().date_time_converter(result) ingredients = QueryReadRecipes().query_ingredients_for_full_recipe( recipe_id) method = QueryReadRecipes().query_method_for_full_recipe(recipe_id) user_id = Get().get_user_id(username[0]['Username'])['UserId'] is_saved = Get().get_is_recipe_saved(user_id, recipe_id) ratings = QueryRating(recipe_id).query_rating_and_comments() return username, recipe, ingredients, method, is_saved, ratings
def get_is_recipe_saved(self, user_id, recipe_id): """ CHECKS TO SEE IF A RECIPE IS ALREADY SAVED BY USER """ is_recipe_saved = QueryReadRecipes().query_is_recipe_saved( user_id, recipe_id) if is_recipe_saved != []: return True else: return False
def var_all_public(self, order_by, direction): result = QueryReadRecipes().query_all_mini_recipes( 'MakePublic', 1, order_by, direction) recipes = Get().date_time_converter(result) count = len(recipes) groupings = ViewVariables(self.username).groupings() return recipes, count, groupings
def var_all_myrecipme(self, order_by, direction): user_id = Get().get_user_id(self.username) result = QueryReadRecipes().query_all_mini_recipes( 'User.UserId', user_id['UserId'], order_by, direction) recipes = Get().date_time_converter(result) count = len(recipes) groupings = ViewVariables(self.username).groupings() return recipes, count, groupings
def var_cat_search(self, table, search_by, search_value, column, category, order_by, direction): query = QueryReadRecipes() results = query.query_category_mini_recipes(table, search_by, search_value, column, category, order_by, direction) recipes = Get().date_time_converter(results) count = len((recipes)) groupings = ViewVariables(self.username).groupings() return recipes, count, groupings
def var_ing_search(self, search_by, search_value, ingredient, order_by, direction): recipes = [] count = 0 result = QueryReadRecipes().query_search_ingredient( search_by, search_value, ingredient, order_by, direction) if result == []: count = 0 else: recipes = Get().date_time_converter(result) count = len(recipes) groupings = ViewVariables(self.username).groupings() return recipes, count, groupings
def get_saved_recipes_for_user(self, user_id, order_by, direction): """ GET ALL THE SAVED RECIPES FOR A GIVEN USER """ saved_recipes = QueryReadRecipes().query_users_saved_recipes( user_id, order_by, direction) return saved_recipes
def get_method_for_full_recipe(self, recipe_id): """ GETS THE METHOD FOR DISPLAY ON THE FULL RECIPE PAGE """ method = QueryReadRecipes().query_method_for_full_recipe(recipe_id) return method
def get_user_id(self, username): """ GET USER ID FROM USERNAME """ user = QueryReadRecipes().query_username_or_id('UserId', 'Username', username) user_id = user[0] return user_id