示例#1
0
def create_annotation():
    # Only registered users can create annotations
    if g.user is None:
        return _failed_authz_response('create annotation')

    if request.json is not None:
        annotation = g.annotation_class(
            _filter_input(request.json, CREATE_FILTER_FIELDS))

        annotation['consumer'] = g.user.consumer.key
        if _get_annotation_user(annotation) != g.user.id:
            annotation['user'] = g.user.id

        if hasattr(g, 'before_annotation_create'):
            g.before_annotation_create(annotation)

        if hasattr(g, 'after_annotation_create'):
            annotation.save(refresh=False)
            g.after_annotation_create(annotation)

        refresh = request.args.get('refresh') != 'false'
        annotation.save(refresh=refresh)

        return jsonify(annotation)
    else:
        return jsonify('No JSON payload sent. Annotation not created.',
                       status=400)
示例#2
0
def create_annotation():
    # Only registered users can create annotations
    if g.user is None:
        return _failed_authz_response('create annotation')

    if request.json is not None:
        annotation = g.annotation_class(
            _filter_input(
                request.json,
                CREATE_FILTER_FIELDS))

        annotation['consumer'] = g.user.consumer.key
        if _get_annotation_user(annotation) != g.user.id:
            annotation['user'] = g.user.id

        if hasattr(g, 'before_annotation_create'):
            g.before_annotation_create(annotation)

        if hasattr(g, 'after_annotation_create'):
            annotation.save(refresh=False)
            g.after_annotation_create(annotation)

        refresh = request.args.get('refresh') != 'false'
        annotation.save(refresh=refresh)

        location = url_for('.read_annotation', id=annotation['id'])

        return jsonify(annotation), 201, {'Location': location}
    else:
        return jsonify('No JSON payload sent. Annotation not created.',
                       status=400)
示例#3
0
def create_annotation():
    # Only registered users can create annotations
    if g.user is None:
        return _failed_authz_response("create annotation")

    if request.json is not None:
        annotation = g.annotation_class(_filter_input(request.json, CREATE_FILTER_FIELDS))

        annotation["consumer"] = g.user.consumer.key
        if _get_annotation_user(annotation) != g.user.id:
            annotation["user"] = g.user.id

        if hasattr(g, "before_annotation_create"):
            g.before_annotation_create(annotation)

        if hasattr(g, "after_annotation_create"):
            annotation.save(refresh=False)
            g.after_annotation_create(annotation)

        refresh = request.args.get("refresh") != "false"
        annotation.save(refresh=refresh)

        location = url_for(".read_annotation", docid=annotation["id"])

        return jsonify(annotation), 201, {"Location": location}
    else:
        return jsonify("No JSON payload sent. Annotation not created.", status=400)
示例#4
0
def create_annotation_bundle():
    # Only registered users can create annotations
    if g.user is None:
        return _failed_authz_response('create annotation')

    if request.json is not None:

        locations = []
        annotations = []
        for raw_annotation in request.json:
            annotation = g.annotation_class(
                _filter_input(
                    raw_annotation,
                    CREATE_FILTER_FIELDS))

            # print raw_annotation

            annotation['consumer'] = g.user.consumer.key
            if _get_annotation_user(annotation) != g.user.id:
                annotation['user'] = g.user.id

            if hasattr(g, 'before_annotation_create'):
                g.before_annotation_create(annotation)

            if hasattr(g, 'after_annotation_create'):
                annotation.save(refresh=False)
                g.after_annotation_create(annotation)

            refresh = request.args.get('refresh') != 'false'
            annotation.save(refresh=refresh)

            location = url_for('.read_annotation', docid=annotation['id'])
            locations.append(location)
            annotations.append(annotation)

        # print "Total %d annotations added\n" % (len(annotations))
        return jsonify(annotations), 201
    else:
        return jsonify('No JSON payload sent. Annotation not created.',
                       status=400)