def rsvp(event_id): """RSVP to an event.""" # TODO: Get the event with the given id from the database is_returning_guest = request.form.get('returning') guest_name = request.form.get('guest_name') event = Event.query.filter_by(name=guest_name).one() if is_returning_guest: # TODO: Look up the guest by name, and add the event to their # events_attending, then commit to the database guest = Guest.query.filter_by(name=guest_name).one() if guest is not None: guest.events_attending.append(event) db.session.add(guest) db.session.commit() else: print("No user found") else: guest_email = request.form.get('email') guest_phone = request.form.get('phone') # TODO: Create a new guest with the given name, email, and phone, and # add the event to their events_attending, then commit to the database new_guest = Guest(name=guest_name, email=guest_email, phone=guest_phone) new_guest.events_attending.append(event) db.session.add(new_guest) db.session.commit() flash('You have successfully RSVP\'d! See you there!') return redirect(url_for('main.event_detail', event_id=event_id))
def show_guests(): """ Show guests that have RSVP'd. Add guests to RSVP list if method is POST. """ events = Event.query.all() if request.method == "GET": return render_template("guests.html", events=events) elif request.method == "POST": name = request.form.get("name") email = request.form.get("email") plus_one = request.form.get("plus-one") phone = request.form.get("phone") event_id = request.form.get("event_id") event = Event.query.filter_by(id=event_id).first() guest = Guest( name=name, email=email, plus_one=plus_one, phone=phone, events_attending=[], ) event.guests.append(guest) db.session.add(guest) db.session.commit() return render_template("guests.html", events=events)
def rsvp(event_id): """RSVP to an event.""" event = Event.query.filter_by(id=event_id).one() is_returning_guest = request.form.get('returning') guest_name = request.form.get('guest_name') if is_returning_guest: guest = Guest.query.filter_by(name=guest_name).one() guest.events_attending.append(event) db.session.add(guest) db.session.commit() else: guest_email = request.form.get('email') guest_phone = request.form.get('phone') new_guest = Guest(name=guest_name, email=guest_email, phone=guest_phone) db.session.add(new_guest) db.session.commit() guest = Guest.query.filter_by(name=guest_name).one() guest.events_attending.append(event) db.session.add(guest) db.session.commit() flash('You have successfully RSVP\'d! See you there!') return redirect(url_for('main.event_detail', event_id=event_id))
def rsvp(event_id): """RSVP to an event.""" # TODO: Get the event with the given id from the database event = Event.query.get(event_id) is_returning_guest = request.form.get('returning') guest_name = request.form.get('guest_name') if is_returning_guest: guest = Guest.query.filter_by(name=guest_name) guest.events_attending.append(event) db.session.add(guest) db.session.commit() pass else: guest_email = request.form.get('email') guest_phone = request.form.get('phone') guest = Guest(name=guest_name, email=guest_email, phone=guest_phone) guest.events_attending.append(event) db.session.add(guest) db.session.commit() pass flash('You have successfully RSVP\'d! See you there!') return redirect(url_for('main.event_detail', event_id=event_id))
def rsvp(event_id): """RSVP to an event.""" is_returning_guest = request.form.get("returning") guest_name = request.form.get("guest_name") event = Event.query.filter_by(id=event_id).one() if is_returning_guest: guest = Guest.query.filter_by(name=guest_name).one() if guest == None: print("No such guest") else: guest.events_attending.append(event) db.session.add(guest) db.session.commit() else: guest_email = request.form.get("email") guest_phone = request.form.get("phone") new_guest = Guest(name=guest_name, email=guest_email, phone=guest_phone) new_guest.events_attending.append(event) db.session.add(new_guest) db.session.commit() flash("You have successfully RSVP'd! See you there!") return redirect(url_for("main.event_detail", event_id=event_id))
def rsvp(event_id): """RSVP to an event.""" event = Event.query.get(event_id) is_returning_guest = request.form.get("returning") guest_name = request.form.get("guest_name") if is_returning_guest: guest = Guest.query.filter_by(name=guest_name).first() event.guests.append(guest) db.session.commit() else: guest_email = request.form.get("email") guest_phone = request.form.get("phone") guest = Guest(name=guest_name, email=guest_email, phone=guest_phone) event.guests.append(guest) db.session.add(guest) db.session.commit() pass flash("You have successfully RSVP'd! See you there!") return redirect(url_for("main.event_detail", event_id=event_id))
def show_guests(): """ Show guests that have RSVP'd. Add guests to RSVP list if method is POST. """ events = Event.query.all() data = [{ "name": event.title, "description": event.description, "date": event.date.strftime("%M-%d-%Y"), "time": event.time.strftime("%H:%M"), } for event in events] if request.method == "GET": return jsonify({"data": data}), 200 elif request.method == "POST": name = request.form.get("name") email = request.form.get("email") plus_one = request.form.get("plus-one") phone = request.form.get("phone") event_id = request.form.get("event_id") event = Event.query.filter_by(id=event_id).first() guest = Guest( name=name, email=email, plus_one=plus_one, phone=phone, events_attending=[], ) event.guests.append(guest) print(f"Event guests: {event.guests}") db.session.add(guest) db.session.commit() return jsonify({"msg": "new guest added.", "data": data})
def rsvp(event_id): """RSVP to an event.""" # TODO: Get the event with the given id from the database is_returning_guest = request.form.get('returning') guest_name = request.form.get('guest_name') event = Event.query.filter_by(id=event_id).one() if is_returning_guest: # TODO: Look up the guest by name, and add the event to their # events_attending, then commit to the database try: guest = Guest.query.filter_by(name=guest_name).one() except: flash("You are not recurring Guest! Register Again") return redirect(url_for("main.event_detail", event_id=event_id)) else: guest_email = request.form.get('email') guest_phone = request.form.get('phone') # TODO: Create a new guest with the given name, email, and phone, and # add the event to their events_attending, then commit to the database guest = Guest(name=guest_name, email=guest_email, phone=guest_phone) guest.events_attending.append(event) db.session.add(guest) db.session.commit() flash('You have successfully RSVP\'d! See you there!') return redirect(url_for('main.event_detail', event_id=event_id)) @main.route('/create', methods=['GET', 'POST']) def create(): """Create a new event.""" if request.method == 'POST': new_event_title = request.form.get('title') new_event_description = request.form.get('description') date = request.form.get('date') time = request.form.get('time') try: date_and_time = datetime.strptime( f'{date} {time}', '%Y-%m-%d %H:%M') except ValueError: print('there was an error: incorrect datetime format') # TODO: Create a new event with the given title, description, & # datetime, then add and commit to the database new_event = Event( title=new_event_title, description=new_event_description, date_and_time=date_and_time, ) db.session.add(new_event) db.session.commit() flash('Event created.') return redirect(url_for('main.index')) else: return render_template('create.html') @main.route('/guest/<guest_id>') def guest_detail(guest_id): # TODO: Get the guest with the given id and send to the template guest = "" try: guest = Guest.query.filter_by(id=guest_id).one() except: print("No Guest Was Found") return render_template('guest_detail.html', guest=guest, events_attending=guest.events_attending)