Ejemplo n.º 1
0
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)
Ejemplo n.º 2
0
def rsvp():
    form = RsvpForm()
    if 'guestid' not in session:
        return redirect(url_for('login'))
    guests = Guest.query.filter_by(group=session['group']).all()

    if request.method == 'POST' and form.validate():
        #if form.validate_on_submit():
            #testg = Rsvp(2, 1, 'friday','afternoon',0)
            #return testg
            #db.session.add(testg)
            msg = Message("Thank you for your RSVP", sender=("Name", "*****@*****.**"))
            msg.bcc = ("*****@*****.**","*****@*****.**")
            for i in guests:
                msg.add_recipient(i.email_address)
                #return i.id
                #gid = i.id
                #logging.debug("this is i.id: ", i.id)
                #rsvpi = Rsvp(gid, form.i['id'].data, form.arrival_date.data, form.arrival_time.data, form.child_care.data, 1)
                radioname = "guest" + str(i.id)
                radval = form[radioname].data
                radval = str(radval)
 		if radval not in ('0','1'): radval = -1
                #if i.id == session['guestid']: session['response'] = radval
                ccval = form.child_care.data
                if ccval not in ('0','1'): ccval = -1
                rsvpi = Rsvp(i.id, radval, form.notebox.data, form.arrival_date.data, form.arrival_time.data, ccval, 1 )
                db.session.add(rsvpi)
            db.session.commit()
            rsvp_response0 = GuestRsvp.query.filter_by(id=session['guestid']).first()
            rsvp_response1 = GuestRsvp.query.filter_by(group=session['group']).all()
            #msg.body = "Insert receipt email here" # text body
            msg.body = render_template('rsvp-thank-you-email.txt', rsvp0=rsvp_response0, rsvpr=rsvp_response1)
            msg.html = render_template('rsvp-thank-you-email.html', rsvp0=rsvp_response0, rsvpr=rsvp_response1)
            mail.send(msg)
            return redirect(url_for('rsvp'))
        #else:
            #return "Didn't work"

    glist = []
    for j in guests:
        glist.append(j.id)

    rsvp_response0 = GuestRsvp.query.filter_by(id=session['guestid']).first()
    rsvp_response = GuestRsvp.query.filter_by(group=session['group']).all()
    for r in rsvp_response:
        if r.id == session['guestid']:
            session['response'] = r.response

    if rsvp_response:
        return render_template('rsvp-thank-you.html', rsvpr=rsvp_response, guests=guests, glist=glist, rsvp0=rsvp_response0)

    return render_template('rsvp.html', form=form, guests=guests)
Ejemplo n.º 3
0
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))
Ejemplo n.º 4
0
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)
Ejemplo n.º 5
0
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))