def post(self, request, *args, **kwargs): try: slug = self.kwargs['slug'] rsvp_form = RSVPForm(request.POST) event = get_object_or_404(Event, slug=slug ) if not rsvp_form.is_valid(): # THis is so that we maintain state # The previous filled form is not lost variables = {'form': rsvp_form, 'event': event } return render(request, self.template_name, variables ) # Validate the CAPTCHA try: captcha_resp = request.REQUEST['g-recaptcha-response'] except: variables = {'form': rsvp_form, 'event': event } return render(request, self.template_name, variables ) remote_ip = utils.get_client_ip(request) captcha_validity = utils.validateCaptcha(captcha_resp, remote_ip) if not captcha_validity: rsvp_form.add_error('captcha_field_hidden',"reCAPTCHA is not complete or incorrect. Complete the CAPTCHA to proceed") variables = {'form': rsvp_form, 'event': event } return render(request, self.template_name, variables ) # Pulling out values from the request guest_email = request.REQUEST['your_email'] guest_name = request.REQUEST['name'] guest_associated_organization = request.REQUEST['associated_organization'] guest_attending_status = request.REQUEST['will_you_be_attending'] guest_is_student = request.REQUEST['are_you_a_student'] guest_wants_updates = False # We have to do this since the field is a Boolean check box. # Not clicking true is going to not return anything if request.REQUEST.has_key('receive_email_updates_for_this_event'): guest_wants_updates = request.REQUEST['receive_email_updates_for_this_event'] # Getting current RSVP count so that we are not above limit rsvp_count = Guest.objects.filter(Q(attending_status='yes') & Q(event_id=event.id)).count() if rsvp_count >= event.maximum_attendees: return HttpResponseRedirect('/rsvp/event/%s/full/' % slug ) # Checking if this email ID has been used to RSVP before is_guest_present = Guest.objects.filter(Q(email=guest_email) & Q(event_id=event.id)) if is_guest_present: return HttpResponseRedirect('/rsvp/event/%s/duplicate/' % slug ) Guest.objects.create(event=event, email=guest_email, name=guest_name, attending_status=guest_attending_status,associated_organization=guest_associated_organization, is_student=guest_is_student, wants_updates= guest_wants_updates) # If denied RSVP if guest_attending_status.lower() == 'no': return HttpResponseRedirect('/rsvp/event/%s/deniedrsvp/' % slug ) # Accept RSVP. if guest_wants_updates: venue_info = [event.hosted_by, event.street_address, event.city, event.state ] utils.sendConfirmationEmail(guest_email, guest_name, event.title, event.description, localtime(event.date_of_event), venue_info, event.speaker) return HttpResponseRedirect('/rsvp/event/%s/thanks/' % slug ) except Exception, exp: print "Exception: ",exp return HttpResponseRedirect('/rsvp/event/%s/failed/' % slug )
def new_rsvp(event_id): if session.get('user'): rsvp_form = RSVPForm() # validate_on_submit only validates using POST if rsvp_form.validate_on_submit(): new_rsvp = RSVP(event_id, session['user_id']) db.session.add(new_rsvp) db.session.commit() return redirect(url_for('get_event', event_id=event_id)) else: return redirect(url_for('login'))
def new_report(event_id): if session.get('user'): rsvp_form = RSVPForm() # validate_on_submit only validates using POST if rsvp_form.validate_on_submit(): new_report = report(event_id, session['user_id']) db.session.add(new_report) db.session.commit() #my_report = db.session.query(User).filter_by(id=user_id).one() #return render_template('reports.html', account=my_report, user=session['user']) return redirect(url_for('get_reports', user_id=User.id)) else: return redirect(url_for('login'))
def main(request): if request.method == 'POST': fs = RSVPForm(request.POST) if fs.is_valid(): fs.save() f = RSVPForm() thanks = True else: f = fs thanks = False else: f = RSVPForm() thanks = False return render_to_response('rsvp/main.html', {'form': f, 'thanks': thanks}, context_instance=RequestContext(request))
def start(request): if request.method == "POST": form = RSVPForm(data=request.POST) if form.is_valid() or not request.POST.get('coming'): if RSVP.objects.filter(user=request.user): rsvp =RSVP.objects.get(user=request.user) else: rsvp =RSVP.objects.create(user=request.user, food={}) if not request.POST.get('coming'): rsvp.coming = False rsvp.save() return HttpResponseRedirect(reverse('rsvp:shame')) people = form.cleaned_data['people'] people = [x.strip() for x in people.splitlines() if x.strip()] rsvp.people = people rsvp.no_people = len(people) rsvp.save() return HttpResponseRedirect(reverse('rsvp:food')) else: print form.errors else: person_name = '%s %s' % (request.user.first_name, request.user.last_name) if RSVP.objects.filter(user=request.user): rsvp = RSVP.objects.get(user=request.user) people = rsvp.people person_name = person_name.strip() if person_name not in people: people.insert(0, person_name) coming = rsvp.coming initial = dict(people='\n'.join(people), song_requests=rsvp.song_requests) else: initial = dict(people=person_name) form = RSVPForm(initial=initial) return locals()
def get_event(event_id): if session.get('user'): my_event = db.session.query(Event).filter_by(id=event_id).one() form_comment = CommentForm() event_rsvps = db.session.query(RSVP).filter_by(event_id=event_id).all() form_rsvp = RSVPForm() print(event_rsvps) return render_template('event.html', event=my_event, user=session['user'], form_comment=form_comment, form_rsvp=form_rsvp, rsvps=event_rsvps) else: return redirect(url_for('login'))
def post(self, request, *args, **kwargs): try: slug = self.kwargs['slug'] rsvp_form = RSVPForm(request.POST) event = get_object_or_404(Event, slug=slug) if not rsvp_form.is_valid(): # THis is so that we maintain state # The previous filled form is not lost variables = {'form': rsvp_form, 'event': event} return render(request, self.template_name, variables) # Validate the CAPTCHA try: captcha_resp = request.REQUEST['g-recaptcha-response'] except: variables = {'form': rsvp_form, 'event': event} return render(request, self.template_name, variables) remote_ip = utils.get_client_ip(request) captcha_validity = utils.validateCaptcha(captcha_resp, remote_ip) if not captcha_validity: rsvp_form.add_error( 'captcha_field_hidden', "reCAPTCHA is not complete or incorrect. Complete the CAPTCHA to proceed" ) variables = {'form': rsvp_form, 'event': event} return render(request, self.template_name, variables) # Pulling out values from the request guest_email = request.REQUEST['your_email'] guest_name = request.REQUEST['name'] guest_associated_organization = request.REQUEST[ 'associated_organization'] guest_attending_status = request.REQUEST['will_you_be_attending'] guest_is_student = request.REQUEST['are_you_a_student'] guest_wants_updates = False # We have to do this since the field is a Boolean check box. # Not clicking true is going to not return anything if request.REQUEST.has_key('receive_email_updates_for_this_event'): guest_wants_updates = request.REQUEST[ 'receive_email_updates_for_this_event'] # Getting current RSVP count so that we are not above limit rsvp_count = Guest.objects.filter( Q(attending_status='yes') & Q(event_id=event.id)).count() if rsvp_count >= event.maximum_attendees: return HttpResponseRedirect('/rsvp/event/%s/full/' % slug) # Checking if this email ID has been used to RSVP before is_guest_present = Guest.objects.filter( Q(email=guest_email) & Q(event_id=event.id)) if is_guest_present: return HttpResponseRedirect('/rsvp/event/%s/duplicate/' % slug) Guest.objects.create( event=event, email=guest_email, name=guest_name, attending_status=guest_attending_status, associated_organization=guest_associated_organization, is_student=guest_is_student, wants_updates=guest_wants_updates) # If denied RSVP if guest_attending_status.lower() == 'no': return HttpResponseRedirect('/rsvp/event/%s/deniedrsvp/' % slug) # Accept RSVP. if guest_wants_updates: venue_info = [ event.hosted_by, event.street_address, event.city, event.state ] utils.sendConfirmationEmail(guest_email, guest_name, event.title, event.description, localtime(event.date_of_event), venue_info, event.speaker) return HttpResponseRedirect('/rsvp/event/%s/thanks/' % slug) except Exception, exp: print "Exception: ", exp return HttpResponseRedirect('/rsvp/event/%s/failed/' % slug)