def vote_insert(self, request): """ Exposes an API endpoint to insert a vote for the current user. """ user = auth_user(self.request_state.headers) anno = Anno.get_by_id(request.anno_id) if anno is None: raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id) vote = Vote() vote.anno_key = anno.key vote.creator = user.key if request.created is not None: vote.created = request.created vote.put() anno.vote_count += 1 anno.last_update_time = datetime.datetime.now() anno.last_activity = 'vote' anno.last_update_type = 'create' anno.put() # update user anno state UserAnnoState.insert(user=user, anno=anno, type=AnnoActionType.UPVOTED) # update vote in search document put_search_document(anno.generate_search_document(), SearchIndexName.ANNO) return vote.to_message()
def vote_insert(self, request): """ Exposes an API endpoint to insert a vote for the current user. """ user = handle_user(request.user_email) anno = Anno.get_by_id(request.anno_id) if anno is None: raise endpoints.NotFoundException('No anno entity with the id "%s" exists.' % request.id) vote = Vote() vote.anno_key = anno.key vote.creator = user.key if request.created is not None: vote.created = request.created vote.put() anno.vote_count += 1 anno.last_update_time = datetime.datetime.now() anno.last_activity = 'vote' anno.put() return vote.to_message()