def _publish_annotation_event(request, annotation, action): """Publish an event to the annotations queue for this annotation action.""" links_service = request.find_service(name='links') annotation_dict = None if action == 'delete': presenter = AnnotationJSONPresenter(annotation, links_service) annotation_dict = presenter.asdict() event = AnnotationEvent(request, annotation.id, action, annotation_dict) request.notify_after_commit(event)
def create(request): """Create an annotation from the POST payload.""" schema = schemas.CreateAnnotationSchema(request) appstruct = schema.validate(_json_payload(request)) annotation = storage.create_annotation(request, appstruct) _publish_annotation_event(request, annotation, 'create') links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(annotation, links_service) return presenter.asdict()
def create(request): """Create an annotation from the POST payload.""" schema = schemas.CreateAnnotationSchema(request) appstruct = schema.validate(_json_payload(request)) annotation = storage.create_annotation(request, appstruct) _publish_annotation_event(request, annotation, 'create') links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(annotation, links_service) return presenter.asdict()
def _publish_annotation_event(request, annotation, action): """Publish an event to the annotations queue for this annotation action.""" links_service = request.find_service(name='links') annotation_dict = None if action == 'delete': presenter = AnnotationJSONPresenter(annotation, links_service) annotation_dict = presenter.asdict() event = AnnotationEvent(request, annotation.id, action, annotation_dict) request.notify_after_commit(event)
def update(annotation, request): """Update the specified annotation with data from the PUT payload.""" schema = schemas.UpdateAnnotationSchema(request, annotation.target_uri, annotation.groupid) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request.db, annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(annotation, links_service) return presenter.asdict()
def update(context, request): """Update the specified annotation with data from the PUT payload.""" schema = schemas.UpdateAnnotationSchema(request, context.annotation.target_uri, context.annotation.groupid) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request.db, context.annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(annotation, links_service) return presenter.asdict()
def update(context, request): """Update the specified annotation with data from the PATCH payload.""" if request.method == 'PUT' and hasattr(request, 'stats'): request.stats.incr('memex.api.deprecated.put_update_annotation') schema = schemas.UpdateAnnotationSchema(request, context.annotation.target_uri, context.annotation.groupid) appstruct = schema.validate(_json_payload(request)) annotation = storage.update_annotation(request.db, context.annotation.id, appstruct) _publish_annotation_event(request, annotation, 'update') links_service = request.find_service(name='links') group_service = request.find_service(IGroupService) resource = AnnotationResource(annotation, group_service, links_service) presenter = AnnotationJSONPresenter(resource) return presenter.asdict()
def read(annotation, request): """Return the annotation (simply how it was stored in the database).""" links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(annotation, links_service) return presenter.asdict()
def read(context, request): """Return the annotation (simply how it was stored in the database).""" presenter = AnnotationJSONPresenter(context) return presenter.asdict()
def read(context, request): """Return the annotation (simply how it was stored in the database).""" links_service = request.find_service(name='links') presenter = AnnotationJSONPresenter(context.annotation, links_service) return presenter.asdict()