コード例 #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)