_data_model.py 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. # Copyright 2021-2025 Avaiga Private Limited
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
  4. # the License. You may obtain a copy of the License at
  5. #
  6. # http://www.apache.org/licenses/LICENSE-2.0
  7. #
  8. # Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
  9. # an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
  10. # specific language governing permissions and limitations under the License.
  11. from dataclasses import dataclass
  12. from typing import Any, Dict, List, Optional
  13. from .._repository._base_taipy_model import _BaseModel
  14. from ..common.scope import Scope
  15. from .data_node_id import Edit
  16. @dataclass
  17. class _DataNodeModel(_BaseModel):
  18. id: str
  19. config_id: str
  20. scope: Scope
  21. storage_type: str
  22. owner_id: Optional[str]
  23. parent_ids: List[str]
  24. last_edit_date: Optional[str]
  25. edits: List[Edit]
  26. version: str
  27. validity_days: Optional[float]
  28. validity_seconds: Optional[float]
  29. edit_in_progress: bool
  30. editor_id: Optional[str]
  31. editor_expiration_date: Optional[str]
  32. data_node_properties: Dict[str, Any]
  33. @staticmethod
  34. def from_dict(data: Dict[str, Any]):
  35. return _DataNodeModel(
  36. id=data["id"],
  37. config_id=data["config_id"],
  38. scope=Scope._from_repr(data["scope"]),
  39. storage_type=data["storage_type"],
  40. owner_id=data.get("owner_id"),
  41. parent_ids=_BaseModel._deserialize_attribute(data.get("parent_ids", [])),
  42. last_edit_date=data.get("last_edit_date"),
  43. edits=_BaseModel._deserialize_attribute(data["edits"]),
  44. version=data["version"],
  45. validity_days=data["validity_days"],
  46. validity_seconds=data["validity_seconds"],
  47. edit_in_progress=bool(data.get("edit_in_progress", False)),
  48. editor_id=data.get("editor_id", None),
  49. editor_expiration_date=data.get("editor_expiration_date"),
  50. data_node_properties=_BaseModel._deserialize_attribute(data["data_node_properties"]),
  51. )
  52. def to_list(self):
  53. return [
  54. self.id,
  55. self.config_id,
  56. repr(self.scope),
  57. self.storage_type,
  58. self.owner_id,
  59. _BaseModel._serialize_attribute(self.parent_ids),
  60. self.last_edit_date,
  61. _BaseModel._serialize_attribute(self.edits),
  62. self.version,
  63. self.validity_days,
  64. self.validity_seconds,
  65. self.edit_in_progress,
  66. self.editor_id,
  67. self.editor_expiration_date,
  68. _BaseModel._serialize_attribute(self.data_node_properties),
  69. ]