Ejemplo n.º 1
0
def pantry_display():
    """Display pantry from database"""

    current_user = session['user_id']
    pantry = make_pantry(current_user)
    user_locs = get_locs(current_user)

    return render_template("pantry.html", pantry=pantry, user_locs=user_locs)
Ejemplo n.º 2
0
    def test_get_locs(self):
        """Takes user id, returns list of user's location objects"""

        query = Location.query.filter_by(user_id=1).order_by(
            Location.location_name).all()
        function = get_locs(1)

        assert query == function
Ejemplo n.º 3
0
def eatme_display():
    """Display eatme"""

    # Grab all user's items with an exp
    current_user = session['user_id']
    eat_me = eatme_generator(current_user)
    user_locs = get_locs(current_user)

    return render_template("eatme.html", eat_me=eat_me, user_locs=user_locs)
Ejemplo n.º 4
0
def store_form_display():
    """Display shopping list form"""

    # Grab all user's items with is_shopping status
    current_user = session["user_id"]
    shopping_list = get_shop_lst(current_user)
    user_locs = get_locs(current_user)

    return render_template("store.html",
                           shopping_list=shopping_list,
                           user_locs=user_locs)
Ejemplo n.º 5
0
def edit_item():
    """Display every field about a pantry item, with option to update any field"""

    pantry_id = request.args.get("pantry_id")

    # Grab from database
    item = Foodstuff.query.get(pantry_id)
    current_user = session['user_id']
    user_locs = get_locs(current_user)

    # Need to put user_locs into not-object form for jsonify
    loc_lst = []  # This will be a list of lists, inner list will be [id, name]
    for loc in user_locs:
        temp = []
        temp.append(loc.location_id)
        temp.append(loc.location_name)
        loc_lst.append(temp)
    """Convert to display format, get user's timezone, apply that to last_purch,
       which is saved in GMT in db, so user sees last_purch in their time zone"""
    tz = get_tz(current_user)
    ugly = (item.last_purch) + timedelta(hours=tz)
    pretty = ugly.strftime('%b %d, %Y')

    print "###################", item, item.is_shopping

    return jsonify({
        "pantryId": item.pantry_id,
        "userId": item.user_id,
        "itemName": item.name,
        "isPantry": item.is_pantry,
        "isShopping": item.is_shopping,
        "lastPurch": pretty,
        "locationId": item.location_id,
        "exp": item.exp,
        "description": item.description,
        "barcodeId": item.barcode_id
    })