industrial-model 0.1.28__py3-none-any.whl → 0.1.29__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from abc import abstractmethod
|
|
2
|
+
from datetime import date, datetime
|
|
2
3
|
from typing import (
|
|
3
4
|
Any,
|
|
4
5
|
ClassVar,
|
|
@@ -10,6 +11,8 @@ from typing import (
|
|
|
10
11
|
|
|
11
12
|
from pydantic import PrivateAttr
|
|
12
13
|
|
|
14
|
+
from industrial_model.statements import Column
|
|
15
|
+
|
|
13
16
|
from .base import DBModelMetaclass, RootModel
|
|
14
17
|
|
|
15
18
|
|
|
@@ -45,6 +48,7 @@ class ViewInstanceConfig(TypedDict, total=False):
|
|
|
45
48
|
view_external_id: str | None
|
|
46
49
|
instance_spaces: list[str] | None
|
|
47
50
|
instance_spaces_prefix: str | None
|
|
51
|
+
view_code: str | None
|
|
48
52
|
|
|
49
53
|
|
|
50
54
|
class ViewInstance(InstanceId, metaclass=DBModelMetaclass):
|
|
@@ -56,6 +60,54 @@ class ViewInstance(InstanceId, metaclass=DBModelMetaclass):
|
|
|
56
60
|
def get_view_external_id(cls) -> str:
|
|
57
61
|
return cls.view_config.get("view_external_id") or cls.__name__
|
|
58
62
|
|
|
63
|
+
def generate_model_id(
|
|
64
|
+
self,
|
|
65
|
+
fields: list[str] | list[Column] | list[Any],
|
|
66
|
+
view_code_as_prefix: bool = True,
|
|
67
|
+
separator: str = "-",
|
|
68
|
+
) -> str:
|
|
69
|
+
if not fields:
|
|
70
|
+
raise ValueError("Fields list cannot be empty")
|
|
71
|
+
field_values = self._get_field_values(fields)
|
|
72
|
+
|
|
73
|
+
view_code = self.view_config.get("view_code")
|
|
74
|
+
|
|
75
|
+
result = separator.join(field_values)
|
|
76
|
+
return (
|
|
77
|
+
f"{view_code}{separator}{result}"
|
|
78
|
+
if view_code_as_prefix and view_code
|
|
79
|
+
else result
|
|
80
|
+
)
|
|
81
|
+
|
|
82
|
+
def _get_field_values(
|
|
83
|
+
self, fields: list[str] | list[Column] | list[Any]
|
|
84
|
+
) -> list[str]:
|
|
85
|
+
field_values: list[str] = []
|
|
86
|
+
for field in fields:
|
|
87
|
+
if not isinstance(field, str | Column):
|
|
88
|
+
field_type = type(field).__name__
|
|
89
|
+
raise TypeError(
|
|
90
|
+
f"Expected field to be a string or Column, got {field_type}"
|
|
91
|
+
)
|
|
92
|
+
field_name = self.get_field_name(
|
|
93
|
+
field.property if isinstance(field, Column) else field
|
|
94
|
+
)
|
|
95
|
+
if field_name is None:
|
|
96
|
+
raise ValueError(f"Field {field} not found in the model")
|
|
97
|
+
field_entry = getattr(self, field_name)
|
|
98
|
+
|
|
99
|
+
field_entry_str = ""
|
|
100
|
+
if isinstance(field_entry, str):
|
|
101
|
+
field_entry_str = field_entry
|
|
102
|
+
elif isinstance(field_entry, date | datetime):
|
|
103
|
+
field_entry_str = field_entry.isoformat()
|
|
104
|
+
elif isinstance(field_entry, InstanceId):
|
|
105
|
+
field_entry_str = field_entry.external_id
|
|
106
|
+
else:
|
|
107
|
+
field_entry_str = str(field_entry)
|
|
108
|
+
field_values.append(field_entry_str.replace(" ", ""))
|
|
109
|
+
return field_values
|
|
110
|
+
|
|
59
111
|
|
|
60
112
|
class WritableViewInstance(ViewInstance):
|
|
61
113
|
@abstractmethod
|
|
@@ -20,7 +20,7 @@ industrial_model/engines/async_engine.py,sha256=-sQv2vn93bBmTZOxY_C1r40YP7IMl1ND
|
|
|
20
20
|
industrial_model/engines/engine.py,sha256=lECOpjN6fGvKt28b441isT_u4UNF3LeLiJH-zwHmkYw,3798
|
|
21
21
|
industrial_model/models/__init__.py,sha256=AzJ0CyPK5PvUCX45FFtybl13tkukUvk2UAF_90s_LQ8,742
|
|
22
22
|
industrial_model/models/base.py,sha256=iGhDjXqA5ULEQIFHtkMi7WYJl0nQq1wi8_zqOr-Ep78,1649
|
|
23
|
-
industrial_model/models/entities.py,sha256=
|
|
23
|
+
industrial_model/models/entities.py,sha256=BC85P8THwvVmcNpYq2spJuFJtlK8Oegkmd0kx3CI_wU,4704
|
|
24
24
|
industrial_model/models/schemas.py,sha256=EoLK9GYdS-0DQ98myTP3wOU9YpWIJOfDSLOYZUy3xEY,4559
|
|
25
25
|
industrial_model/queries/__init__.py,sha256=lA83zOxMRgBgkseWJgK9kCr1vD8D8iSWs9NGGRnoYKk,355
|
|
26
26
|
industrial_model/queries/models.py,sha256=VK69c4L0b0miPrKvOQBB8A01SPxZXYThrquv6gw5OGY,2544
|
|
@@ -28,6 +28,6 @@ industrial_model/queries/params.py,sha256=50qY5BO5onLsXorhcv-7qCKhJaMO94UzhKLCmZ
|
|
|
28
28
|
industrial_model/queries/utils.py,sha256=uP6PLh9IVHDK6J8x444zHWPmyV4PkxdLO-PMc6qWItc,1505
|
|
29
29
|
industrial_model/statements/__init__.py,sha256=rjLRo2KoazHQaOpmPkxbI3_Nm8NCkJxjpuqow6IZVSc,4221
|
|
30
30
|
industrial_model/statements/expressions.py,sha256=4ZZOcZroI5-4xRw4PXIRlufi0ARndE5zSbbxLDpR2Ec,4816
|
|
31
|
-
industrial_model-0.1.
|
|
32
|
-
industrial_model-0.1.
|
|
33
|
-
industrial_model-0.1.
|
|
31
|
+
industrial_model-0.1.29.dist-info/METADATA,sha256=vNGyeERDw-3hlRpxgxKjGERKp8VhwNPBhYRzoqWlArA,6858
|
|
32
|
+
industrial_model-0.1.29.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
|
|
33
|
+
industrial_model-0.1.29.dist-info/RECORD,,
|
|
File without changes
|