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'])
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)
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)