def rsvp(username): user = User.query.filter_by(username=username).first_or_404() dinner_parties = DinnerParty.query.all() if dinner_parties is None: dinner_parties = [] form = RsvpForm(csrf_enabled=False) if form.validate_on_submit(): dinner_party = DinnerParty.query.filter_by( id=int(form.party_id.data)).first() # try block try: dinner_party.attendees += f", {username}" db.session.commit() # query to find the host of dinner_party host = User.query.filter_by( id=int(dinner_party.party_host_id)).first() # add RSVP success message here: flash( f"You successfully RSVP'd to {host.username}'s dinner party on {dinner_party.date}!" ) # except block except: # add the RSVP failure message here flash("Please enter a valid Party ID to RSVP!") return render_template('rsvp.html', user=user, dinner_parties=dinner_parties, form=form)
def detail(request, event_id, token=None): nav_selected = "events" event = get_object_or_404(Event, id=event_id) guest = event.current_guest(request, token) has_manager_privileges = event.has_manager_privileges(request.user) if not has_manager_privileges: rsvp_form = RsvpForm(instance=guest, initial={"token": token, "rsvp_status": "A"}) return render_to_response("events/detail.html", locals(), context_instance=RequestContext(request))
def rsvp(request, event_id): event = get_object_or_404(Event, id=event_id) guest = event.current_guest(request=request, token=request.POST.get("token", None)) rsvp_form = RsvpForm(instance=guest, data=request.POST) if rsvp_form.is_valid(): guest = rsvp_form.store(request) if guest.contributor.needs_more_info(): return redirect("event-rsvp-confirm", event_id=event.id) else: rsvp_form.save() return redirect(event) return render_to_response("events/show.html", locals(), context_instance=RequestContext(request))
def rsvp(username): user = User.query.filter_by(username=username).first_or_404() dinner_parties = DinnerParty.query.all() if dinner_parties is None: dinner_parties = [] form = RsvpForm(csrf_enabled=False) if form.validate_on_submit(): # query the DinnerParty model here: dinner_party = DinnerParty.query.filter_by( id=int(form.party_id.data)).first() # update the attendees here: dinner_party.attendees += f", {username}" db.session.commit() return render_template('rsvp.html', user=user, dinner_parties=dinner_parties, form=form)