예제 #1
0
    def mutate(root, args, context, info):
        require_cls_permission(CrudPermissions.CREATE, models.Extract, context)
        discussion_id = context.matchdict['discussion_id']

        user_id = context.authenticated_userid or Everyone

        post_id = args.get('post_id')
        post_id = int(Node.from_global_id(post_id)[1])
        post = models.Post.get(post_id)
        new_extract = models.Extract(creator_id=user_id,
                                     owner_id=user_id,
                                     discussion_id=discussion_id,
                                     body=args.get('body'),
                                     important=args.get('important', False),
                                     content=post)
        post.db.add(new_extract)
        range = models.TextFragmentIdentifier(
            extract=new_extract,
            xpath_start=args.get('xpath_start'),
            offset_start=args.get('offset_start'),
            xpath_end=args.get('xpath_end'),
            offset_end=args.get('offset_end'))
        post.db.add(range)
        post.db.flush()

        return AddPostExtract(post=post)
예제 #2
0
파일: post.py 프로젝트: shangxor/assembl
    def mutate(root, args, context, info):
        status = False
        require_cls_permission(CrudPermissions.CREATE, models.Extract, context)
        discussion_id = context.matchdict['discussion_id']
        # Retrieve the user id
        user_id = context.authenticated_userid or Everyone
        extracts = args.get('extracts')
        status = True
        extract_nature = args.get('extract_nature', None)
        extract_nature = models.ExtractNatureVocabulary.Enum(extract_nature) if extract_nature else None
        extract_state = args.get('extract_state', None)
        # Add all of extracts
        for extract in extracts:
            post_id = extract.get('post_id')
            post_id = int(Node.from_global_id(post_id)[1])
            post = models.Post.get(post_id) if post_id else None
            if not post:
                continue

            db = post.db
            extract_hash = models.Extract.get_extract_hash(
                extract.get('lang'),
                extract.get('xpath_start'),
                extract.get('xpath_end'),
                extract.get('offset_start'),
                extract.get('offset_end'),
                post_id)
            exist = db.query(exists().where(models.Extract.extract_hash == extract_hash)).scalar()
            if not exist:
                new_extract = models.Extract(
                    creator_id=user_id,
                    owner_id=user_id,
                    discussion_id=discussion_id,
                    body=extract.get('body'),
                    important=extract.get('important', False),
                    content=post,
                    extract_nature=extract_nature,
                    extract_state=extract_state,
                    extract_hash=extract_hash
                )
                new_extract.lang = extract.get('lang')
                db.add(new_extract)
                range = models.TextFragmentIdentifier(
                    extract=new_extract,
                    xpath_start=extract.get('xpath_start'),
                    offset_start=extract.get('offset_start'),
                    xpath_end=extract.get('xpath_end'),
                    offset_end=extract.get('offset_end'))
                db.add(range)
                db.flush()

        return AddPostsExtract(status=status)
예제 #3
0
파일: post.py 프로젝트: shangxor/assembl
    def mutate(root, args, context, info):
        require_cls_permission(CrudPermissions.CREATE, models.Extract, context)
        discussion_id = context.matchdict['discussion_id']

        user_id = context.authenticated_userid or Everyone

        post_id = args.get('post_id')
        post_id = int(Node.from_global_id(post_id)[1])
        post = models.Post.get(post_id)
        extract_hash = models.Extract.get_extract_hash(
            args.get('lang'),
            args.get('xpath_start'),
            args.get('xpath_end'),
            args.get('offset_start'),
            args.get('offset_end'),
            post_id
        )
        db = post.db
        exist = db.query(exists().where(models.Extract.extract_hash == extract_hash)).scalar()
        if exist:
            raise Exception("Extract already exists!")

        new_extract = models.Extract(
            creator_id=user_id,
            owner_id=user_id,
            discussion_id=discussion_id,
            body=args.get('body'),
            important=args.get('important', False),
            content=post,
            extract_hash=extract_hash
        )
        new_extract.lang = args.get('lang')
        tags = models.Keyword.get_tags(args.get('tags', []), discussion_id, db)
        new_extract.tags = tags['new_tags'] + tags['tags']
        db.add(new_extract)
        range = models.TextFragmentIdentifier(
            extract=new_extract,
            xpath_start=args.get('xpath_start'),
            offset_start=args.get('offset_start'),
            xpath_end=args.get('xpath_end'),
            offset_end=args.get('offset_end'))
        db.add(range)
        db.flush()

        return AddPostExtract(post=post, extract=new_extract)