示例#1
0
    def anno_insert(self, request):
        """
        Exposes an API endpoint to insert an anno for the current user.

        if current user doesn't exist, the user will be created first.
        """
        user = auth_user(self.request_state.headers)

        # checking if same anno exists
        exist_anno = Anno.is_anno_exists(user, request)
        if exist_anno is not None:
            raise endpoints.BadRequestException("Duplicate anno(%s) already exists." % exist_anno.key.id())

        entity = Anno.insert_anno(request, user)

        # find all hashtags
        tags = extract_tags_from_text(entity.anno_text.lower())
        for tag, count in tags.iteritems():
            # Write the cumulative amount per tag
            Tag.add_tag_total(tag, total=count)

        # index this document. strange exception here.
        put_search_document(entity.generate_search_document(), SearchIndexName.ANNO)

        # send push notifications
        ActivityPushNotifications.send_push_notification(first_user=user, anno=entity, action_type=AnnoActionType.CREATED)

        return entity.to_response_message(user)
示例#2
0
    def anno_insert(self, request):
        """
        Exposes an API endpoint to insert an anno for the current user.

        if current user doesn't exist, the user will be created first.
        """
        user = auth_user(self.request_state.headers)
        if Anno.is_anno_exists(user, request):
            raise endpoints.BadRequestException("Duplicate anno already exists.")
        entity = Anno.insert_anno(request, user)
        return entity.to_response_message()
示例#3
0
    def anno_insert(self, request):
        """
        Exposes an API endpoint to insert an anno for the current user.

        if current user doesn't exist, the user will be created first.
        """
        user = auth_user(self.request_state.headers)
        exist_anno = Anno.is_anno_exists(user, request)
        if exist_anno is not None:
            raise endpoints.BadRequestException("Duplicate anno(%s) already exists." % exist_anno.key.id())
        entity = Anno.insert_anno(request, user)

        # index this document. strange exception here.
        put_search_document(entity.generate_search_document())

        return entity.to_response_message()