def get_page_lines(book_id, page_id): lines = repository.get_lines(book_id, page_id) if lines is None: raise ApiException( "Could not find lines for page '{}' in book '{}'".format( page_id, book_id), 404) fac = ManifestFactory() fac.set_base_prezi_uri(flask.request.url_root[:-1] + '/iiif/' + book_id + '/' + page_id) annotation_list = fac.annotationList(ident=book_id + '/' + page_id) # FIXME: Workaround for a really stupid bug in iiif-prezi: # The library sets .resources as a class-attribute, which is why: # - it will not get serialized during toJSON # - multiple instances share their resources annotation_list.resources = [] for idx, (text, x, y, w, h) in enumerate(lines): anno = annotation_list.annotation(ident='line-{}'.format(idx)) anno.text(text=text) anno.on = (get_canvas_id(book_id, page_id) + "#xywh={},{},{},{}".format(x, y, w, h)) out_data = annotation_list.toJSON(top=True) if not annotation_list.resources: # NOTE: iiif-prezi strips empty lists from the resulting JSON, # so we have to add the empty list ourselves... out_data['resources'] = [] return flask.jsonify(out_data)
def get_page_lines(book_id, page_id): lines = repository.get_lines(book_id, page_id) fac = ManifestFactory() base_url = app.config.get('BASE_URL', 'http://localhost:5000') fac.set_base_metadata_uri(base_url + '/iiif/' + book_id) annotation_list = fac.annotationList(ident=page_id) for idx, (text, x, y, w, h) in enumerate(lines): anno = annotation_list.annotation(ident='line-{}'.format(idx)) anno.text(text=text) anno.on = (get_canvas_id(book_id, page_id) + "#xywh={},{},{},{}".format(x, y, w, h)) out_data = annotation_list.toJSON(top=True) if not annotation_list.resources: # NOTE: iiif-prezi strips empty list from the resulting JSON, # so we have to add the empty list ourselves... out_data['resources'] = [] return flask.jsonify(out_data)