Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt to Address Issue-225 and Issue-226. #227

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions iiif_prezi3/helpers/make_collection.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
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.
"""
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should update the description to mention if you don't pass in items then it creates a CollectionRef.

How easy is it to convert a CollectionRef to Collection? If a user doesn't pass items then tries to add it later will this cause an error? Should we have two methods, make_collection and make_collection_ref to make it more explicit?

child_collection = Collection(**kwargs)
if 'items' not in kwargs:
child_collection = CollectionRef(**kwargs)
elif not kwargs['items']:
kwargs.pop('items')
child_collection = CollectionRef(**kwargs)
else:
child_collection = Collection(**kwargs)
self.add_item(child_collection)
return child_collection

Expand Down
2 changes: 1 addition & 1 deletion iiif_prezi3/helpers/make_manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
4 changes: 3 additions & 1 deletion tests/test_make_collection.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Loading