Example #1
0
def add_recipe_to_cart(recipeid, userid):
    """Add ingredients from a given recipe to grocery cart."""

    recipe_ingredients = Ingredient.get_recipe_ingredients(recipeid)

    for ingredient in recipe_ingredients:
        Cart_Ingredient.create_new_cart_ingredient(session['Cart'], ingredient.ingredient_id)

    flash("You have successfully added your recipe to your grocery cart.", "cart_add")

    return redirect("/myrecipes/%d/cart/%d" % (userid, session['Cart']))
Example #2
0
def update_edited_cart(userid, cartid):
    """Update the cart_ingredients table to reflect edited changes."""

    # delete old cart ingredients
    Cart_Ingredient.delete_old_cart_ingredients(cartid)

    # get and format the new cart ingredients
    edited_cart_ings = Ingredient.get_edited_cart_ings(request.form)

    # add new cart ingredients to the ingredients table and cart_ingredients table
    Ingredient.add_edited_cart_ings_to_db(edited_cart_ings, cartid)

    return redirect("/myrecipes/%d/cart/%d" % (userid, cartid))
Example #3
0
def update_edited_cart(userid, cartid):
    """Update the cart_ingredients table to reflect edited changes."""

    # delete old cart ingredients
    Cart_Ingredient.delete_old_cart_ingredients(cartid)

    # get and format the new cart ingredients
    edited_cart_ings = Ingredient.get_edited_cart_ings(request.form)

    # add new cart ingredients to the ingredients table and cart_ingredients table
    Ingredient.add_edited_cart_ings_to_db(edited_cart_ings, cartid)

    return redirect("/myrecipes/%d/cart/%d" % (userid, cartid))
Example #4
0
def add_recipe_to_cart(recipeid, userid):
    """Add ingredients from a given recipe to grocery cart."""

    recipe_ingredients = Ingredient.get_recipe_ingredients(recipeid)

    for ingredient in recipe_ingredients:
        Cart_Ingredient.create_new_cart_ingredient(session['Cart'],
                                                   ingredient.ingredient_id)

    flash("You have successfully added your recipe to your grocery cart.",
          "cart_add")

    return redirect("/myrecipes/%d/cart/%d" % (userid, session['Cart']))
Example #5
0
def send_text():
    """Send a SMS with user grocery cart."""

    # gets the phone number we're sending a text to
    user_phone = User.get_user_phone(session['User'])
    user_phone = "+1" + (str(user_phone))

    # gets the ingredients in the cart
    cart_ings = Cart_Ingredient.get_cart_ingredients(session['Cart'])

    cart_text = "My Cart:"

    # formats the cart ingredients
    for c in cart_ings:
        if c.ingredient.measure is None and c.ingredient.quantity is not None:
            cart_text += '\n + ' + c.ingredient.quantity + ' ' + c.ingredient.item
        else:
            cart_text += '\n + ' + c.ingredient.item

    #sends text via twilio
    account_sid = os.environ['TWILIO_ACCOUNT_SID']
    auth_token = os.environ['TWILIO_AUTH_TOKEN']
    client = TwilioRestClient(account_sid, auth_token)

    message = client.messages.create(to=user_phone, from_=os.environ['TWILIO_NUMBER'],
                                     body=cart_text)

    resp = twilio.twiml.Response()
    resp.sms(message)

    flash("Your grocery cart was texted to you. Happy shopping!", "text_message")

    return redirect("/myrecipes/%d" % session['User'])
Example #6
0
def send_text():
    """Send a SMS with user grocery cart."""

    # gets the phone number we're sending a text to
    user_phone = User.get_user_phone(session['User'])
    user_phone = "+1" + (str(user_phone))

    # gets the ingredients in the cart
    cart_ings = Cart_Ingredient.get_cart_ingredients(session['Cart'])

    cart_text = "My Cart:"

    # formats the cart ingredients
    for c in cart_ings:
        if c.ingredient.measure is None and c.ingredient.quantity is not None:
            cart_text += '\n + ' + c.ingredient.quantity + ' ' + c.ingredient.item
        else:
            cart_text += '\n + ' + c.ingredient.item

    #sends text via twilio
    account_sid = os.environ['TWILIO_ACCOUNT_SID']
    auth_token = os.environ['TWILIO_AUTH_TOKEN']
    client = TwilioRestClient(account_sid, auth_token)

    message = client.messages.create(to=user_phone,
                                     from_=os.environ['TWILIO_NUMBER'],
                                     body=cart_text)

    resp = twilio.twiml.Response()
    resp.sms(message)

    flash("Your grocery cart was texted to you. Happy shopping!",
          "text_message")

    return redirect("/myrecipes/%d" % session['User'])
Example #7
0
def edit_cart(userid, cartid):
    """Display form fields so user can edit their cart."""

    cart_ings = Cart_Ingredient.get_cart_ingredients(cartid)

    return render_template("edit_cart.html",
                           userid=userid,
                           cart_ings=cart_ings)
Example #8
0
def edit_cart(userid, cartid):
    """Display form fields so user can edit their cart."""

    cart_ings = Cart_Ingredient.get_cart_ingredients(cartid)

    return render_template("edit_cart.html", userid=userid, cart_ings=cart_ings)
Example #9
0
def display_cart(userid, cartid):
    """Display items in a user's cart."""

    cart_ings = Cart_Ingredient.get_cart_ingredients(cartid)

    return render_template("cart.html", userid=userid, cart_ings=cart_ings)
Example #10
0
def display_cart(userid, cartid):
    """Display items in a user's cart."""

    cart_ings = Cart_Ingredient.get_cart_ingredients(cartid)

    return render_template("cart.html", userid=userid, cart_ings=cart_ings)