Permalink
Browse files

Fix validation for event size

  • Loading branch information...
1 parent 2fb7542 commit 86158774e92b9fcfa43c3c5099720cf4fe477f3b Brian Klug committed Jun 15, 2010
Showing with 9 additions and 1 deletion.
  1. +5 −1 main.py
  2. +4 −0 models.py
View
6 main.py
@@ -162,8 +162,12 @@ def post(self):
self.request.get('end_time_hour'),
self.request.get('end_time_minute'),
self.request.get('end_time_ampm')), "%m/%d/%Y %I:%M %p")
+ if not self.request.get('estimated_size').isdigit():
+ raise ValueError("Estimated number of people must be a number")
+ if not int(self.request.get('estimated_size')) > 0:
+ raise ValueError("Estimated number of people must be greater then zero")
if (end_time-start_time).days < 0:
- raise ValueError("End time must be after start time")
+ raise ValueError("End time must be after start time")
else:
event = Event(
name = self.request.get('name'),
View
4 models.py
@@ -76,7 +76,11 @@ def is_staffed(self):
return len(self.staff) >= self.staff_needed()
def staff_needed(self):
+ if self.estimated_size.isdigit():
return int(self.estimated_size) / GUESTS_PER_STAFF
+ else:
+ # invalid data; just return something reasonable
+ return 2
def is_approved(self):
'''Has the events team approved the event? Note: This does not

0 comments on commit 8615877

Please sign in to comment.