forked from sydney-linux-user-group/slug
-
Notifications
You must be signed in to change notification settings - Fork 0
/
response.py
100 lines (81 loc) · 3.24 KB
/
response.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#!/usr/bin/python
#
# -*- coding: utf-8 -*-
# vim: set ts=4 sw=4 et sts=4 ai:
"""Module for dealing with people's RSVPs."""
import config
config.setup()
import logging
from google.appengine.ext import webapp
from google.appengine.api import users
import models
import event_lists
from utils.render import render
class ShowResponsePage(webapp.RequestHandler):
"""Showing an RSVP."""
def get(self, eventid):
# We use locals() which confuses pylint.
# pylint: disable-msg=W0612
####################################################
event = models.Event.get_by_id(long(eventid))
if not event:
self.redirect('/')
current_user = users.get_current_user()
if not current_user:
self.redirect('/')
return
####################################################
response, guests = event_lists.get_event_responses(event, current_user)
self.response.out.write(render(
'templates/response-show.html', locals()))
class UpdateResponsePage(webapp.RequestHandler):
"""Update an RSVP."""
def post(self, eventid):
# We use locals() which confuses pylint.
# pylint: disable-msg=W0612
####################################################
event = models.Event.get_by_id(long(eventid))
if not event:
self.redirect('/')
current_user = users.get_current_user()
if not current_user:
self.redirect('/')
return
####################################################
response, guests = event_lists.get_event_responses(event, current_user)
# Check if the person is trying to add friends
try:
extra_guests = range(
0, int(self.request.get('friends', '0'))-len(guests))
except ValueError:
extra_guests = []
if extra_guests:
self.response.out.write(render(
'templates/response-friends.html', locals()))
return
# Remove the current information
if response is not None:
response.delete()
for guest in guests:
guest.delete()
response = models.Response(event=event, gcreated_by = current_user,
guest=False)
response.attending = self.request.get('attending').lower() != 'no'
response.put()
logging.info('Response %s created by user %s (email: %s fedid: %s)',
response.key(), current_user.nickname(), current_user.email(),
current_user.federated_identity() )
guest_names = self.request.get_all('guest_name')
guest_emails = self.request.get_all('guest_email')
assert len(guest_names) == len(guest_emails)
for name, email in zip(guest_names, guest_emails):
name, email = name.strip(), email.strip()
if not name or not email:
continue
response = models.Response(event=event, guest=True,
gcreated_by = current_user)
response.attending = True
response.guest_name = name
response.guest_email = email
response.put()
self.redirect('/event/%s/response/show' % event.key().id())