Exemple #1
0
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop("_separate_replies", False)
    results = search_lib.search(request, params, separate_replies=separate_replies)

    return_value = {"total": results["total"], "rows": [search_lib.render(a) for a in results["rows"]]}

    if separate_replies:
        return_value["replies"] = [search_lib.render(a) for a in results["replies"]]

    return return_value
Exemple #2
0
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context

    # Read the new fields for the annotation
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    # Check user's permissions
    has_admin_permission = request.has_permission('admin', annotation)

    # Update and store the annotation
    try:
        logic.update_annotation(annotation, fields, has_admin_permission)
    except RuntimeError as err:
        return _api_error(
            request,
            err.args[0],
            status_code=err.args[1])

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
Exemple #3
0
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context.model

    # Read the new fields for the annotation
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    try:
        appstruct = schemas.AnnotationSchema().validate(fields)
    except schemas.ValidationError as err:
        return _api_error(request, err.message, status_code=400)

    # Update and store the annotation
    try:
        logic.update_annotation(annotation,
                                appstruct,
                                userid=request.authenticated_userid)
    except RuntimeError as err:
        return _api_error(request, err.args[0], status_code=err.args[1])

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
Exemple #4
0
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context.model

    # Read the new fields for the annotation
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    try:
        validators.Annotation().validate(fields)
    except validators.Error as err:
        return _api_error(request, err.message, status_code=400)

    # Update and store the annotation
    try:
        logic.update_annotation(annotation,
                                fields,
                                userid=request.authenticated_userid)
    except RuntimeError as err:
        return _api_error(
            request,
            err.args[0],
            status_code=err.args[1])

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
Exemple #5
0
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context

    # Read the new fields for the annotation
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    # Check user's permissions
    has_admin_permission = request.has_permission('admin', annotation)

    # Update and store the annotation
    try:
        logic.update_annotation(annotation, fields, has_admin_permission)
    except RuntimeError as err:
        return _api_error(request, err.args[0], status_code=err.args[1])

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
Exemple #6
0
def read(context, request):
    """Return the annotation (simply how it was stored in the database)."""
    annotation = context.model

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'read')

    return search_lib.render(annotation)
Exemple #7
0
def read(context, request):
    """Return the annotation (simply how it was stored in the database)."""
    annotation = context.model

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'read')

    return search_lib.render(annotation)
Exemple #8
0
def search(request):
    """Search the database for annotations matching with the given query."""
    results = search_lib.search(request, request.params)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #9
0
def search_annotations(params, user=None, search_normalized_uris=False):
    results = search_lib.search(request_params=params,
                                user=user,
                                search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #10
0
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    results = search_lib.search(request, {"limit": 20})

    return {"total": results["total"], "rows": [search_lib.render(a) for a in results["rows"]]}
Exemple #11
0
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    results = search_lib.search(request, params,
                                separate_replies=separate_replies)

    return_value = {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']]
    }

    if separate_replies:
        return_value['replies'] = [
            search_lib.render(a) for a in results['replies']]

    return return_value
Exemple #12
0
def search(request):
    """Search the database for annotations matching with the given query."""
    params = request.params.copy()

    separate_replies = params.pop('_separate_replies', False)
    results = search_lib.search(request,
                                params,
                                separate_replies=separate_replies)

    return_value = {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']]
    }

    if separate_replies:
        return_value['replies'] = [
            search_lib.render(a) for a in results['replies']
        ]

    return return_value
Exemple #13
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    schema = schemas.CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))

    annotation = logic.create_annotation(appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #14
0
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    results = search_lib.search(request, {"limit": 20})

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #15
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    schema = schemas.CreateAnnotationSchema(request)
    appstruct = schema.validate(_json_payload(request))

    annotation = logic.create_annotation(appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #16
0
def search(request):
    """Search the database for annotations matching with the given query."""
    search_normalized_uris = request.feature('search_normalized')

    # The search results are filtered for the authenticated user
    user = get_user(request)
    results = search_lib.search(request_params=request.params,
                                user=user,
                                search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #17
0
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context.model
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    appstruct = schema.validate(_json_payload(request))

    # Update and store the annotation
    logic.update_annotation(annotation, appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
Exemple #18
0
def search(request):
    """Search the database for annotations matching with the given query."""
    search_normalized_uris = request.feature('search_normalized')

    # The search results are filtered for the authenticated user
    user = get_user(request)
    results = search_lib.search(request_params=request.params,
                                user=user,
                                search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #19
0
def update(context, request):
    """Update the fields we received and store the updated version."""
    annotation = context.model
    schema = schemas.UpdateAnnotationSchema(request, annotation)
    appstruct = schema.validate(_json_payload(request))

    # Update and store the annotation
    logic.update_annotation(annotation, appstruct)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'update')

    # Return the updated version that was just stored.
    return search_lib.render(annotation)
Exemple #20
0
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    search_normalized_uris = request.feature('search_normalized')

    user = get_user(request)
    results = search_lib.index(user=user,
                               search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #21
0
def annotations_index(request):
    """Do a search for all annotations on anything and return results.

    This will use the default limit, 20 at time of writing, and results
    are ordered most recent first.
    """
    search_normalized_uris = request.feature('search_normalized')

    user = get_user(request)
    results = search_lib.index(user=user,
                               search_normalized_uris=search_normalized_uris)

    return {
        'total': results['total'],
        'rows': [search_lib.render(a) for a in results['rows']],
    }
Exemple #22
0
def read(context, request):
    """Return the annotation (simply how it was stored in the database)."""
    annotation = context.model

    # Don't show group annotations for users who don't have the groups feature
    # enabled, even if they are members of the group (this can happen if a user
    # joins a group and then the groups feature is later disabled for that
    # user).
    if not request.feature('groups'):
        if annotation.get('group') not in (None, '__world__'):
            raise httpexceptions.HTTPNotFound()


    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'read')

    return search_lib.render(annotation)
Exemple #23
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    user = get_user(request)

    # Create the annotation
    annotation = logic.create_annotation(fields, user)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #24
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    user = get_user(request)

    # Create the annotation
    annotation = logic.create_annotation(fields, user)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #25
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(
            request, "No JSON payload sent. Annotation not created.", status_code=400
        )  # Client Error: Bad Request

    try:
        appstruct = schemas.AnnotationSchema().validate(fields)
    except schemas.ValidationError as err:
        return _api_error(request, err.message, status_code=400)

    annotation = logic.create_annotation(appstruct, userid=request.authenticated_userid)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, "create")

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)
Exemple #26
0
def create(request):
    """Read the POSTed JSON-encoded annotation and persist it."""
    # Read the annotation from the request payload
    try:
        fields = request.json_body
    except ValueError:
        return _api_error(request,
                          'No JSON payload sent. Annotation not created.',
                          status_code=400)  # Client Error: Bad Request

    try:
        appstruct = schemas.AnnotationSchema().validate(fields)
    except schemas.ValidationError as err:
        return _api_error(request, err.message, status_code=400)

    annotation = logic.create_annotation(appstruct,
                                         userid=request.authenticated_userid)

    # Notify any subscribers
    _publish_annotation_event(request, annotation, 'create')

    # Return it so the client gets to know its ID and such
    return search_lib.render(annotation)