_cycle_model.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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
  13. from .._repository._base_taipy_model import _BaseModel
  14. from ..common.frequency import Frequency
  15. from .cycle_id import CycleId
  16. @dataclass
  17. class _CycleModel(_BaseModel):
  18. id: CycleId
  19. name: str
  20. frequency: Frequency
  21. properties: Dict[str, Any]
  22. creation_date: str
  23. start_date: str
  24. end_date: str
  25. @staticmethod
  26. def from_dict(data: Dict[str, Any]):
  27. return _CycleModel(
  28. id=data["id"],
  29. name=data["name"],
  30. frequency=Frequency._from_repr(data["frequency"]),
  31. properties=_BaseModel._deserialize_attribute(data["properties"]),
  32. creation_date=data["creation_date"],
  33. start_date=data["start_date"],
  34. end_date=data["end_date"],
  35. )
  36. def to_list(self):
  37. return [
  38. self.id,
  39. self.name,
  40. repr(self.frequency),
  41. _BaseModel._serialize_attribute(self.properties),
  42. self.creation_date,
  43. self.start_date,
  44. self.end_date,
  45. ]