From 0f06c326acb3147f46157edb88c5fb3679a038b5 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Thu, 1 Jun 2023 17:16:16 +0200 Subject: [PATCH 1/4] Add rangeref to the skeleton modifier --- utils/modify_skeleton.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/utils/modify_skeleton.py b/utils/modify_skeleton.py index 4eeffc9..bfda576 100644 --- a/utils/modify_skeleton.py +++ b/utils/modify_skeleton.py @@ -5,6 +5,13 @@ "before": "class ManifestRef(Reference):\n type: Optional[constr(regex=r'^Manifest$')] = None\n", "after": "\n\nclass CanvasRef(Reference):", "data": "\n class Config:\n extra = Extra.allow\n" + }, + { + "description": "Re-add RangeRef", + "type": "insert", + "before": "class CanvasRef(Reference):\n type: Optional[constr(regex=r'^Canvas$')] = None\n", + "after": "\n\n", + "data": "\n\nclass RangeRef(Reference):\n type: Optional[constr(regex=r'^Range$')] = None\n" } ] From 92c3a5cd022577d39ed48c1f7ae6a2cb554d688d Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Thu, 1 Jun 2023 17:24:36 +0200 Subject: [PATCH 2/4] Update skeleton modifier data to be accurate for new changes --- utils/modify_skeleton.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/modify_skeleton.py b/utils/modify_skeleton.py index bfda576..4546a45 100644 --- a/utils/modify_skeleton.py +++ b/utils/modify_skeleton.py @@ -2,7 +2,7 @@ { "description": "Allow extra properties on ManifestRef", "type": "insert", - "before": "class ManifestRef(Reference):\n type: Optional[constr(regex=r'^Manifest$')] = None\n", + "before": "class ManifestRef(Reference):\n type: constr(regex=r'^Manifest$') = 'Manifest'\n", "after": "\n\nclass CanvasRef(Reference):", "data": "\n class Config:\n extra = Extra.allow\n" }, @@ -10,7 +10,7 @@ "description": "Re-add RangeRef", "type": "insert", "before": "class CanvasRef(Reference):\n type: Optional[constr(regex=r'^Canvas$')] = None\n", - "after": "\n\n", + "after": "\n\nModel.update_forward_refs()", "data": "\n\nclass RangeRef(Reference):\n type: Optional[constr(regex=r'^Range$')] = None\n" } ] From 4a687754e280451e070e02ad1759202cfa39e4f7 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Thu, 1 Jun 2023 17:24:45 +0200 Subject: [PATCH 3/4] Regenerate skeleton --- iiif_prezi3/skeleton.py | 81 +++++++++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 27 deletions(-) diff --git a/iiif_prezi3/skeleton.py b/iiif_prezi3/skeleton.py index ccc860c..eca87b9 100644 --- a/iiif_prezi3/skeleton.py +++ b/iiif_prezi3/skeleton.py @@ -1,6 +1,6 @@ # generated by datamodel-codegen: # filename: iiif_3_0.json -# timestamp: 2023-02-17T13:09:25+00:00 +# timestamp: 2023-06-01T15:24:07+00:00 from __future__ import annotations @@ -56,7 +56,7 @@ class ViewingDirection(Base): class Id(Base): - __root__: AnyUrl = Field(..., title='Id must be presesnt and must be a URI') + __root__: AnyUrl = Field(..., title='Id must be present and must be a URI') class LngString(Base): @@ -94,13 +94,33 @@ class Format(Base): __root__: constr(regex=r'^[a-z][a-z]*/.*$') -class AnnoSelectorItem(Base): +class SelectorItem(Base): type: str - t: Optional[Duration] = None + t: Duration -class AnnoSelector(Base): - __root__: Union[AnyUrl, AnnoSelectorItem] +class SelectorItem1(Base): + type: constr(regex=r'^FragmentSelector$') = 'FragmentSelector' + conformsTo: AnyUrl = 'http://www.w3.org/TR/media-frags/' + value: Any + + +class SelectorItem2(Base): + type: constr(regex=r'^SvgSelector$') = 'SvgSelector' + value: Any + + +class SelectorItem3(Base): + type: constr(regex=r'^ImageApiSelector$') = 'ImageApiSelector' + region: Optional[Any] = None + size: Optional[Any] = None + rotation: Optional[Any] = None + quality: Optional[Any] = None + format: Optional[Any] = None + + +class Selector(Base): + __root__: Union[AnyUrl, SelectorItem, SelectorItem1, SelectorItem2, SelectorItem3] class NavPlace(Base): @@ -142,8 +162,8 @@ class SpecificResource(Base): type: constr(regex=r'^SpecificResource$') = 'SpecificResource' format: Optional[Format] = None accessibility: Optional[str] = None - source: Id - selector: Union[AnnoSelector, List[AnnoSelector]] + source: Union[Id, Class] + selector: Union[Selector, List[Selector]] class HomepageItem(Class): @@ -165,6 +185,7 @@ class PartOf(Base): class Item(Class): type: constr(regex=r'^Canvas$') = 'Canvas' + items: List class SeeAlso(Base): @@ -179,18 +200,15 @@ class Model(Base): __root__: Union[Manifest, Collection, AnnotationPage] -class AnnotationPage(Base): - class Config: - extra = Extra.forbid - - context: Optional[Any] = Field(None, alias='@context') +class AnnotationPage(Class): + context: Optional[Union[List[AnyUrl], str]] = Field(None, alias='@context') id: Id type: constr(regex=r'^AnnotationPage$') = 'AnnotationPage' rendering: Optional[External] = None label: Optional[LngString] = None service: Optional[Service] = None thumbnail: Optional[List[Resource]] = None - items: Optional[List[Annotation]] = None + items: List[Annotation] class Collection(Class): @@ -217,7 +235,7 @@ class Collection(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: Optional[List[Union[ManifestRef, CollectionRef, Collection]]] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class Manifest(Class): @@ -246,7 +264,7 @@ class Manifest(Class): partOf: Optional[PartOf] = None items: Optional[List[Canvas]] = None structures: Optional[List[Range]] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class AccompanyingCanvas(Class): @@ -269,7 +287,7 @@ class AccompanyingCanvas(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: List[AnnotationPage] - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class BodyItem(Choice): @@ -308,7 +326,7 @@ class Canvas(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: List[AnnotationPage] - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class PlaceholderCanvas(Class): @@ -331,7 +349,7 @@ class PlaceholderCanvas(Class): behavior: Optional[Behavior] = None partOf: Optional[PartOf] = None items: List[AnnotationPage] - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class ProviderItem(Class): @@ -352,9 +370,9 @@ class Range(Class): service: Optional[Service] = None placeholderCanvas: Optional[PlaceholderCanvas] = None accompanyingCanvas: Optional[AccompanyingCanvas] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None thumbnail: Optional[List[Resource]] = None - items: List[Union[SpecificResource, Item, Range, CanvasRef, RangeRef]] + items: List[Union[SpecificResource, Item, Range, CanvasRef]] class ResourceItem(Base): @@ -369,7 +387,7 @@ class ResourceItem(Base): format: Optional[Format] = None label: Optional[LngString] = None thumbnail: Optional[List[Resource]] = None - annotations: Optional[List[AnnotationPage]] = None + annotations: Optional[List[Union[AnnotationPage, AnnotationPageRef]]] = None class Resource(Base): @@ -396,29 +414,37 @@ class AnnotationCollection(Class): type: constr(regex=r'^AnnotationCollection$') = 'AnnotationCollection' rendering: Optional[External] = None partOf: Optional[PartOf] = None - next: Optional[AnnotationPage] = None - first: Optional[AnnotationPage] = None - last: Optional[AnnotationPage] = None + next: Optional[AnnotationPageRef] = None + first: Optional[AnnotationPageRef] = None + last: Optional[AnnotationPageRef] = None service: Optional[Service] = None thumbnail: Optional[List[Resource]] = None items: Optional[List[Annotation]] = None class Reference(Base): + class Config: + extra = Extra.allow + id: Id - label: LngString + label: Optional[LngString] = None type: constr( regex=r'^Manifest$|^AnnotationPage$|^Collection$|^AnnotationCollection$|^Canvas$|^Range$' ) thumbnail: Optional[List[Resource]] = None +class AnnotationPageRef(Reference): + type: Optional[constr(regex=r'^AnnotationPage$')] = None + + class CollectionRef(Reference): type: Optional[constr(regex=r'^Collection$')] = None + label: LngString class ManifestRef(Reference): - type: Optional[constr(regex=r'^Manifest$')] = None + type: constr(regex=r'^Manifest$') = 'Manifest' class Config: extra = Extra.allow @@ -446,3 +472,4 @@ class RangeRef(Reference): ResourceItem.update_forward_refs() ServiceItem.update_forward_refs() ServiceItem1.update_forward_refs() +AnnotationCollection.update_forward_refs() From 91261a78876152d59bb9c907087eff9dd14f74b0 Mon Sep 17 00:00:00 2001 From: Mike Bennett Date: Thu, 1 Jun 2023 17:25:51 +0200 Subject: [PATCH 4/4] Add AnnotationPage to AutoItems helper as field is now required --- iiif_prezi3/helpers/auto_fields.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iiif_prezi3/helpers/auto_fields.py b/iiif_prezi3/helpers/auto_fields.py index 727f7b8..8860f43 100644 --- a/iiif_prezi3/helpers/auto_fields.py +++ b/iiif_prezi3/helpers/auto_fields.py @@ -181,6 +181,6 @@ def __init__(self): # Set up some obvious defaults ai.register_on_class(AnnotationPage, Class) al.register_on_class(KeyValueString, Class, Reference) -ait.register_on_class(Canvas, Range) +ait.register_on_class(Canvas, Range, AnnotationPage) alst.register_on_class(Class, AnnotationPage, ResourceItem, ServiceItem1, NavPlace, Reference, ProviderItem) allst.register_on_class(HomepageItem)