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

Adds args for intermediate objects #139

Merged
merged 7 commits into from
Dec 24, 2022
Merged
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
18 changes: 12 additions & 6 deletions iiif_prezi3/helpers/annotation_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,25 @@

class AnnotationHelpers:

def add_annotation(self, annotation):
def add_annotation(self, annotation, anno_page_id=None):
"""Adds the annotation object to the (AnnotationPage object in the) annotations property.

Creates an AnnotationPage object if it doesn't exist.

Args:
annotation (Annotation): the Annotation to add
annotation (Annotation): the Annotation to add
anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.

Returns:
annotation (Annotation): the Annotation attached to the AnnotationPage.

Creates an AnnotationPage object if it doesn't exist.
"""
if not self.annotations:
self.annotations = list()

if len(self.annotations) == 0:
# add empty AnnotationPage
anno_page = AnnotationPage(items=[])
anno_page = AnnotationPage(id=anno_page_id, items=[])
self.annotations.append(anno_page)
else:
anno_page = self.annotations[0]
Expand All @@ -27,14 +32,15 @@ def add_annotation(self, annotation):

return annotation

def make_annotation(self, **kwargs):
def make_annotation(self, anno_page_id=None, **kwargs):
"""Creates an annotation object and adds it to the annotations property using .add_annotation().

Args:
anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.
**kwargs (): see Annotation.
"""
annotation = Annotation(**kwargs)
self.add_annotation(annotation)
self.add_annotation(annotation, anno_page_id=anno_page_id)
return annotation


Expand Down
18 changes: 13 additions & 5 deletions iiif_prezi3/helpers/create_canvas_from_iiif.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,19 @@
class CreateCanvasFromIIIF:
# should probably be added to canvas helpers

def create_canvas_from_iiif(self, url, **kwargs):
def create_canvas_from_iiif(self, url, anno_id=None, anno_page_id=None, **kwargs):
"""Create a canvas from a IIIF Image URL.

Creates a canvas from a IIIF Image service passing any
kwargs to the Canvas. Returns a Canvas object
Creates a canvas from a IIIF Image service passing any kwargs to the Canvas.

Args:
url (str): An HTTP URL at which at a IIIF Image is available.
anno_id (str): An HTTP URL for the annotation to which the image will be attached.
anno_page_id (str): An HTTP URL for the annotation page to which the annotation will be attached.
**kwargs (): see Canvas

Returns:
canvas (Canvas): the Canvas created from the IIIF Image.

"""
canvas = Canvas(**kwargs)
Expand Down Expand Up @@ -40,9 +48,9 @@ def create_canvas_from_iiif(self, url, **kwargs):
body.id = f'{infoJson["id"]}/full/max/0/default.jpg'
body.format = "image/jpeg"

annotation = Annotation(motivation='painting', body=body, target=canvas.id)
annotation = Annotation(id=anno_id, motivation='painting', body=body, target=canvas.id)

annotationPage = AnnotationPage()
annotationPage = AnnotationPage(id=anno_page_id)
annotationPage.add_item(annotation)

canvas.add_item(annotationPage)
Expand Down