示例#1
0
 def vote_get(self, request):
     """
     Exposes an API endpoint to get a vote.
     """
     if request.id is None:
         raise endpoints.BadRequestException('id field is required.')
     vote = Vote.get_by_id(request.id)
     if vote is None:
         raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id)
     return vote.to_message()
示例#2
0
 def vote_delete(self, request):
     """
     Exposes an API endpoint to delete an existing vote.
     """
     if request.id is None and request.anno_id is None:
         raise endpoints.BadRequestException('id or anno_id field is required.')
     if request.id is not None:
         vote = Vote.get_by_id(request.id)
         if vote is None:
             raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id)
         anno = vote.anno_key.get()
         vote.key.delete()
         anno.vote_count -= 1
         anno.put()
     elif request.anno_id is not None:
         user = User.find_user_by_email(get_endpoints_current_user().email())
         anno = Anno.get_by_id(request.anno_id)
         for key in Vote.query(Vote.anno_key == anno.key, Vote.creator == user.key).iter(keys_only=True):
             key.delete()
             anno.vote_count -= 1
             anno.put()
     return message_types.VoidMessage()
示例#3
0
 def vote_delete(self, request):
     """
     Exposes an API endpoint to delete an existing vote.
     """
     user = auth_user(self.request_state.headers)
     anno = None
     if request.id is None and request.anno_id is None:
         raise endpoints.BadRequestException('id or anno_id field is required.')
     if request.id is not None:
         vote = Vote.get_by_id(request.id)
         if vote is None:
             raise endpoints.NotFoundException('No vote entity with the id "%s" exists.' % request.id)
         anno = vote.anno_key.get()
         vote.key.delete()
         anno.vote_count -= 1
         anno.put()
     elif request.anno_id is not None:
         anno = Anno.get_by_id(request.anno_id)
         for key in Vote.query(Vote.anno_key == anno.key, Vote.creator == user.key).iter(keys_only=True):
             key.delete()
             anno.vote_count -= 1
             anno.put()
     put_search_document(anno.generate_search_document(), SearchIndexName.ANNO)
     return message_types.VoidMessage()