Coverage for src/paperap/models/share_links/model.py: 86%
21 statements
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-20 13:17 -0400
« prev ^ index » next coverage.py v7.6.12, created at 2025-03-20 13:17 -0400
1"""
2----------------------------------------------------------------------------
4 METADATA:
6 File: share_links.py
7 Project: paperap
8 Created: 2025-03-04
9 Version: 0.0.8
10 Author: Jess Mann
11 Email: jess@jmann.me
12 Copyright (c) 2025 Jess Mann
14----------------------------------------------------------------------------
16 LAST MODIFIED:
18 2025-03-04 By Jess Mann
20"""
22from __future__ import annotations
24from datetime import datetime
25from typing import TYPE_CHECKING, Any
27from pydantic import Field, field_serializer
29from paperap.models.abstract.model import StandardModel
30from paperap.models.share_links.queryset import ShareLinksQuerySet
32if TYPE_CHECKING:
33 from paperap.models.correspondent import Correspondent
34 from paperap.models.document import Document
35 from paperap.models.document_type import DocumentType
36 from paperap.models.storage_path import StoragePath
37 from paperap.models.tag import Tag
40class ShareLinks(StandardModel):
41 expiration: datetime | None = None
42 slug: str | None = None
43 document: int | None = None
44 created: datetime | None = Field(description="Creation timestamp", default=None, alias="created_on")
45 file_version: str | None = None
47 class Meta(StandardModel.Meta):
48 queryset = ShareLinksQuerySet
50 @field_serializer("expiration", "created")
51 def serialize_datetime(self, value: datetime | None) -> str | None:
52 """
53 Serialize a datetime object to an ISO 8601 formatted string
55 Args:
56 value (datetime): The datetime object to serialize
58 Returns:
59 str: The serialized datetime
61 """
62 return value.isoformat() if value else None
64 def get_document(self) -> "Document":
65 """
66 Get the document associated with this share link
68 Returns:
69 Document: The document object
71 """
72 if not self.document:
73 raise ValueError("Document ID not set")
74 return self._client.documents().get(pk=self.document)