Skip to content
Newer
Older
100755 254 lines (233 sloc) 10.4 KB
8414350 @billsaysthis multiline for details and notes fields
billsaysthis authored Jun 22, 2010
1 import cgi
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
2 from google.appengine.ext import webapp, db
3 from google.appengine.ext.webapp import util, template
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 4, 2010
4 from google.appengine.api import urlfetch, memcache, users, mail
5
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
6 from django.utils import simplejson
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 21, 2010
7 from django.template.defaultfilters import slugify
5cd04ac Fixed iCalendar-related imports, and added the end date to the
Matt Hancher authored Apr 29, 2010
8 from icalendar import Calendar
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
9 import logging, urllib
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
10
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
11 from datetime import datetime, timedelta
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
12
81a81e1 @progrium adding errors for form validation, full notifications, and minor edit…
progrium authored Apr 18, 2010
13 from models import Event, Feedback, ROOM_OPTIONS, GUESTS_PER_STAFF, PENDING_LIFETIME
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
14 from utils import dojo, username, human_username, set_cookie, local_today
81a81e1 @progrium adding errors for form validation, full notifications, and minor edit…
progrium authored Apr 18, 2010
15 from notices import *
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 17, 2010
16
e2b9558 @btubbs Fixes issue 4. Changed to jqueryUI datepicker. Replaced jquery
btubbs authored May 1, 2010
17 class ExpireCron(webapp.RequestHandler):
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
18 def post(self):
19 # Expire events marked to expire today
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
20 today = local_today()
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
21 events = Event.all() \
22 .filter('status IN', ['pending', 'understaffed']) \
23 .filter('expired >=', today) \
24 .filter('expired <', today + timedelta(days=1))
25 for event in events:
26 event.expire()
27 notify_owner_expired(event)
28
29 class ExpireReminderCron(webapp.RequestHandler):
30 def post(self):
31 # Find events expiring in 10 days to warn owner
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
32 ten_days = local_today() + timedelta(days=10)
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
33 events = Event.all() \
34 .filter('status IN', ['pending', 'understaffed']) \
35 .filter('expired >=', ten_days) \
36 .filter('expired <', ten_days + timedelta(days=1))
37 for event in events:
38 notify_owner_expiring(event)
39
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
40 class EventsHandler(webapp.RequestHandler):
41 def get(self, format):
42 if format == 'ics':
43 events = Event.all().filter('status IN', ['approved', 'canceled']).order('start_time')
44 cal = Calendar()
45 for event in events:
46 cal.add_component(event.to_ical())
47 self.response.headers['content-type'] = 'text/calendar'
48 self.response.out.write(cal.as_string())
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
49
50 class EventHandler(webapp.RequestHandler):
51 def get(self, id):
52 event = Event.get_by_id(int(id))
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
53 user = users.get_current_user()
54 if user:
55 is_admin = username(user) in dojo('/groups/events')
56 is_staff = username(user) in dojo('/groups/staff')
57 can_approve = (event.status in ['pending'] and is_admin)
58 can_staff = (event.status in ['pending', 'understaffed', 'approved'] and is_staff and not user in event.staff)
72849c2 @billsaysthis added unstaff event, including email notification if event becomes un…
billsaysthis authored Jun 22, 2010
59 can_unstaff = (not event.status in ['canceled', 'deleted'] and is_staff and user in event.staff)
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
60 logout_url = users.create_logout_url('/')
61 else:
62 login_url = users.create_login_url('/')
8414350 @billsaysthis multiline for details and notes fields
billsaysthis authored Jun 23, 2010
63 event.details = event.details.replace("\n","<br/>")
64 event.notes = event.notes.replace("\n","<br/>")
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
65 self.response.out.write(template.render('templates/event.html', locals()))
e2b9558 @btubbs Fixes issue 4. Changed to jqueryUI datepicker. Replaced jquery
btubbs authored May 1, 2010
66
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
67 def post(self, id):
68 event = Event.get_by_id(int(id))
69 user = users.get_current_user()
70 is_admin = username(user) in dojo('/groups/events')
71 is_staff = username(user) in dojo('/groups/staff')
72 state = self.request.get('state')
73 if state:
74 if state.lower() == 'approve' and is_admin:
75 event.approve()
76 if state.lower() == 'staff' and is_staff:
77 event.add_staff(user)
72849c2 @billsaysthis added unstaff event, including email notification if event becomes un…
billsaysthis authored Jun 23, 2010
78 if state.lower() == 'unstaff' and is_staff:
79 event.remove_staff(user)
80 # send notification is state changed to understaffed
81 if event.status == 'understaffed':
82 notify_unapproved_unstaff_event(event)
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
83 if state.lower() == 'cancel' and is_admin:
84 event.cancel()
a67ac50 @mdhancher Add a simple admin-only event delete and undelete.
mdhancher authored May 12, 2010
85 if state.lower() == 'delete' and is_admin:
86 event.delete()
87 if state.lower() == 'undelete' and is_admin:
88 event.undelete()
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
89 if state.lower() == 'expire' and is_admin:
90 event.expire()
e2b9558 @btubbs Fixes issue 4. Changed to jqueryUI datepicker. Replaced jquery
btubbs authored May 1, 2010
91
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
92 if event.status == 'approved':
93 notify_owner_approved(event)
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
94 self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name)))
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
95
96 class ApprovedHandler(webapp.RequestHandler):
97 def get(self):
98 user = users.get_current_user()
99 if user:
100 logout_url = users.create_logout_url('/')
101 else:
102 login_url = users.create_login_url('/')
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
103 today = local_today()
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
104 events = Event.get_approved_list()
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
105 tomorrow = today + timedelta(days=1)
d63161a Add widget mode
Brian Klug authored Jun 8, 2010
106 whichbase = 'base.html'
107 if self.request.get('base'):
108 whichbase = self.request.get('base') + ".html"
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
109 self.response.out.write(template.render('templates/approved.html', locals()))
110
a82b43e @billsaysthis add myevents, pastevents code, refined list display on event page
billsaysthis authored Apr 1, 2010
111 class MyEventsHandler(webapp.RequestHandler):
112 @util.login_required
113 def get(self):
114 user = users.get_current_user()
115 if user:
116 logout_url = users.create_logout_url('/')
117 else:
118 login_url = users.create_login_url('/')
119 events = Event.all().filter('member = ', user).order('start_time')
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
120 today = local_today()
a82b43e @billsaysthis add myevents, pastevents code, refined list display on event page
billsaysthis authored Apr 1, 2010
121 tomorrow = today + timedelta(days=1)
122 is_admin = username(user) in dojo('/groups/events')
123 self.response.out.write(template.render('templates/myevents.html', locals()))
124
125 class PastHandler(webapp.RequestHandler):
126 def get(self):
127 user = users.get_current_user()
128 if user:
129 logout_url = users.create_logout_url('/')
130 else:
131 login_url = users.create_login_url('/')
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
132 today = local_today()
d75579f @progrium minor updates here and there to bills contributions.
progrium authored Apr 6, 2010
133 events = Event.all().filter('start_time < ', today).order('-start_time')
a82b43e @billsaysthis add myevents, pastevents code, refined list display on event page
billsaysthis authored Apr 1, 2010
134 is_admin = username(user) in dojo('/groups/events')
135 self.response.out.write(template.render('templates/past.html', locals()))
136
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
137 class PendingHandler(webapp.RequestHandler):
138 def get(self):
139 user = users.get_current_user()
140 if user:
141 logout_url = users.create_logout_url('/')
142 else:
143 login_url = users.create_login_url('/')
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
144 events = Event.get_pending_list()
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
145 today = local_today()
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
146 tomorrow = today + timedelta(days=1)
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
147 is_admin = username(user) in dojo('/groups/events')
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
148 self.response.out.write(template.render('templates/pending.html', locals()))
149
150 class NewHandler(webapp.RequestHandler):
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
151 @util.login_required
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
152 def get(self):
153 user = users.get_current_user()
154 if user:
155 logout_url = users.create_logout_url('/')
156 else:
157 login_url = users.create_login_url('/')
158 rooms = ROOM_OPTIONS
159 self.response.out.write(template.render('templates/new.html', locals()))
e2b9558 @btubbs Fixes issue 4. Changed to jqueryUI datepicker. Replaced jquery
btubbs authored May 1, 2010
160
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
161 def post(self):
162 user = users.get_current_user()
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
163 try:
164 start_time = datetime.strptime("%s %s:%s %s" % (
165 self.request.get('date'),
166 self.request.get('start_time_hour'),
167 self.request.get('start_time_minute'),
e2b9558 @btubbs Fixes issue 4. Changed to jqueryUI datepicker. Replaced jquery
btubbs authored May 1, 2010
168 self.request.get('start_time_ampm')), "%m/%d/%Y %I:%M %p")
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
169 end_time = datetime.strptime("%s %s:%s %s" % (
170 self.request.get('date'),
171 self.request.get('end_time_hour'),
172 self.request.get('end_time_minute'),
e2b9558 @btubbs Fixes issue 4. Changed to jqueryUI datepicker. Replaced jquery
btubbs authored May 1, 2010
173 self.request.get('end_time_ampm')), "%m/%d/%Y %I:%M %p")
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
174 if (end_time-start_time).days < 0:
175 raise ValueError("End time must be after start time")
176 else:
177 event = Event(
178 name = self.request.get('name'),
179 start_time = start_time,
180 end_time = end_time,
181 type = self.request.get('type'),
182 estimated_size = self.request.get('estimated_size'),
183 contact_name = self.request.get('contact_name'),
184 contact_phone = self.request.get('contact_phone'),
8414350 @billsaysthis multiline for details and notes fields
billsaysthis authored Jun 23, 2010
185 details = cgi.escape(self.request.get('details')),
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
186 url = self.request.get('url'),
187 fee = self.request.get('fee'),
8414350 @billsaysthis multiline for details and notes fields
billsaysthis authored Jun 23, 2010
188 notes = cgi.escape(self.request.get('notes')),
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
189 rooms = self.request.get_all('rooms'),
b879063 @mdhancher Respect the local timezone (Pacific), and tidy up related imports.
mdhancher authored May 13, 2010
190 expired = local_today() + timedelta(days=PENDING_LIFETIME), # Set expected expiration date
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
191 )
192 event.put()
193 notify_owner_confirmation(event)
194 if not event.is_staffed():
195 notify_staff_needed(event)
196 notify_new_event(event)
81a81e1 @progrium adding errors for form validation, full notifications, and minor edit…
progrium authored Apr 18, 2010
197 set_cookie(self.response.headers, 'formvalues', None)
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
198 self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name)))
81a81e1 @progrium adding errors for form validation, full notifications, and minor edit…
progrium authored Apr 18, 2010
199 except Exception, e:
200 message = str(e)
201 if 'match format' in message:
202 message = "Date is required."
203 if message.startswith('Property'):
204 message = message[9:].replace('_', ' ').capitalize()
205 set_cookie(self.response.headers, 'formerror', message)
7742592 @progrium start of maintaining form state on errors
progrium authored Apr 18, 2010
206 set_cookie(self.response.headers, 'formvalues', dict(self.request.POST))
207 self.redirect('/new')
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
208
d2c3dc7 @billsaysthis moved app-specific js to separate file
billsaysthis authored Apr 19, 2010
209
210 class FeedbackHandler(webapp.RequestHandler):
211 @util.login_required
212 def get(self, event_id):
213 user = users.get_current_user()
214 event = Event.get_by_id(int(event_id))
215 if user:
216 logout_url = users.create_logout_url('/')
217 else:
218 login_url = users.create_login_url('/')
219 self.response.out.write(template.render('templates/feedback.html', locals()))
220
221 def post(self, event_id):
222 user = users.get_current_user()
223 event = Event.get_by_id(int(event_id))
8c52522 @billsaysthis small tweak to how feedbacks displayed in event page
billsaysthis authored Apr 19, 2010
224 try:
225 if self.request.get('rating'):
226 feedback = Feedback(
227 event = event,
228 rating = int(self.request.get('rating')),
229 comment = self.request.get('comment'))
230 feedback.put()
231 self.redirect('/event/%s-%s' % (event.key().id(), slugify(event.name)))
232 else:
233 raise ValueError("Please select a rating")
234 except Exception:
235 set_cookie(self.response.headers, 'formvalues', dict(self.request.POST))
236 self.redirect('/feedback/new/'+event_id)
d2c3dc7 @billsaysthis moved app-specific js to separate file
billsaysthis authored Apr 19, 2010
237
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
238 def main():
239 application = webapp.WSGIApplication([
240 ('/', ApprovedHandler),
fcf7602 @progrium working approval process and ical view of approved events
progrium authored Mar 22, 2010
241 ('/events\.(.+)', EventsHandler),
d75579f @progrium minor updates here and there to bills contributions.
progrium authored Apr 6, 2010
242 ('/past', PastHandler),
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
243 ('/pending', PendingHandler),
a82b43e @billsaysthis add myevents, pastevents code, refined list display on event page
billsaysthis authored Apr 1, 2010
244 ('/myevents', MyEventsHandler),
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
245 ('/new', NewHandler),
47a7f7a @progrium basic form validation, added end time, start of notifications, some f…
progrium authored Apr 5, 2010
246 ('/event/(\d+).*', EventHandler),
247 ('/expire', ExpireCron),
34d98f0 @billsaysthis moved feedback stuff to separate py file, small tweak to email notifi…
billsaysthis authored Apr 16, 2010
248 ('/expiring', ExpireReminderCron),
d2c3dc7 @billsaysthis moved app-specific js to separate file
billsaysthis authored Apr 19, 2010
249 ('/feedback/new/(\d+).*', FeedbackHandler) ],debug=True)
9b632dd @progrium initial commit -- basic form, rough listing
progrium authored Mar 6, 2010
250 util.run_wsgi_app(application)
251
252 if __name__ == '__main__':
253 main()
Something went wrong with that request. Please try again.