From ebe267f79c486e36e123742259b94f23f1c2ab34 Mon Sep 17 00:00:00 2001 From: Satrajit Ghosh Date: Thu, 15 Apr 2021 13:02:38 -0400 Subject: [PATCH] enh: refactor publishable --- dandi/models.py | 47 +++++++++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 24 deletions(-) diff --git a/dandi/models.py b/dandi/models.py index 71569ed2e..2901113c0 100644 --- a/dandi/models.py +++ b/dandi/models.py @@ -581,6 +581,10 @@ class Session(Activity): schemaKey: Literal["Session"] = Field("Session", readOnly=True) +class PublishActivity(Activity): + schemaKey: Literal["PublishActivity"] = Field("PublishActivity", readOnly=True) + + class Locus(DandiBaseModel): identifier: Union[Identifier, List[Identifier]] = Field( description="Identifier for genotyping locus" @@ -873,26 +877,6 @@ def check_data(cls, values): } -class PublishedDandisetMeta(DandisetMeta): - publishedBy: HttpUrl = Field( - description="The URL should contain the provenance of the publishing process.", - readOnly=True, - nskey="dandi", - ) # TODO: formalize "publish" activity to at least the Actor - datePublished: date = Field(readOnly=True, title="Publication date and time", nskey="schema") - version: str = Field(readOnly=True, nskey="schema") - doi: str = Field( - None, - title="DOI", - readOnly=True, - pattern=r"^10\.[A-Za-z0-9.\/-]+", - nskey="dandi", - ) - url: HttpUrl = Field( - None, readOnly=True, description="permalink to the item", nskey="schema" - ) - - class BareAssetMeta(CommonModel): """Metadata used to describe an asset anywhere (local or server). @@ -962,18 +946,33 @@ class AssetMeta(BareAssetMeta, Identifiable): contentUrl: Optional[List[HttpUrl]] = Field(None, readOnly=True, nskey="schema") -class PublishedAssetMeta(AssetMeta): +class Publishable(DandiBaseModel): id: str = Field(readOnly=True, description="Uniform resource identifier") - publishedBy: HttpUrl = Field( + publishedBy: Union[HttpUrl, PublishActivity] = Field( description="The URL should contain the provenance of the publishing process.", readOnly=True, nskey="dandi", ) # TODO: formalize "publish" activity to at least the Actor - datePublished: date = Field(readOnly=True, nskey="schema") + datePublished: datetime = Field(readOnly=True, nskey="schema") url: HttpUrl = Field( - None, readOnly=True, description="permalink to the item", nskey="schema" + readOnly=True, description="permalink to the item", nskey="schema" + ) + + +class PublishedDandisetMeta(DandisetMeta, Publishable): + version: str = Field(readOnly=True, nskey="schema") + doi: str = Field( + None, + title="DOI", + readOnly=True, + pattern=r"^10\.[A-Za-z0-9.\/-]+", + nskey="dandi", ) +class PublishedAssetMeta(AssetMeta, Publishable): + pass + + def get_schema_version(): return DANDI_SCHEMA_VERSION