Beispiel #1
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
Beispiel #2
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)
Beispiel #3
0
def _path_cat_map(manifests):
    manifest_paths = [
        unquote(url_for('.get_manifest', source_type=item.source_type,
                options=list_to_rest_options([
                    item.source_url,
                    item.id
                ])))
        for item in manifests
    ]
    manifest_categories = [item.manifest_category for item in manifests]
    return zip(manifest_paths, manifest_categories)