def add_alerts(): user_plant_id = request.form.get('user_plant_id') alert_type_id = request.form.get('alert_type_id') date = request.form['date'] user_id = session.get('user_id') user_alert = Alert.query.filter_by(alert_type_id=alert_type_id, user_plant_id=user_plant_id, date=date).all() #conditional that searches userplant table for existing plants. if it already exists, plant is left alone. if plant does not exist, it's added to the table. if user_alert: # user_alert.date = date flash('Alert updated!') else: user_alert = Alert(user_plant_id=user_plant_id, alert_type_id=alert_type_id, date=date) flash('New alert added') db.session.add(user_alert) db.session.commit() return jsonify({ 'user_plant_id': user_plant_id, 'alert_type_id': alert_type_id, 'date': date })
def add_rec_alertset(): name = request.form['set_name'] desc = request.form['descri'] interval = request.form['interval'] contacts = request.form.getlist('contact') user = User.query.filter_by(email=session['current_user']).one() new_alert_set = AlertSet(user_id=user.user_id, a_name=name, a_desc=desc, interval=interval) db.session.add(new_alert_set) db.session.commit() alert_set = AlertSet.query.filter(AlertSet.user_id == user.user_id, AlertSet.a_name == name).first() contact1 = int(contacts[0]) contact2 = None contact3 = None if len(contacts) > 1: contact2 = int(contacts[1]) if len(contacts) > 2: contact3 = int(contacts[2]) new_alert = Alert(alert_set_id=alert_set.alert_set_id, user_id=user.user_id, contact_id1=contact1, contact_id2=contact2, contact_id3=contact3, interval=interval, message=desc) db.session.add(new_alert) db.session.commit() return redirect("/rec_alerts")
def add_sched_alert(alert_set_id): """Saves a new scheduled alert""" alert_set = AlertSet.query.filter( AlertSet.user_id == user.user_id, AlertSet.alert_set_id == alert_set_id).first() #Queries the current user user = User.query.filter_by(email=session['current_user']).one() #Gets the alert info from the form on the edit sched set page time = request.form['time'] #Initiates 3 contact variables, sets the first to the first contact and the next two to None contact1 = alert_set.contact_id1 contact2 = alert_set.contact_id2 contact3 = alert_set.contact_id3 #If more than one contact is associated with the alert set, the following variables are set to them #Creates a new alert object, adds it to the dBase, commits, and redirects back to the edit page new_alert = Alert(alert_set_id=alert_set_id, user_id=user.user_id, contact_id1=contact1, contact_id2=contact2, contact_id3=contact3, time=time) db.session.add(new_alert) db.session.commit() return "Alert Added"
def add_rec_alertset(): """Adds a recurring Alert-Set to the dBase""" user = User.query.filter_by(email=session['current_user']).one() alert_sets_all = AlertSet.query.filter_by(user_id=user.user_id).all() #Gets the alert and alert set info from the form on the add a new rec set page name = request.form['set_nam'] desc = request.form['descri'] interval = request.form['interval'] contacts = request.form.getlist('contact') print("name1: ", name, type(name), len(name)) if len(name) == 0: name = "Alert Set " + str(len(alert_sets_all)) print("name2: ", name, type(name), len(name)) #Queries the current user user = User.query.filter_by(email=session['current_user']).one() dt = datetime.datetime.now() #Creates a new alert set, adds it to the dBase, commits, and then queries the just-created alert set new_alert_set = AlertSet(user_id=user.user_id, start_datetime=dt, a_desc=desc, interval=interval, a_name=name) db.session.add(new_alert_set) db.session.commit() alert_set_q = AlertSet.query.order_by( AlertSet.start_datetime.desc()).first() #Initiates 3 contact variables, sets the first to the first contact and the next two to None contact1 = int(contacts[0]) contact2 = None contact3 = None #If more than one contact is associated with the alert set, the following variables are set to them if len(contacts) > 1: contact2 = int(contacts[1]) if len(contacts) > 2: contact3 = int(contacts[2]) #A new alert (associated with the alert set) is created, added, and commited to the dBase new_alert = Alert(alert_set_id=alert_set_q.alert_set_id, user_id=user.user_id, contact_id1=contact1, contact_id2=contact2, contact_id3=contact3, interval=interval, message=desc) db.session.add(new_alert) db.session.commit() return redirect("/bs_alerts")
def handleRfidData(): if request.method == "POST": data = request.form['rfid'] data = data[1:13] item = Item.query.filter_by(tagID=data).first() if item is not None: if item.status == 0: item.status = 1 else: item.status = 0 db.session.commit() day = weekdays[datetime.datetime.today().weekday()] print(day) time = str(datetime.datetime.now().hour) + ":" + str( datetime.datetime.now().minute) pattern = Pattern.query.filter_by(itemID=item.id, dayOfWeek=day).first() scheduleTime = pattern.startTime.split(",") schedulePresent = pattern.presentItem.split(",") print(scheduleTime) print(schedulePresent) found = binarySearch(scheduleTime, 0, len(scheduleTime) - 1, time) print(found) if item.status == 0: stat = 'false' else: stat = 'true' if found >= 0: if stat == schedulePresent[found]: print("No Problem!") else: if item.status == 0: str1 = "Item " + item.name + " had a problem. You needed it for class." else: str1 = "Item " + item.name + " had a problem. It is missing from the locker." recip = User.query.filter_by(id=item.userID).first() # sendEmailAlert(str1, recip) db.session.add( Alert(userID=item.userID, itemID=item.id, message=str1, dayOfWeek=day, time=time, status=1)) db.session.commit() print("The was a problem!") else: res = findSpot(scheduleTime, time) print(res) if stat == schedulePresent[res]: print("No Problem!") else: if item.status == 1: str1 = "Item " + item.name + " had a problem. You needed it for class." else: str1 = "Item " + item.name + " had a problem. It is missing from the locker." recip = User.query.filter_by(id=item.userID).first() # sendEmailAlert(str1, recip) db.session.add( Alert(userID=item.userID, itemID=item.id, message=str1, dayOfWeek=day, time=time, status=1)) db.session.commit() print("The was a problem!") return redirect(url_for('home'))
def check_time_status(): error = None items = Item.query.filter_by(userID=session['user_id']).all() if request.method == "POST": time = request.form["Hours"] + ":" + request.form["Minutes"] day = request.form["dayOfWeek"] pattern = Pattern.query.filter_by( userID=session['user_id'], itemID=request.form["item"], dayOfWeek=request.form["dayOfWeek"]).first() scheduleTime = pattern.startTime.split(",") schedulePresent = pattern.presentItem.split(",") found = binarySearch(scheduleTime, 0, len(scheduleTime) - 1, time) item = Item.query.filter_by(userID=session['user_id'], id=request.form['item']).first() data = request.form["found"] if found >= 0: if data == schedulePresent[found]: print("No Problem!") else: if data == "true": str1 = "Item " + item.name + " had a problem. You needed it for class." else: str1 = "Item " + item.name + " had a problem. It is missing from the locker." sendEmailAlert(str1) db.session.add( Alert(userID=session['user_id'], itemID=request.form['item'], message=str1, dayOfWeek=day, time=time, status=1)) db.session.commit() print("There was a problem!") else: res = findSpot(scheduleTime, time) print(res) if data == schedulePresent[res]: print("No Problem!") else: if data == "true": str1 = "Item " + item.name + " had a problem. You needed it for class." else: str1 = "Item " + item.name + " had a problem. It is missing from the locker." sendEmailAlert(str1) db.session.add( Alert(userID=session['user_id'], itemID=request.form['item'], message=str1, dayOfWeek=day, time=time, status=1)) db.session.commit() print("There was a problem!") return render_template("check.html", error=error, items=items, user=g.user)
def add_alert(): """Adds an alert to the dBase""" #The user is queried along with all associated alerts user = User.query.filter_by(email=session['current_user']).one() alerts_all = Alert.query.filter_by(user_id=user.user_id).all() #Gets the alert and alert set info from the form on the add a new rec set page name = request.form['a_name'] desc = request.form['descri'] interval = request.form['interval'] contacts = request.form.getlist('contact') time = request.form['time'] #If there is no interval, the variable is set to None if interval == "": interval = None #If no name is included, the name is set as the next sequential number if len(name) == 0: name = "Alert " + str(len(alerts_all)) #Current DateTime is queried dt = datetime.datetime.now() #Initiates 3 contact variables, sets the first to the first contact and the next two to None contact1 = int(contacts[0]) contact2 = None contact3 = None #If more than one contact is associated with the alert set, the following variables are set to them if len(contacts) > 1: contact2 = int(contacts[1]) if len(contacts) > 2: contact3 = int(contacts[2]) #A new alert (associated with the alert set) is created, added, and commited to the dBase new_alert = Alert(user_id=user.user_id, contact_id1=contact1, a_name=name, contact_id2=contact2, contact_id3=contact3, interval=interval, message=desc, time=time, active=False, status='Not Yet Activated') db.session.add(new_alert) db.session.commit() #The new alert is now queried alert = Alert.query.filter_by(a_name=name).order_by( Alert.alert_id.desc()).first() #The Variable "note" is created, which includes the text of the log entry note = "Check In " + str(name) + " For " + str( alert.time.strftime("%I:%M %p")) + " Created. " #If there is a message included in the alert, it is included in the log entry if desc: note += "The user included the following message: " + str(desc) + "." add_log_note(user.user_id, dt, "Check-In Added", note, time) return redirect("/bs_alerts")
jesus_contact = Contact(name="Jesus") jesus_contact.user = user_juan jesus_contact.phones.extend([cel_jesus, home_jesus]) #CREATE NATURAL DISASTERS & ALERTS natural_disaster_1 = NaturalDisaster( nat_type="Earthquake", title="Earthquake- M 4.6 - 21km SSE of Kettleman City, CA", latitude="37.689511", longitude="-122.468796", location="4km WSW of Daly City, CA", timestamp="2019-02-12 15:08:40 (UTC)") alert_1 = Alert( natural_disaster=natural_disaster_1, message= "Earthquake- M 4.6 - 21km SSE of Kettleman City, CA ******* User Location: 3098 E 10th St, Oakland, CA 94601 - User Coordinates (lat,lng): 37.776460, -122.228150 - Allergies: Penicillin, lactose, dogs - Medications: Metformin, Amlodipine" ) alert_1.user = user_fabio natural_disaster_2 = NaturalDisaster( nat_type="Earthquake", title="Earthquake- M 5.8 - 4km WSW of Daly City, CA", latitude="36.008795", longitude="-119.962860", location="21km SSE of Kettleman City, CA", timestamp="2019-05-8 03:03:30 (UTC)") alert_2 = Alert( natural_disaster=natural_disaster_2, message= "Earthquake- M 5.8 - 4km WSW of Daly City, CA ******** User Location: 683 Sutter St, San Francisco, CA 94109 - User Coordinates (lat,lng): 37.787970, -122.418470 - Allergies: Aspirin, seafood, nuts, cats - Medications: Lipitor, Lisinopril"