|
| 1 | +from datetime import datetime |
| 2 | +from typing import Any, Annotated |
| 3 | +from pydantic import Field |
| 4 | + |
| 5 | +from planning.types.base import BasePlanningModel |
| 6 | + |
| 7 | +from superdesk.utc import utcnow |
| 8 | +from superdesk.core.resources import fields, dataclass |
| 9 | +from superdesk.core.resources.validators import validate_data_relation_async, validate_iunique_value_async |
| 10 | +from superdesk.core.utils import generate_guid, GUID_NEWSML |
| 11 | + |
| 12 | + |
| 13 | +@dataclass |
| 14 | +class Position: |
| 15 | + latitude: float | None = None |
| 16 | + longitude: float | None = None |
| 17 | + altitude: int | None = None |
| 18 | + gps_datum: str | None = None |
| 19 | + |
| 20 | + |
| 21 | +@dataclass |
| 22 | +class Address: |
| 23 | + title: str | None = None |
| 24 | + line: list[str] | None = None |
| 25 | + suburb: str | None = None |
| 26 | + city: str | None = None |
| 27 | + state: str | None = None |
| 28 | + postal_code: str | None = None |
| 29 | + country: str | None = None |
| 30 | + locality: str | None = None # Aka city |
| 31 | + area: str | None = None |
| 32 | + external: dict | None = None |
| 33 | + boundingbox: list | None = None |
| 34 | + address_type: str | None = Field(alias="type", default=None) |
| 35 | + |
| 36 | + |
| 37 | +class LocationResourceModel(BasePlanningModel): |
| 38 | + guid: Annotated[ |
| 39 | + fields.Keyword, |
| 40 | + validate_iunique_value_async("locations", "guid"), |
| 41 | + Field(default_factory=lambda: generate_guid(type=GUID_NEWSML)), |
| 42 | + ] |
| 43 | + unique_id: Annotated[int, validate_iunique_value_async("locations", "unique_id")] | None = None |
| 44 | + unique_name: Annotated[fields.Keyword, validate_iunique_value_async("locations", "unique_name")] | None = None |
| 45 | + version: int | None = None |
| 46 | + ingest_id: fields.Keyword | None = None |
| 47 | + |
| 48 | + # Audit Information |
| 49 | + firstcreated: datetime = Field(default_factory=utcnow) |
| 50 | + versioncreated: datetime = Field(default_factory=utcnow) |
| 51 | + |
| 52 | + # Ingest Details |
| 53 | + ingest_provider: Annotated[fields.ObjectId, validate_data_relation_async("ingest_providers")] | None = None |
| 54 | + source: fields.Keyword | None = None |
| 55 | + original_source: fields.Keyword | None = None |
| 56 | + ingest_provider_sequence: fields.Keyword | None = None |
| 57 | + |
| 58 | + # Location Details |
| 59 | + # NewsML-G2 Event properties See: |
| 60 | + # https://iptc.org/std/NewsML-G2/2.23/specification/XML-Schema-Doc-Core/ConceptItem.html#LinkC5 |
| 61 | + name: str | None = None |
| 62 | + translations: dict[str, Any] | None = None |
| 63 | + location_type: str = Field(alias="type", default="Unclassified") |
| 64 | + |
| 65 | + # Position Details |
| 66 | + # NewsML-G2 poiDetails properties See IPTC-G2-Implementation_Guide 12.6.3 |
| 67 | + # or https://iptc.org/std/NewsML-G2/2.23/specification/XML-Schema-Doc-Power/ConceptItem.html#LinkAA |
| 68 | + position: Position | None = None |
| 69 | + |
| 70 | + # Address Details |
| 71 | + address: Address | None = None |
| 72 | + |
| 73 | + # Other Location Info |
| 74 | + access: list[str] | None = None |
| 75 | + details: list[str] | None = None |
| 76 | + created: datetime | None = None |
| 77 | + ceased_to_exist: datetime | None = None |
| 78 | + open_hours: str | None = None |
| 79 | + capacity: str | None = None |
| 80 | + contact_info: list[str] | None = None |
| 81 | + is_active: bool = Field( |
| 82 | + default=True, description="Flag indicates if the location is active and should be shown in the UI" |
| 83 | + ) |
0 commit comments