|
| 1 | +# -*- coding: utf-8; -*- |
| 2 | +# |
| 3 | +# This file is part of Superdesk. |
| 4 | +# |
| 5 | +# Copyright 2013, 2025 Sourcefabric z.u. and contributors. |
| 6 | +# |
| 7 | +# For the full copyright and license information, please see the |
| 8 | +# AUTHORS and LICENSE files distributed with this source code, or |
| 9 | +# at https://www.sourcefabric.org/superdesk/license |
| 10 | + |
| 11 | + |
| 12 | +from enum import Enum, unique |
| 13 | +import logging |
| 14 | +from typing import Annotated, Any |
| 15 | + |
| 16 | +from pydantic import BaseModel, ConfigDict, Field |
| 17 | +from quart_babel import gettext as _ |
| 18 | + |
| 19 | +from superdesk.core.resources import ResourceModel |
| 20 | +from superdesk.core.resources.model import Dataclass, ResourceModel |
| 21 | +from superdesk.core.resources.validators import validate_maxlength |
| 22 | + |
| 23 | +logger = logging.getLogger(__name__) |
| 24 | + |
| 25 | + |
| 26 | +class Tag(Dataclass): |
| 27 | + text: str |
| 28 | + |
| 29 | + |
| 30 | +class Item(BaseModel): |
| 31 | + name: str |
| 32 | + qcode: str |
| 33 | + is_active: bool = True |
| 34 | + |
| 35 | + |
| 36 | +class DateShortcut(Dataclass): |
| 37 | + value: int |
| 38 | + term: str |
| 39 | + label: str |
| 40 | + |
| 41 | + |
| 42 | +class CustomFieldConfig(Dataclass): |
| 43 | + increment_steps: list[int] |
| 44 | + initial_offset_minutes: int |
| 45 | + |
| 46 | + |
| 47 | +@unique |
| 48 | +class CVAccessType(str, Enum): |
| 49 | + MANAGEABLE = "manageable" |
| 50 | + UNMANAGEABLE = "unmanageable" |
| 51 | + |
| 52 | + |
| 53 | +@unique |
| 54 | +class SelectionType(str, Enum): |
| 55 | + SINGLE_SELECTION = "single selection" |
| 56 | + MULTI_SELECTION = "multi selection" |
| 57 | + DO_NOT_SHOW = "do not show" |
| 58 | + |
| 59 | + |
| 60 | +class VocabulariesResourceModel(ResourceModel): |
| 61 | + display_name: str |
| 62 | + description: str | None = None |
| 63 | + helper_text: Annotated[str | None, validate_maxlength(120)] = None |
| 64 | + tags: list[Tag] | None = None |
| 65 | + popup_width: int | None = None |
| 66 | + management_type: Annotated[CVAccessType, Field(alias="type")] |
| 67 | + items: list[Item] |
| 68 | + selection_type: SelectionType | None = None |
| 69 | + read_only: bool | None = None |
| 70 | + schema_field: str | None = None |
| 71 | + dependent: bool = False |
| 72 | + service: dict[str, int] = Field(default_factory=dict) |
| 73 | + priority: int = 0 |
| 74 | + unique_field: str | None = None |
| 75 | + schema: dict[str, dict] |
| 76 | + field_type_: str | None = None |
| 77 | + field_options_: dict[str, Any] = Field(default_factory=dict) |
| 78 | + init_version: int = 0 |
| 79 | + preffered_items: bool = False |
| 80 | + disable_entire_category_selection: bool = False |
| 81 | + date_shortcuts: list[DateShortcut] | None = None |
| 82 | + custom_field_type: str | None = None |
| 83 | + custom_field_config: CustomFieldConfig | None = None |
| 84 | + translations: dict[str, dict[str, Any]] = Field(default_factory=dict) |
0 commit comments