def index(request): logger.info("Rendering page") context = {} images = FrontPagePhoto.objects.order_by('weight').filter(visible=True) if images: context['images'] = [img.to_json() for img in images] return render(request, 'web/wedding/index.html', context)
def extract_guests(data, guest_count): guest_list = [] errors = [] for i in xrange(1, guest_count+1): name = data.get('guest_name_%s' % i) attending = data.get('guest_select_%s' % i) == 'Yes' food_choice = data.get('guest_food_%s' % i) guest = {'count':i, 'name':name, 'food_choice':food_choice, 'attending':attending} logger.info(guest) if attending: if not name: name = 'Guest %s' % i errors.append("Name missing for %s" % name) if food_choice == 'N/A': errors.append("Food choice missing for %s" % name) guest_list.append(guest) #No name and not attending == Not a guest return guest_list, errors
def email(request): context = {} errors = [] if request.method == 'POST': data = request.POST.dict() context.update(data) # Preserve data sent on POST logger.info('POST DATA:%s' % data) email_sent, errors = send_email(data) if errors: logger.warn('MAIL ERRORS: %s' % ', '.join(errors)) if email_sent: #Data has been sent, lets clear it out context = {} context['success'] = True context['errors'] = errors logger.info('CONTEXT: %s' % context) context.update(csrf(request)) return render(request, 'web/email.html', context)
def rsvp(request): context = {} GUEST_COUNT = 5 empty_guest_list = [] for i in xrange(1, GUEST_COUNT+1): empty_guest_list.append({'count':i, 'name':'', 'food_choice':'N/A'}) context.update({'guest_list':empty_guest_list}) if request.method == 'POST': data = request.POST.dict() logger.info(data) context.update(data) # Preserve data sent on POST guest_list, errors = extract_guests(data, 5) if guest_list: context.update({'guest_list':guest_list}) if not guest_list and data.get('message'): errors.append('You must RSVP to send a message') if errors: context['errors'] = errors if guest_list and not errors: context.update({'guest_list':guest_list}) logger.info(guest_list) rsvp_mail = "Message:%s\n" % data.get('message','No message included.') for guest in guest_list: if not guest['name']: continue first,last = Guest.split_name(guest['name']) guest_obj = Guest.objects.get_or_create( first_name=first, last_name=last)[0] guest_obj.atending = guest['attending'] guest_obj.food_choice = guest['food_choice'] guest_obj.save() rsvp_mail += "%s: Attending:%s%s\n" %\ (guest['name'], guest['attending'], ' Food Choice:%s' % guest['food_choice'] if guest['attending'] else '', ) email_sent = send_email_to_admin('Wedding', 'RSVP', '*****@*****.**', 'Wedding RSVP', rsvp_mail) context = {} context.update({'guest_list':empty_guest_list}) context['success'] = True logger.info("context = %s" % context) context.update(csrf(request)) return render(request, 'web/wedding/rsvp.html', context)
def menu(request): logger.info("Rendering page") context = {} return render(request, 'web/wedding/menu.html', context)
def home(request): logger.info("Rendering home page") logger.info(request) context = {} return render(request, 'web/main.html', context)