コード例 #1
0
ファイル: reply.py プロジェクト: Shopcaster/Connectsy-Server
 def test_sms_reply_comment(self):
     if not settings.TEST_SMS: return
     
     user, event, smsuser = self.prep_for_response_sms()
     
     comment = 'This is a comment'
     
     response = self.post('/extras/SMS/', args={'From': smsuser[u'number'],
                                                'To': settings.TWILIO_NUMBERS[0],
                                                'Body': comment})
     self.assertEqual(response.status, 200)
     
     db_comment = Comment.get({'event': event[u'id']})
     
     self.assertNotEqual(db_comment, None, 'Comment exists')
     self.assertEqual(comment, db_comment[u'comment'], 'comment body matches')
コード例 #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})
コード例 #3
0
 def get(self, event_id):
     '''
     Gets all comments for a given event.
     '''
     #make sure the event exists
     if not Event.get(event_id): raise HTTPError(404)
     
     #show them comments!
     comments = Comment.find({u'event': event_id})
     comments.sort(u'timestamp', pymongo.ASCENDING)
     
     ret_coms = []
     for c in comments:
         user = User.get(c[u'user'])
         ret = c.__data__
         ret[u'username'] = user.__data__.get(u'username', None)
         if ret[u'username'] is None:
             del ret[u'username']
         ret[u'display_name'] = user.__data__.get(u'display_name', None)
         if ret[u'display_name'] is None:
             del ret[u'display_name']
         ret_coms.append(ret)
     
     self.output({u'comments': ret_coms})