Exemplo n.º 1
0
def create_alert():
    if request.method == 'POST':
        item_url = request.form['item_url']

        store = Store.find_by_url(item_url)
        item = Item(item_url, store.tag_name, store.query)
        item.load_price()
        item.save_to_mongo()

        alert_name = request.form['name']
        price_limit = request.form['price_limit']

        Alert(alert_name, item._id, price_limit,
              session["email"]).save_to_mongo()

    # What happens if it's a GET request
    return render_template("alerts/new_alert.html")
Exemplo n.º 2
0
def new_alert():

    # If POST method included in the request, a new alert needs to be saved
    # After saving the new alert from the POST, user redirected to their alerts list at '/'
    if request.method == 'POST':
        alert_name = request.form['name']
        item_url = request.form['item_url']
        price_limit = float(request.form['price_limit'])
        store = Store.find_by_url(item_url)
        item = Item(item_url, store.tag_name, store.query)
        item.load_price()
        item.save_to_mongo()
        Alert(alert_name, item._id, price_limit,
              session['email']).save_to_mongo()

        return redirect(url_for('.index'))

    # If POST was not included in the request, form is provided for user to enter new alert information
    return render_template('/alerts/new_alert.html')