Ejemplo n.º 1
0
 def get(self):
     next = self.request.get('next')
     owner_email = self.request.get('owner_email')
     bout_id = long(self.request.get('bout_id'))
     bout = Bout.get_by_id(bout_id)
     photo = Photo.for_bout_user(bout, owner_email)
     response = util.fetch_with_cursor(Comment.all().ancestor(photo).order("-timestamp"), limit=20, cursor=next, mapper=make_comment_dict)
     self.response.write(json.dumps(response))
Ejemplo n.º 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)
Ejemplo n.º 3
0
 def post(self):
     user = util.get_user_from_session()
     bout_id = long(self.request.get('bout_id'))
     image_blob_key = str(self.get_uploads()[0].key())
     bout = Bout.get_by_id(bout_id)
     photo = Photo.for_bout_user(bout, user.email)
     if photo:
         votes = Vote.for_photo(photo)
         if len(votes) > 0:
             db.delete(votes)
     Photo.create(bout, user, image_blob_key)
     deferred.defer(send_add_photo_notifications, bout, user.email)
Ejemplo n.º 4
0
def make_users_bout_dict(bout, email):
    bout_dict = {}
    bout_dict['id'] = bout.id
    bout_dict['name'] = bout.name
    bout_dict['photos'] = []
    num_photos = Photo.all().ancestor(bout).count()
    user_uploaded_photo = Photo.for_bout_user(bout, email)
    if user_uploaded_photo:
        bout_dict['photos'].append({'image':user_uploaded_photo.image_url})
        num_photos -= 1
    for i in range(0, num_photos):
        bout_dict['photos'].append({})
    bout_dict['ended'] = bout.ended
    if bout_dict['ended']:
        bout_dict['winners'] = []
        if Winner.for_bout_user(bout, email):
            bout_dict['winners'].append(email)
    return bout_dict
Ejemplo n.º 5
0
def make_bout_dict(bout, email):
    bout_dict = {}
    bout_dict['id'] = bout.id
    bout_dict['name'] = bout.name
    bout_dict['description'] = bout.description
    bout_dict['time_left'] = bout.time_left_string
    bout_dict['ended'] = bout.ended
    bout_dict['photos'] = []
    user_in_session_photo = Photo.for_bout_user(bout, email)
    if user_in_session_photo:
        photo_dict = make_photo_dict(user_in_session_photo, email)
        bout_dict['photos'].append(photo_dict)
    for photo in sorted(Photo.for_(bout), key=lambda x: Vote.count(x), reverse=True):
        if photo.owner_email != email:
            photo_dict = make_photo_dict(photo, email)
            bout_dict['photos'].append(photo_dict)
    if bout.ended:
        bout_dict['winners'] = []
        winners = Winner.for_bout(bout)
        if len(winners) > 0:
            for winner in winners:
                bout_dict['winners'].append(winner.email)
    return bout_dict