Exemplo n.º 1
0
 def post(self, event_id):
     '''
     Updates an invitee's attendance
     '''
     body = self.body_dict()
     username = self.get_session()[u'username']
     user = User.get({u'username': username})
     #make sure the event exists
     event = Event.get(event_id)
     if not event: raise HTTPError(404)
     
     #try to grab the user's existing attendance status
     att = Attendant.get({u'event': event[u'id'],
                          u'user': user[u'id']})
     
     #if the user isn't invited, we need to error out if broadcast is off
     if att is None:
         if event[u'broadcast']:
             att = Attendant(user=user[u'id'], event=event[u'id'])
         else:
             raise HTTPError(403)
     
     # create a list of acceptable statuses
     valid_statuses = [v for k, v in status.__dict__.iteritems() if k[0] != '_']
     
     #make sure status is present and a correct value
     if body.get(u'status') not in valid_statuses:
         raise HTTPError(400)
     
     notify = (att[u'status'] == status.INVITED 
               and body[u'status'] == status.ATTENDING)
     
     att[u'status'] = body[u'status']
     att.save()
     
     if notify:
         #Send out the attendant notifications
         for uname in Attendant.to_notify(event, skip=[username]):
             notifications.send(uname, {u'type': 'attendant',
                                        u'event_revision': event[u'revision'],
                                        u'event_id': event[u'id'],
                                        u'attendant': username})
Exemplo n.º 2
0
 def post(self, event_id):
     #make sure the event exists
     event = Event.get(event_id)
     if not event: raise HTTPError(404)
     
     #grab the data
     body = self.body_dict()
     #comment body is required, and must have content
     if not u'comment' in body or len(body[u'comment']) == 0:
         raise HTTPError(400)
     
     #nonce is optional
     if u'nonce' in body:
         #if another comment exists with this nonce, it's a double-post
         if Comment.get({u'nonce': body[u'nonce'],
                         u'event': event[u'id'], 
                         u'user': self.get_session()[u'username']}):
             raise HTTPError(409)
     
     commenter = self.get_session()[u'username']
     
     #create the comment
     Comment(**{
         u'comment': body[u'comment'],
         u'event': event[u'id'],
         u'username': commenter,
     }).save()
     
     #Send out the comment notifications
     usernames = Attendant.to_notify(event, skip=[commenter])
     for username in usernames:
         notifications.send(username, {u'type': 'comment',
                                       u'event_revision': event[u'revision'],
                                       u'event_id': event[u'id'],
                                       u'comment': body[u'comment'],
                                       u'commenter': commenter})