def profile(): user_id = session['user_id'] database = Database(filename) user_profile = database.findUserProfile(user_id) user_name = database.findUserName(user_id) return render_template('profile.html', user_id=user_id, user_profile=user_profile, user_name=user_name, language=session['language'])
def debug(): user_id = session['user_id'] database = Database(filename) user_group = database.findUserGroup(user_id) user_name = database.findUserName(user_id) return render_template('debug.html', user_id=user_id, user_group=user_group, user_name=user_name, language=session['language'])
def recipes(): if 'user_id' in session: user_id = session['user_id'] database = Database(filename) user_name = database.findUserName(user_id) recipes = database.deliverRecipe() return render_template('recipes.html', user_id=session['user_id'], recipes=recipes, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def result(): if 'user_id' in session: database = Database(filename) user_id = session['user_id'] user_name = database.findUserName(user_id) #user_id = 1 recipes = database.deliverMyRecipe(user_id) fridge = database.deliverFridge(user_id) if len(fridge) != 0: fridge = fridge[0][1] fridge = fridge.split(' ') # fridge is a list of what you have-unicode # recipes is a list of tuple recipe_list = list(recipes) result_list = [] for one_recipe in recipes: dish_num = one_recipe[0] dish_name = one_recipe[1] still_need = one_recipe[2].split( ' ') #components is a list of materials. what_i_have = [] for item in fridge: if item in still_need: still_need.remove(item) what_i_have.append(item) this_entry = [] this_entry.append(dish_num) this_entry.append(dish_name) this_entry.append(what_i_have) this_entry.append(still_need) this_entry.append(len(still_need)) result_list.append(this_entry) sorted_result = [] while len(result_list) != 0: min = 10000 to_delete = 0 for line in result_list: if line[4] < min: min = line[4] to_delete = line sorted_result.append(to_delete) result_list.remove(to_delete) # soted_result is a list: # [dish_num, dish_name, list(what_i_have), list(material still needed), item number still needed] return render_template('result.html', user_id=session['user_id'], data=sorted_result, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def my_recipes(): if 'user_id' in session: user_id = session['user_id'] database = Database(filename) user_name = database.findUserName(user_id) user_group = database.findUserGroup(user_id) if user_group == 2: return "您必须先验证邮箱才能使用功能" recipes = database.deliverMyRecipe(user_id) return render_template('my_recipes.html', user_id=session['user_id'], recipes=recipes, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])
def fridges(): if 'user_id' in session: database = Database(filename) user_id = session['user_id'] user_name = database.findUserName(user_id) user_group = database.findUserGroup(user_id) if user_group == 2: return "您必须先验证邮箱才能使用功能" #user_id = 1 fridges = database.deliverFridge(user_id) if len(fridges) != 0: fridges = fridges[0][1].split(' ') # now fridges is a list of stock return render_template('fridges.html', user_id=session['user_id'], fridges=fridges, user_name=user_name, language=session['language']) return render_template('login_name.html', language=session['language'])