Exemple #1
0
def send_add_photo_notifications(bout, from_user_email):
    if bout and from_user_email:
        Notification.create('photo_add', bout.owner, from_user_email, bout)
        photos = Photo.for_(bout)
        if len(photos)>0:
            for photo in photos:
                if photo.owner_email != from_user_email and photo.owner_email != bout.owner.email:
                    Notification.create('photo_add', photo.user, from_user_email, bout)
Exemple #2
0
 def post(self):
     user = util.get_user_from_session()
     message = self.request.get('message')
     owner_email = self.request.get('owner_email')
     bout_id = self.request.get('bout_id')
     bout = Bout.get_by_id(long(bout_id))
     photo = Photo.for_bout_user(bout, owner_email)
     Comment.create(user, photo, message)
     Notification.create('comment_add', photo.bout.owner, user.email, bout)
Exemple #3
0
 def post(self):
     ids_str = self.request.get('ids')
     ids = [id for id in ids_str.split(';') if len(id) > 0]
     bout_id = self.request.get('bout_id')
     if len(ids) <= 0:
         return
     invited_by = util.get_user_from_session()
     bout = Bout.get_by_id(long(bout_id))
     for id in ids:
         user = User.get_by_key_name(id)
         Invited(key_name=bout_id, parent=user, timestamp=datetime.datetime.now(), invited_by=invited_by).put()
         Notification.create('invited', user, invited_by.email, bout)
         message = "%s invited you to the bout %s"%(invited_by.name, bout.name)
         deferred.defer(send_push_notification, user.email, message, bout_id)
Exemple #4
0
def set_winner(bout):
    bout.change_status(2)
    participants = sorted(Photo.for_(bout), key=lambda x: Vote.count(x), reverse=True)
    if len(participants) > 0:
        max_vote_count = Vote.count(participants[0])
        if max_vote_count > 0:
            for participant in participants:
                current_vote_count = Vote.count(participant)
                if current_vote_count == max_vote_count:
                    winner = User.get_by_key_name(participant.owner_email)
                    Winner.create(winner, bout)
                    Notification.create('winner', winner, winner.email, bout)
                elif current_vote_count < max_vote_count:
                    break
Exemple #5
0
 def post(self):
     response = {}
     user = util.get_user_from_session()
     email = user.key().name()
     owner_email = self.request.get('owner_email')
     bout_id = long(self.request.get('bout_id'))
     bout = Bout.get_by_id(bout_id)
     photo = Photo.get_by_key_name(owner_email, parent=bout)
     if Vote.update(email, photo, bout):
         Notification.create('photo_vote', bout.owner, user.email, bout)
         message = "%s voted on your photo in the Bout %s."%(user.name, bout.name)
         util.send_push_notification(photo.user.email, message, bout.id)
         response = {"success": True, "voted": True}
     else:
         response = {"success": True, "voted": False}
     vote_count = Vote.count(photo)
     response["vote_count"] = vote_count
     self.response.write(json.dumps(response))
def setup():
    user_1 = User.create('email1', 'firstname1', 'lastname1', 'password1')
    tp_user_1 = ThirdPartyUser(key_name='FB', parent=user_1)
    tp_user_1.network_id = '359059317608175'
    tp_user_1.put()
    user_2 = User.create('email2', 'firstname2', 'lasstname2', 'password2')
    tp_user_2 = ThirdPartyUser(key_name='FB', parent=user_2)
    tp_user_2.network_id = '359059317608175'
    tp_user_2.put()
    bout_1 = Bout.create(user_1, 'bout1', 'desc1', 1, 1)
    util.schedule_end(bout_1)
    photo_1 = Photo.create(bout_1, user_1, 'image_blob_key_1')
    photo_2 = Photo.create(bout_1, user_2, 'image_blob_key_2')
    bout_2 = Bout.create(user_2, 'bout2', 'desc2', 1, 2)
    util.schedule_end(bout_2)
    Vote.create('email1', photo_1)
    Vote.create('email2', photo_1)
    Vote.create('email2', photo_2)
    #photo_add, photo_vote, comment_add, winner, invited
    Notification.create('photo_add', bout_1.owner, user_2.email, bout_1)
    Notification.create('photo_vote', bout_1.owner, user_2.email, bout_1)
    Notification.create('comment_add', bout_1.owner, user_2.email, bout_1)
    Notification.create('winner', user_1, user_2.email, bout_1)
    Notification.create('invited', user_1, user_2.email, bout_1)
    #Winner.create(user_1, bout_1)
    Comment(parent=photo_1, user=user_1, message='message1', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_1, user=user_2, message='message2', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message3', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message4', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message5', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_1, message='message6', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message7', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message8', timestamp=datetime.datetime.now()).put()
    Comment(parent=photo_2, user=user_2, message='message9', timestamp=datetime.datetime.now()).put()
    Follower.create('email1', user_2)
    Following.create(user_1, 'email2')