예제 #1
0
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'])
예제 #2
0
def admin_my_recipes():
    if not 'user_id' in session:
        return redirect(url_for('login_name'))
    if session['user_id'] != 0:
        return "You don't have the access!"
    user_id = request.args['user_id']
    recipes = []
    if request.method == 'POST':
        user_id = request.form['next_user_id']
    database = Database(filename)
    recipes = database.deliverMyRecipe(user_id)
    return render_template('admin_my_recipes.html',
                           user_id=user_id,
                           recipes=recipes)
예제 #3
0
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'])