Ejemplo n.º 1
0
def get_annotation_list(source_type, options, canvas_name):
    source_type = source_mapping.get((source_type, 'base'))
    if not source_type:
        return jsonify({"message": "bad type", "success": False}), 502
    if not is_dynamic_source(source_type):
        options = iiifoo_utils.parse_mapped_rest_options(options, pub_req_optmap)
        pi = Image.query.filter_by(
            identifier=canvas_name,
            manifest_id=options['manifest_id'],
            source_type=source_type.type_name,
            source_url=options['source_url']
        ).first()
        if pi:
            response = jsonify(simplejson.loads(pi.annotations)), 200
        else:
            response = jsonify({"message": "image not found",
                                "success": False}), 404
        return response
    else:
        options = iiifoo_utils.parse_rest_options(options)
        nph = source_type(options)
        manifest_url = url_for('.get_manifest', source_type=source_type,
                               options=options)
        manifest_url = "".join([request.url_root.rstrip('/'), manifest_url])
        annotations = nph.get_annotations(canvas_name=canvas_name,
                                          manifest_url=manifest_url)
        return jsonify(annotations)
Ejemplo n.º 2
0
def get_manifest(source_type, options):
    """Get a manifest for the given info.

    For authoring sources, gets it from db.

    For dynamic sources, creates it on request.
    """
    source_type = source_mapping.get((source_type, 'base'))
    if not source_type:
        return jsonify({"message": "bad type", "success": False}), 502
    if not is_dynamic_source(source_type):
        options = iiifoo_utils.parse_mapped_rest_options(options, pub_req_optmap)
        if not source_type:
            return jsonify({"message": "bad type", "success": False}), 502
        manifest = Manifest.query.filter_by(
            id=options['manifest_id'], source_type=source_type.type_name,
            source_url=options['source_url']
        ).first()
        if not manifest:
            return jsonify({"message": "manifest not found",
                            "success": False}), 404
        # canvases = manifest['sequences'][0]['canvases']
        # canvas_image_ids = [image_id_from_canvas_id(canvas['@id'])
        #                     for canvas in canvases]
        # for image_id in canvas_image_ids:
        #     if source_type.allowed_access(image_id=image_id,
        #                                   cookie=session[''])  # TODO
        responsetext = manifest.manifest
    else:
        parsed_options = iiifoo_utils.parse_rest_options(options)
        nph = source_type(parsed_options)
        responsetext = \
            nph.get_manifest(url_root=request.base_url.rstrip("manifest"))
    return responsetext, 200
Ejemplo n.º 3
0
 def _export_image(params, source_type):
     ph = source_mapping[(source_type, 'export')]
     if is_dynamic_source(ph):
         raise exception.InvalidAPIAccess("This source doesn't "
                                          "support authoring.")
     ph = ph(params)
     images = ph.images
     optpath = iiifoo_utils.list_to_rest_options([ph.source_url,
                                                  ph.manifest_identifier])
     manifest_url = url_for('viewing.get_manifest', source_type=source_type,
                            options=optpath)
     # Because url_for will quote it again, we'll re-unquote it.
     # Alternatively, create a RawPathConverter extending
     # werkzeug.routing.PathConverter and remove the quoting in to_url.
     manifest_url = unquote(manifest_url)
     manifest_url = request.url_root + manifest_url.lstrip('/')
     if images:
         manifest_ops.add(db.session,
                          ph.manifest_identifier, source_type, ph.source_url,
                          ph.manifest_label, ph.manifest_category,
                          ph.metadata, manifest_url, images,
                          ph.user, ph.info,
                          commit=True)
         logger.info("Exporting request processed, "
                     "manifest generated.")
         resp = jsonify({"status": "exported", "success": True,
                         "message": "exported %s image(s)" % len(images)})
     else:
         resp = jsonify({"status": "did nothing", "message":
                         "no exportable images found.", "success": False})
         logger.info("No exportable images found!")
     return resp
Ejemplo n.º 4
0
def specific_manifest(source_type):
    if request.method == 'POST':
        params = request.get_json()
    else:
        params = request.args
    try:
        ph = source_mapping[(source_type, 'view')]
    except KeyError:
        try:
            ph = source_mapping[(source_type, 'base')]
        except KeyError:
            return "not found", 404
    if not is_dynamic_source(ph):
        ph = ph(params)
        source_url = ph.source_url
        # auth_service = ph.auth_service(source_url)
        canvas_id = ph.canvas_id
        url = url_for('.get_manifest', source_type=source_type,
                      options=list_to_rest_options([
                          source_url,
                          ph.manifest_identifier
                          ])
                      )
        if canvas_id:
            canvas_id = iiif_metadata_url(url, canvas_id, 'canvas')

        # category = manifest.manifest_category
        manifests = Manifest.query.filter_by(
            source_url=source_url,
            source_type=source_type
        )
        manifests = _path_cat_map(manifests)
        response = render_template(
            'mirador2_index.html',  # auth=auth_service,
            uris_and_locations=manifests,
            preloaded_manifest=url,
            do_not_save=True
        ) if not canvas_id else render_template(
            'mirador2_index.html',  # auth=auth_service,
            uris_and_locations=manifests,
            preloaded_manifest=url,
            preloaded_image=canvas_id,
            do_not_save=True
        )
        return response
    else:
        ph = ph(params)
        category = ph.category
        manifest = url_for('.get_manifest', source_type=source_type,
                           options=dict_to_rest_options(request.args))
        return render_template('mirador2_index.html',
                               uris_and_locations=[(manifest, category)],
                               do_not_save=True,
                               preloaded_manifest=manifest)
Ejemplo n.º 5
0
 def _delete_image(params, source_type):
     ph = source_mapping[(source_type, 'delete')]
     if is_dynamic_source(ph):
         raise exception.InvalidAPIAccess("This source doesn't "
                                          "support authoring.")
     ph = ph(params)
     manifest_ops.delete(session=db.session,
                         image_ids=ph.images,
                         manifest_id=ph.manifest_identifier,
                         source_url=ph.source_url, source_type=source_type,
                         user=ph.user, commit=True)
     resp = jsonify({"success": True, "message": "deleted"})
     logger.info("Images deleted!")
     return resp
Ejemplo n.º 6
0
def get_canvas(source_type, options, canvas_name):
    source_type = source_mapping.get((source_type, 'base'))
    if not source_type:
        return jsonify({"message": "bad type", "success": False}), 502
    if not is_dynamic_source(source_type):
        options = iiifoo_utils.parse_mapped_rest_options(options, pub_req_optmap)
        m = Manifest.query.filter_by(
            id=options['manifest_id'],
            source_type=source_type.type_name,
            source_url=options['source_url']
        ).first()
        if not m:
            return jsonify({"message": "manifest not found",
                            "success": False}), 404
        manifest = simplejson.loads(m.manifest)
        canvases = manifest['sequences'][0]['canvases']
        canvas_image_ids = [iiifoo_utils.image_id_from_canvas_id(canvas['@id'])
                            for canvas in canvases]
        index = canvas_image_ids.index(canvas_name)
        response = jsonify(canvases[index]), 200
        return response
    else:
        raise NotImplementedError()