def _delete_images(manifest_json, images): canvases = manifest_json['sequences'][0]['canvases'] image_ids = [str(image['image_id']) for image in images] canvases_after_deleting = [canvas for canvas in canvases if image_id_from_canvas_id(canvas['@id']) not in image_ids] manifest_json['sequences'][0]['canvases'] = canvases_after_deleting return manifest_json
def check_updated_details(manifest_json, details): sequences = manifest_json['sequences'] canvases = sequences[0]['canvases'] new_image_ids = [image['image_id'] for image in details['images']] updated_canvases = [canvas for canvas in canvases if image_id_from_canvas_id(canvas["@id"]) in new_image_ids] updated_canvases = {image_id_from_canvas_id(canvas["@id"]): canvas for canvas in updated_canvases} assert_equal(manifest_json['label'], details['manifest_label']) for image_id in new_image_ids: canvas = updated_canvases[image_id] image = [image for image in details['images'] if image['image_id'] == image_id][0] assert_equal(canvas['label'], image['name']) assert_equal(canvas['width'], image['width']) assert_equal(canvas['height'], image['height']) image_resource = canvas['images'][0]['resource'] assert_equal(image_resource['service']['@id'], image['path']) assert_equal(image_resource['width'], image['width']) assert_equal(image_resource['height'], image['height'])
def step_impl(context): manifest_id = context.deletion_info['manifest_identifier'] manifest_path = '/iiif/test/%s/%s/manifest' % \ (context.deletion_info['source_url'], manifest_id) response = context.app.get(manifest_path) assert response.status_code == 200, "Failed to retrieve manifest" \ " at path %s" % manifest_path manifest_str = response.data manifest_json = simplejson.loads(manifest_str) canvases = manifest_json['sequences'][0]['canvases'] canvas_image_ids = [image_id_from_canvas_id(canvas['@id']) for canvas in canvases] assert context.deletion_info['images'][0]['image_id'] not \ in canvas_image_ids, "Image not deleted"
def check_annotations_in_list(annotation_list, imageobj): resources = annotation_list['resources'] relevant_resources = [] for resource in resources: if image_id_from_canvas_id(resource['on']) == imageobj['image_id']: relevant_resources.append(resource) list_comments = [item['resource']['chars'] for item in resources if item['motivation'] == "oa:commenting"] list_transcriptions = [item['resource']['chars'] for item in resources if item['resource']['@type'] == "cnt:ContentAsText"] for comment in imageobj.get('comments', []): assert comment['text'] in list_comments, \ "Comment %s not found" % comment['text'] for transcription in imageobj.get('transcriptions', []): assert transcription['text'] in list_transcriptions, \ "Comment %s not found" % transcription['text']
def step_impl(context): canvases = context.manifest_json['sequences'][0]['canvases'] annotated_canvases = canvases[-context.no_of_images:] for index, annotated_canvas in enumerate(annotated_canvases): canvas_id = annotated_canvas['@id'] image_id = image_id_from_canvas_id(canvas_id) anno_list_uri = '/iiif/test/%s/%s/list/%s' % \ (context.authoring_details['source_url'], context.authoring_details['manifest_identifier'], image_id) response = context.app.get(anno_list_uri) assert response.status_code == 200, "Failed to retrieve annotation " \ "list at path %s" % anno_list_uri anno_str = response.data anno_json = simplejson.loads(anno_str) check_annotations_in_list(anno_json, context.authoring_details['images'][index])
def delete(session, image_ids, manifest_id, source_type, source_url, user, commit=False): """ Use session to delete images from manifest with id manifest_id with given source_type and source_url. """ image_ids = [str(image['image_id']) for image in image_ids] pi = Image.query\ .filter(Image.identifier.in_(image_ids))\ .filter(Image.source_type == source_type)\ .filter(Image.source_url == source_url)\ .filter(Image.manifest_id == manifest_id).first() if pi: logger.info("Deleting images :{}".format(image_ids)) session.delete(pi) manifest = Manifest.query.filter_by(id=manifest_id, source_type=source_type, source_url=source_url).first() if manifest: manifest_str = manifest.manifest manifest_json = simplejson.loads(manifest_str) canvases = manifest_json['sequences'][0]['canvases'] canvas_image_ids = [image_id_from_canvas_id(canvas['@id']) for canvas in canvases] for image_id in image_ids: try: index = canvas_image_ids.index(image_id) logger.debug("found index %s" % index) if len(canvases) > 1: canvases.pop(index) manifest.manifest = simplejson.dumps(manifest_json) else: logger.info("deleting manifest") session.delete(manifest) break except ValueError: logger.warning("couldn't find index of canvas") else: logger.info("Couldn't find images {}, so cannot delete." .format(image_ids)) if commit: session.commit()
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()