Beispiel #1
0
def edit_alert(alert_id):
    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert = Alert.get_by_id(alert_id)
        alert.price_limit = price_limit
        alert.save_to_mongo()

    # What happens if it's a GET request
    return render_template(
        "alerts/edit_alert.html", alert=Alert.get_by_id(
            alert_id))  # Send the user an error if their login was invalid
def edit_alert(alert_id):
    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert = Alert.get_by_id(alert_id)
        alert.price_limit = price_limit
        alert.save_to_mongo()

        return redirect(url_for('.index'))

    # What happens if it's a GET request
    return render_template("alerts/edit_alert.html", alert=Alert.get_by_id(alert_id)) 
Beispiel #3
0
def edit_alert(alert_id):
    # alert = Alert.get_by_id(alert_id)

    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert = Alert.get_by_id(alert_id)
        alert.price_limit = price_limit
        alert.save_to_mongo()

        return redirect(url_for('.index'))

    return render_template('alerts/edit_alert.html',
                           alert=Alert.get_by_id(alert_id))
Beispiel #4
0
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)

    if request.method == "POST":
        price_limit = float(request.form["price_limit"])

        alert.price_limit = price_limit
        alert.save_to_mongo()

        return redirect(
            url_for(".index"))  # it calculates the URL to go to this index method inside the current blueprint

    # What happens if it's a GET request
    return render_template('alerts/edit_alert.html', alert=Alert.get_by_id(alert_id))
Beispiel #5
0
def edit(alert_id: str) -> Union[str, Response]:
    """
    Handles the RESTful EDIT (GET method) and UPDATE (POST method) routes.

    Parameters
    ----------
    alert_id : str
        The :class:`models.alert.Alert` id

    Returns
    -------
    str
        The INDEX template if POST method, EDIT template otherwise.
    """
    alert = Alert.get_by_id(alert_id)

    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert.price_limit = price_limit

        alert.load_item_price()

        alert.save_to_mongo()

        alert.notify_if_price_reached()

        return redirect(url_for('.index'))

    return render_template('alerts/edit.html', alert=alert)
Beispiel #6
0
def delete_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    alert.remove_from_mongo()
    alerts = Alert.find_many_by('user_email', session['email'])
    for i in alerts:
        i.__post__init__()
    return render_template("alerts/index.html",
                           alerts=alerts,
                           current=session['email'])
Beispiel #7
0
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    alert.__post__init__()
    if request.method == "POST":
        price_limit = float(request.form['price_limit'].strip())
        alert.price_limit = price_limit
        alert.save_to_mongo()
        return redirect(url_for('.index'))
    return render_template("alerts/edit_alert.html", alert=alert)
Beispiel #8
0
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    if request.method == "POST":
        price_limit = float(request.form["price_limit"])
        alert.price_limit = price_limit
        alert.save_to_mongo()
        return redirect(url_for(".index"))

    return render_template("alerts/edit_alert.html", alert=alert)
Beispiel #9
0
def delete_alert(alert_id):
    """

    :param alert_id:
    :return:
    """
    alert = Alert.get_by_id(alert_id)
    if alert.user_email == session['email']:
        alert.remove_to_mongo()
    return redirect(url_for('.index'))
Beispiel #10
0
def delete_alert(alert_id):
    """
    Removes the specified alert from the database
    :param alert_id:
    :return:
    """
    alert = Alert.get_by_id(alert_id)
    if alert.user_email == session['email']:
        alert.remove_from_db()
    return redirect(url_for('.index'))
Beispiel #11
0
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)

    if request.method == 'POST':
        alert.price_limit = float(request.form['price_limit'])
        alert.save_to_mongo()
        return redirect(url_for('.index'))

    # why do we load alert ti edut_alert.heml?
    return render_template('alerts/edit_alert.html', alert=alert)
Beispiel #12
0
def remove_alert(alert_id):

    alert = Alert.get_by_id(alert_id)

    if alert.user_email == session['email']:
        item = Item.get_by_id(alert.item_id)
        item.remove_from_mongo()
        alert.remove_from_mongo()

    return redirect(url_for('.index'))
Beispiel #13
0
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    if alert is not None:
        if request.method == 'POST':
            new_price_limit = float(request.form['price_limit'])
            alert.price_limit = new_price_limit
            alert.save_to_mongo()
            return redirect(url_for('.all_alerts'))
        return render_template('alerts/edit_alert.html', alert=alert)
    else:
        return redirect(url_for('.all_alerts'))
Beispiel #14
0
def delete_alert(alert_id):
    """
    This endpoint allows a user to delete an existing alert and remove from the database
    :return: Alert index for the application once alert is successfully removed
    """
    alert = Alert.get_by_id(alert_id)

    if alert.user_email == session['email']:
        alert.remove_from_mongo()

    return redirect(url_for('.index'))
Beispiel #15
0
def delete_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    d = Database
    print(alert)
    for a in alert:
        if a.user_email == session['email']:
            item_id = a.item_id
            a.remove_from_mongo()
            d.remove('items', {"_id": item_id})
    alert = Alert.all()
    return render_template('alerts/index.html', alerts=alert)
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)  # getting existing alert from db with id

    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert.price_limit = price_limit
        alert.save_to_mongo()  # replacing price_limit with new value

        return redirect(url_for('.index'))

    return render_template('alerts/edit_alert.html', alert=alert)
Beispiel #17
0
def edit_alert(alert_id):

    alert = Alert.get_by_id(alert_id)

    if request.method == 'POST':
        if alert.user_email == session['email']:
            alert.price_limit = float(request.form['price_limit'])
            alert.save_to_mongo()

            return redirect(url_for('.index'))

    else:
        return render_template('alerts/edit_alert.html', alert=alert)
Beispiel #18
0
def edit_alert(alert_id):
    alert_by_id = Alert.get_by_id(alert_id)

    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])
        alert_by_id.price_limit = price_limit
        alert_url = alert_by_id.item.url

        # We'l now update the Alert Entry in DB.
        alert_by_id.save_to_mongo()
        # Call below computes the URL to go to index method inside the current blueprint using '.'
        return redirect(url_for('.index'))

    return render_template('alerts/edit_alert.html', alert=alert_by_id)
Beispiel #19
0
def edit_alert(alert_id):
    """
    This endpoint allows a user to edit an existing alert and save to the database
    :return: Alert index for the application once alert is successfully edited
    """
    alert = Alert.get_by_id(alert_id)

    if request.method == 'POST':
        price_limit = float(request.form['price_limit'])

        alert.price_limit = price_limit
        alert.save_to_mongo()

        return redirect(url_for('.index'))

    return render_template('alerts/edit_alert.html', alert=alert)
Beispiel #20
0
def edit_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    if request.method == 'POST':
        for a in alert:
            if a.user_email == session['email']:
                Price_limit = request.form['price_limit']

                a.Price_limit = Price_limit
                a.get_item_url()
                print(a.item_url)
                print(a.name)
                a.update_to_mongo()
                text = "alert has been successfully edited"
                return redirect(url_for('.index', text=text))
    print(alert)
    return render_template('alerts/edit_alert.html', alert=alert)
Beispiel #21
0
def delete(alert_id: str) -> Union[str, Response]:
    """
    Handles the RESTful DESTROY route.

    Parameters
    ----------
    alert_id : str
        The :class:`models.alert.Alert` id

    Returns
    -------
    str
        The INDEX template.
    """
    alert = Alert.get_by_id(alert_id)
    if alert.user_email == session['email']:
        logger.debug(f"deleting alert: {alert}")
        alert.remove_from_mongo()
    return redirect(url_for('.index'))
Beispiel #22
0
def check_alert_price(alert_id):
    Alert.get_by_id(alert_id).load_item_price()
    return redirect(url_for('.get_alert_page', alert_id=alert_id))
Beispiel #23
0
def delete_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    if alert.user_email == session["email"]:
        alert.remove_from_mongo()
    return redirect(url_for(".index"))
Beispiel #24
0
def activate_alert(alert_id):
    Alert.get_by_id(alert_id).activate()
    return redirect(url_for('users.user_alerts'))
Beispiel #25
0
def delete_alert(alert_id):
    Alert.get_by_id(alert_id).remove_from_mongo()
    return redirect(url_for('users.user_alerts'))
Beispiel #26
0
def get_alert_page(alert_id):
    return render_template('alerts/alert.html',
                           alert=Alert.get_by_id(alert_id))
Beispiel #27
0
def delete_alert(alert_id):
    my_alert = Alert.get_by_id(alert_id)
    if my_alert.user_email == session['rks_email']:
        my_alert.remove_from_mongo()
    return redirect(url_for('.index'))
def delete_alert(alert_id):
    Alert.get_by_id(alert_id).remove_from_mongo()
    return redirect(url_for('.index'))
Beispiel #29
0
def delete_alert(alert_id):
    alert = Alert.get_by_id(alert_id)
    if alert.user_email == session['email']:
        alert.delete_from_mongo()
    return redirect(url_for('.show_all_alerts'))