def flag_insert(self, request): """ Exposes an API endpoint to insert a flag 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.') flag = Flag() flag.anno_key = anno.key flag.creator = user.key if request.created is not None: flag.created = request.created flag.put() anno.flag_count += 1 anno.last_update_time = datetime.datetime.now() anno.last_activity = 'flag' anno.last_update_type = 'create' anno.put() # update user anno state UserAnnoState.insert(user=user, anno=anno, type=AnnoActionType.FLAGGED) # update flag in search document put_search_document(anno.generate_search_document(), SearchIndexName.ANNO) return flag.to_message()
def flag_insert(self, request): """ Exposes an API endpoint to insert a flag 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.') flag = Flag() flag.anno_key = anno.key flag.creator = user.key if request.created is not None: flag.created = request.created flag.put() anno.flag_count += 1 anno.last_update_time = datetime.datetime.now() anno.last_activity = 'flag' anno.put() return flag.to_message()