def delete_alert(alert_id): # Remove alert from database Alert.get_by_id(alert_id).remove_from_mongo() # Redirect to alerts home page return redirect(url_for('.index'))
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')) return render_template("alerts/edit_alert.html", alert=Alert.get_by_id(alert_id))
def index(): # Get alerts from database (null if none) alerts = Alert.find_many_by_email(session['email']) for alert in alerts: print(alert.user_email) # Render alerts template with alerts from database return render_template( 'alerts/index.html', alerts=alerts) # Render alerts template with alerts from database
def edit_alert(alert_id): # Get the alert information from the database (alert_id part of GET request) alert = Alert.get_by_id(alert_id) item = Item.get_by_id(alert.item_id) # POST method is used once changes have been made on the edit alert form # After saving the updated alert, the user is forwarded back to alerts home '/' 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')) # Where GET request only, user is directed to the edit alert page return render_template('alerts/edit_alert.html', alert=alert)
def login_user(): # If POST in request, then the user has submitted the form with content if request.method == 'POST': email = request.form['email'] password = request.form['password'] try: if User.is_login_valid(email, password): session['email'] = email alerts = Alert.find_many_by_email(email) return render_template('alerts/index.html', alerts=alerts) except UserErrors.UserError as e: # user errors are defined in model.user.errors return e.message # If no POST in request user is presented the login form to be completed return render_template('users/login.html')
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")
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')
def logout_user(): # Remove session identifier and reset default alerts, forwarding user back to home page session['email'] = None alerts = Alert.find_many_by_email(os.getenv("ADMIN")) return render_template('home.html', alerts=alerts)
''' File name: alert_updater.py Author: Martin Dwyer Date: April 7, 2020 Description: This file initiates a review of all alerts which users have saved in the application and sends emails to users where prices have reached their desired price or below. License: The application is provide herein under the GNU General Public License, a free copyleft license for software. A copy of this license has been provided in the root folder of this application. ''' from model.alert import Alert # Collecting all alerts in the application alerts = Alert.all() # Checking prices and sending notifications where appropriate for alert in alerts: alert.load_item_price() print(alert.item.price) alert.notifiy_if_price_reached() # Sending notification to console if no alerts exist yet if not alerts: print("No alerts have been created. Add an item and an alert to begin!")
def home(): alerts = Alert.find_many_by_email( os.getenv("ADMIN")) # Alerts for ADMIN provide home page examples. return render_template('home.html', alerts=alerts)
from view.view import View from controller.controller import Controller from model.algorithm import Algorithm from model.state import State from model.logger import Logger from model.alert import Alert if __name__ == "__main__": app = QtWidgets.QApplication(sys.argv) MainWindow = QtWidgets.QMainWindow() algorithm = Algorithm() state = State() logger = Logger() alert = Alert() controller = Controller() controller.connectToModels(algorithm=algorithm, state=state, logger=logger, alert=alert) ui = View(MainWindow) ui.connectToController(controller) ui.subscribeToModels(algorithm, state, logger, alert) # controller = SearchSortUIController(ui) MainWindow.show() sys.exit(app.exec_())
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'))
def index(): alerts = Alert.find_many_by("user_email", session["email"]) return render_template('alerts/index.html', alerts=alerts)