Permalink
Browse files

RSVP system

  • Loading branch information...
1 parent f35065d commit 5ef05d9a0f8f0fef298f0da0769df45cffc80ddf @dustball dustball committed Jul 16, 2011
Showing with 63 additions and 2 deletions.
  1. +3 −0 main.py
  2. +29 −0 models.py
  3. +31 −2 templates/event.html
View
@@ -229,6 +229,7 @@ def post(self, id):
class EventHandler(webapp.RequestHandler):
def get(self, id):
+
event = Event.get_by_id(int(id))
if self.request.path.endswith('json'):
self.response.headers['content-type'] = 'application/json'
@@ -257,6 +258,8 @@ def post(self, id):
if state.lower() == 'approve' and access_rights.can_approve:
event.approve()
desc = 'Approved event'
+ if state.lower() == 'rsvp' and user:
+ event.rsvp()
if state.lower() == 'staff' and access_rights.can_staff:
event.add_staff(user)
desc = 'Added self as staff'
View
@@ -136,6 +136,29 @@ def approve(self):
logging.info('%s approved %s but it is still understaffed' % (user.nickname, self.name))
self.put()
+ def rsvp(self):
+ user = users.get_current_user()
+ if user and not self.has_rsvped():
+ rsvp = Rsvp(event=self)
+ rsvp.put()
+
+ def has_rsvped(self):
+ user = users.get_current_user()
+ if not user:
+ return False
+ for existing_rsvp in self.rsvps:
+ if existing_rsvp.user == user:
+ return True
+ return False
+
+ # Works even for logged out users
+ def can_rsvp(self):
+ if self.has_rsvped():
+ return False
+ time_till_event = self.start_time.replace(tzinfo=pytz.timezone('US/Pacific')) - datetime.now(pytz.timezone('US/Pacific'))
+ hours = time_till_event.seconds/3600+time_till_event.days*24
+ return (hours > 48)
+
def cancel(self):
user = users.get_current_user()
self.status = 'canceled'
@@ -219,6 +242,11 @@ class Feedback(db.Model):
comment = db.StringProperty(multiline=True)
created = db.DateTimeProperty(auto_now_add=True)
+class Rsvp(db.Model):
+ user = db.UserProperty(auto_current_user_add=True)
+ event = db.ReferenceProperty(Event, collection_name='rsvps')
+ created = db.DateTimeProperty(auto_now_add=True)
+
class HDLog(db.Model):
event = db.ReferenceProperty(Event)
created = db.DateTimeProperty(auto_now_add=True)
@@ -229,3 +257,4 @@ class HDLog(db.Model):
def get_logs_list(cls):
return cls.all() \
.order('-created')
+
View
@@ -8,7 +8,7 @@
{% if event.is_deleted %}
{% if access_rights.is_admin %}<input type="submit" name="state" value="Undelete" />{% endif %}
(This will return the event to the &ldquo;pending&rdquo; status.)
- {% else %}
+ {% else %}
<div id="edit-approve-btns">
{% if access_rights.can_cancel and not event.is_onhold %}<input type="submit" name="state" value="OnHold" />{% endif %}
{% if access_rights.can_approve %}<input type="submit" name="state" value="Approve" />{% endif %}
@@ -45,7 +45,7 @@
<div class='b-block'><div class='b-label'>Fee:</div><div class='b-data'>{{event.fee}}</div></div>
<div class='b-block'><div class='b-label'>Rooms:</div><div class='b-data'>{{event.roomlist}}</div></div>
<!--<div class='b-block'><div class='b-label'>Staff:</div><div class='b-data'>{{event.stafflist}}</div></div>-->
- <div class='thin-border'></div>
+ <br />
<div class='b-block'><div class='b-label'>Details:</div><div class='b-data'>{{event.details}}</div></div>
<br />
<div class='b-block'><div class='b-label'>Notes:</div><div class='b-data'>{{event.notes}}</div></div>
@@ -61,6 +61,35 @@
{% endfor %}
</div>
{% endif %}
+ {% ifequal event.status 'approved' %}
+ {% if user %}
+ <br/>
+ <div class='thin-border'></div>
+ <form method="post" style="display: inline;">
+ <h4 style="margin-top:0; margin-bottom:1em">Member RSVP</h4>
+ {% if event.can_rsvp %}
+ <input type="submit" name="state" value="RSVP" />
+ {% endif %}
+
+ </form>
+ {% endif %}
+
+ {% if event.can_rsvp or event.has_rsvped %}
+ <p>Hacker Dojo members may {% if not user %} <a href="{{login_url}}">login</a> to {% endif %} reserve space in the event room up to 48 hours before the event.</p>
+ <p>Member RSVP does not imply event registration if applicable.</p>
+ {% endif %}
+
+ {% if user and event.rsvps.count %}
+ <hr size=1>
+ <p>The following members have RSVPed:</p>
+ <ol>
+ {% for rsvp in event.rsvps %}
+ <li>{{ rsvp.user }}</li>
+ {% endfor %}
+ </ol>
+ {% endif %}
+
+ {% endifequal %}
</div>
{% endblock %}

0 comments on commit 5ef05d9

Please sign in to comment.