Esempio n. 1
0
def getShoppingList(name=None):

    """ It searches a shopping list by name or finds the latest saved"""

    shop_list = ''
    all_names = ''
    i_list = {}
    date_created = ''

    if 'User' in session:

        if name:

            shop_list = ShoppingList.getShoppingListByName(name, session['User'])
            
        else:

            shop_list = ShoppingList.getLatestShoppingList(session['User'])
            if shop_list:
                name = shop_list[0].list_name
        

        if len(shop_list) > 0:

            date_created = shop_list[0].date_created

            all_names = ShoppingList.getShoppingListNames(session['User'])

            i_list = helpFunctions.makeShoppingList(shop_list)


        return render_template("view_shopping_list.html", list=i_list,
                    names=all_names, date_created=date_created, name=name )

    else:

        flash = []
        flash = "You need to login"
        return render_template("/error.html", url="/getShoppingLists")