Source code for betty.ancestry.link

"""
The Link API allows data to reference external resources.
"""

from __future__ import annotations

from typing import final, Any, MutableSequence, TYPE_CHECKING, Self

from typing_extensions import override

from betty.ancestry.description import HasDescription
from betty.ancestry.locale import HasLocale
from betty.ancestry.media_type import HasMediaType
from betty.json.linked_data import (
    JsonLdObject,
    dump_link,
    LinkedDataDumpableJsonLdObject,
    JsonLdSchema,
)
from betty.json.schema import String, Array
from betty.link import Link as StdLink
from betty.locale import UNDETERMINED_LOCALE
from betty.locale.localizable import (
    OptionalStaticTranslationsLocalizableAttr,
    ShorthandStaticTranslations,
    StaticTranslationsLocalizableSchema,
    StaticTranslationsLocalizable,
)
from betty.privacy import is_public

if TYPE_CHECKING:
    from betty.serde.dump import DumpMapping, Dump
    from betty.project import Project
    from betty.media_type import MediaType






[docs] @final class LinkSchema(JsonLdObject): """ A JSON Schema for :py:class:`betty.ancestry.link.Link`. """
[docs] def __init__(self, json_ld_schema: JsonLdSchema): super().__init__(json_ld_schema, def_name="link", title="Link") self.add_property( "url", String( format=String.Format.URI, description="The full URL to the other resource.", ), ) self.add_property( "relationship", String( description="The relationship between this resource and the link target (https://en.wikipedia.org/wiki/Link_relation)." ), False, ) self.add_property( "label", StaticTranslationsLocalizableSchema( title="Label", description="The human-readable link label." ), False, )
[docs] @classmethod async def new(cls) -> Self: """ Create a new instance. """ return cls(await JsonLdSchema.new())
[docs] class LinkCollectionSchema(Array): """ A JSON Schema for :py:class:`betty.ancestry.link.Link` collections. """
[docs] def __init__(self, link_schema: LinkSchema): super().__init__(link_schema, def_name="linkCollection", title="Links")
[docs] @classmethod async def new(cls) -> Self: """ Create a new instance. """ return cls(await LinkSchema.new())