From 4ec242891bda9196abe0bd103f261e2a937b7a5d Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Thu, 16 Jan 2025 18:16:15 -0600 Subject: [PATCH 1/4] Init fix for Issue 225. --- iiif_prezi3/helpers/make_collection.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/iiif_prezi3/helpers/make_collection.py b/iiif_prezi3/helpers/make_collection.py index 435e89e..15e3a3d 100644 --- a/iiif_prezi3/helpers/make_collection.py +++ b/iiif_prezi3/helpers/make_collection.py @@ -1,17 +1,22 @@ from ..loader import monkeypatch_schema -from ..skeleton import Collection +from ..skeleton import Collection, CollectionRef class MakeCollection: def make_collection(self, **kwargs): - """Create a Collection. + """Creates a Collection or CollectionRef. Creates a new collection, adds it to the calling Collection `items` and returns the newly created object. Accepts keyword arguments to customize the resulting instance. """ - child_collection = Collection(**kwargs) + if 'items' not in kwargs: + child_collection = CollectionRef(**kwargs) + elif len(kwargs['items']) == 0: + child_collection = CollectionRef(**kwargs) + else: + child_collection = Collection(**kwargs) self.add_item(child_collection) return child_collection From ff9d576474c67ee8020d3d8a16d8fc1b5b471b29 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Sun, 19 Jan 2025 19:48:38 -0600 Subject: [PATCH 2/4] Ensure no items in CollectionRef. --- iiif_prezi3/helpers/make_collection.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/iiif_prezi3/helpers/make_collection.py b/iiif_prezi3/helpers/make_collection.py index 15e3a3d..36b5685 100644 --- a/iiif_prezi3/helpers/make_collection.py +++ b/iiif_prezi3/helpers/make_collection.py @@ -11,9 +11,8 @@ def make_collection(self, **kwargs): and returns the newly created object. Accepts keyword arguments to customize the resulting instance. """ - if 'items' not in kwargs: - child_collection = CollectionRef(**kwargs) - elif len(kwargs['items']) == 0: + if 'items' not in kwargs or not kwargs['items']: + kwargs.pop('items') child_collection = CollectionRef(**kwargs) else: child_collection = Collection(**kwargs) From 71187ac8a24e1645a3fc861412e7bb29c60a40c8 Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Sun, 19 Jan 2025 19:49:57 -0600 Subject: [PATCH 3/4] Ensure no items in ManifestRef. --- iiif_prezi3/helpers/make_manifest.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiif_prezi3/helpers/make_manifest.py b/iiif_prezi3/helpers/make_manifest.py index 742e65e..9d0924f 100644 --- a/iiif_prezi3/helpers/make_manifest.py +++ b/iiif_prezi3/helpers/make_manifest.py @@ -11,9 +11,9 @@ def make_manifest(self, **kwargs): calling Collection items and returns the newly created Manifest. Accepts keyword arguments to customize the resulting instance. """ + kwargs.pop('items', None) manifest = ManifestRef(**kwargs) self.add_item(manifest) - return manifest monkeypatch_schema(Collection, MakeManifest) From c5eaa23b7a102909729ef6fc999d749180afaf1f Mon Sep 17 00:00:00 2001 From: Mark Baggett Date: Mon, 20 Jan 2025 18:27:53 -0600 Subject: [PATCH 4/4] CollectionRefs must have a label. --- iiif_prezi3/helpers/make_collection.py | 4 +++- tests/test_make_collection.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/iiif_prezi3/helpers/make_collection.py b/iiif_prezi3/helpers/make_collection.py index 36b5685..4808b2f 100644 --- a/iiif_prezi3/helpers/make_collection.py +++ b/iiif_prezi3/helpers/make_collection.py @@ -11,7 +11,9 @@ def make_collection(self, **kwargs): and returns the newly created object. Accepts keyword arguments to customize the resulting instance. """ - if 'items' not in kwargs or not kwargs['items']: + if 'items' not in kwargs: + child_collection = CollectionRef(**kwargs) + elif not kwargs['items']: kwargs.pop('items') child_collection = CollectionRef(**kwargs) else: diff --git a/tests/test_make_collection.py b/tests/test_make_collection.py index 7105fcf..d7454bf 100644 --- a/tests/test_make_collection.py +++ b/tests/test_make_collection.py @@ -10,7 +10,9 @@ def setUp(self): def test_make_collection(self): child_collection = self.parent_collection.make_collection( - id='http://iiif.example.org/prezi/Manifest/0') + id='http://iiif.example.org/prezi/Manifest/0', + label="Example Collection" + ) self.assertEqual(len(self.parent_collection.items), 1) self.assertEqual(child_collection.id, 'http://iiif.example.org/prezi/Manifest/0')