Ejemplo n.º 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)) 
Ejemplo n.º 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))
Ejemplo n.º 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))
Ejemplo n.º 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)
Ejemplo n.º 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'])
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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)
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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'))
Ejemplo n.º 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)
Ejemplo n.º 16
0
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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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'))
Ejemplo n.º 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))
Ejemplo n.º 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"))
Ejemplo n.º 24
0
def activate_alert(alert_id):
    Alert.get_by_id(alert_id).activate()
    return redirect(url_for('users.user_alerts'))
Ejemplo n.º 25
0
def delete_alert(alert_id):
    Alert.get_by_id(alert_id).remove_from_mongo()
    return redirect(url_for('users.user_alerts'))
Ejemplo n.º 26
0
def get_alert_page(alert_id):
    return render_template('alerts/alert.html',
                           alert=Alert.get_by_id(alert_id))
Ejemplo n.º 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'))
Ejemplo n.º 28
0
def delete_alert(alert_id):
    Alert.get_by_id(alert_id).remove_from_mongo()
    return redirect(url_for('.index'))
Ejemplo n.º 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'))