Skip to content

HTTPS clone URL

Subversion checkout URL

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