示例#1
0
文件: views.py 项目: chrber/h
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
示例#2
0
文件: views.py 项目: ningyifan/h
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)
示例#3
0
文件: views.py 项目: linhua55/h
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)
示例#4
0
文件: views.py 项目: coolcool21/h
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)
示例#5
0
文件: views.py 项目: ningyifan/h
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)
示例#6
0
文件: views.py 项目: linhua55/h
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)
示例#7
0
文件: views.py 项目: coolcool21/h
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)
示例#8
0
文件: views.py 项目: coolcool21/h
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']],
    }
示例#9
0
文件: logic.py 项目: plainspace/h
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']],
    }
示例#10
0
文件: views.py 项目: chrber/h
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"]]}
示例#11
0
文件: views.py 项目: openbizgit/h
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
示例#12
0
文件: views.py 项目: linhua55/h
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
示例#13
0
文件: views.py 项目: openbizgit/h
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)
示例#14
0
文件: views.py 项目: linhua55/h
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']],
    }
示例#15
0
文件: views.py 项目: openbizgit/h
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)
示例#16
0
文件: views.py 项目: ningyifan/h
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']],
    }
示例#17
0
文件: views.py 项目: openbizgit/h
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)
示例#18
0
文件: views.py 项目: ningyifan/h
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']],
    }
示例#19
0
文件: views.py 项目: openbizgit/h
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)
示例#20
0
文件: views.py 项目: ningyifan/h
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']],
    }
示例#21
0
文件: views.py 项目: ningyifan/h
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']],
    }
示例#22
0
文件: views.py 项目: bitsoffreedom/h
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)
示例#23
0
文件: views.py 项目: ningyifan/h
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)
示例#24
0
文件: views.py 项目: ningyifan/h
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)
示例#25
0
文件: views.py 项目: chrber/h
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)
示例#26
0
文件: views.py 项目: linhua55/h
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)