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

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.ancestry.privacy import is_public
from betty.json.linked_data import LinkedDataDumpable, JsonLdObject, dump_link
from betty.json.schema import Object, String, Array
from betty.locale import UNDETERMINED_LOCALE
from betty.locale.localizable import (
    OptionalStaticTranslationsLocalizableAttr,
    ShorthandStaticTranslations,
    StaticTranslationsLocalizableSchema,
)
from betty.media_type.media_types import JSON_LD, HTML
from betty.model import Entity, GeneratedEntityId

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






[docs] class LinkSchema(JsonLdObject): """ A JSON Schema for :py:class:`betty.ancestry.link.Link`. """
[docs] def __init__(self): super().__init__(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] class LinkCollectionSchema(Array): """ A JSON Schema for :py:class:`betty.ancestry.link.Link` collections. """
[docs] def __init__(self): super().__init__(LinkSchema(), def_name="linkCollection", title="Links")