GeneralManager 0.4.6__py3-none-any.whl → 0.5.1__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.
- general_manager/apps.py +1 -1
- general_manager/interface/baseInterface.py +6 -6
- general_manager/manager/groupManager.py +34 -22
- general_manager/manager/meta.py +18 -5
- {generalmanager-0.4.6.dist-info → generalmanager-0.5.1.dist-info}/METADATA +1 -1
- {generalmanager-0.4.6.dist-info → generalmanager-0.5.1.dist-info}/RECORD +9 -9
- {generalmanager-0.4.6.dist-info → generalmanager-0.5.1.dist-info}/WHEEL +0 -0
- {generalmanager-0.4.6.dist-info → generalmanager-0.5.1.dist-info}/licenses/LICENSE +0 -0
- {generalmanager-0.4.6.dist-info → generalmanager-0.5.1.dist-info}/top_level.txt +0 -0
general_manager/apps.py
CHANGED
@@ -41,7 +41,7 @@ class GeneralmanagerConfig(AppConfig):
|
|
41
41
|
attributes = general_manager_class.Interface.getAttributes()
|
42
42
|
setattr(general_manager_class, "_attributes", attributes)
|
43
43
|
GeneralManagerMeta.createAtPropertiesForAttributes(
|
44
|
-
attributes, general_manager_class
|
44
|
+
attributes.keys(), general_manager_class
|
45
45
|
)
|
46
46
|
|
47
47
|
if getattr(settings, "AUTOCREATE_GRAPHQL", False):
|
@@ -21,7 +21,7 @@ if TYPE_CHECKING:
|
|
21
21
|
from general_manager.manager.input import Input
|
22
22
|
from general_manager.manager.generalManager import GeneralManager
|
23
23
|
from general_manager.manager.meta import GeneralManagerMeta
|
24
|
-
from general_manager.manager.groupManager import
|
24
|
+
from general_manager.manager.groupManager import GroupManager, GroupBucket
|
25
25
|
|
26
26
|
|
27
27
|
GeneralManagerType = TypeVar("GeneralManagerType", bound="GeneralManager")
|
@@ -239,7 +239,7 @@ class Bucket(ABC, Generic[GeneralManagerType]):
|
|
239
239
|
@abstractmethod
|
240
240
|
def __iter__(
|
241
241
|
self,
|
242
|
-
) -> Generator[GeneralManagerType |
|
242
|
+
) -> Generator[GeneralManagerType | GroupManager[GeneralManagerType]]:
|
243
243
|
raise NotImplementedError
|
244
244
|
|
245
245
|
@abstractmethod
|
@@ -251,11 +251,11 @@ class Bucket(ABC, Generic[GeneralManagerType]):
|
|
251
251
|
raise NotImplementedError
|
252
252
|
|
253
253
|
@abstractmethod
|
254
|
-
def first(self) -> GeneralManagerType |
|
254
|
+
def first(self) -> GeneralManagerType | GroupManager[GeneralManagerType] | None:
|
255
255
|
raise NotImplementedError
|
256
256
|
|
257
257
|
@abstractmethod
|
258
|
-
def last(self) -> GeneralManagerType |
|
258
|
+
def last(self) -> GeneralManagerType | GroupManager[GeneralManagerType] | None:
|
259
259
|
raise NotImplementedError
|
260
260
|
|
261
261
|
@abstractmethod
|
@@ -269,7 +269,7 @@ class Bucket(ABC, Generic[GeneralManagerType]):
|
|
269
269
|
@abstractmethod
|
270
270
|
def get(
|
271
271
|
self, **kwargs: Any
|
272
|
-
) -> GeneralManagerType |
|
272
|
+
) -> GeneralManagerType | GroupManager[GeneralManagerType]:
|
273
273
|
raise NotImplementedError
|
274
274
|
|
275
275
|
@abstractmethod
|
@@ -277,7 +277,7 @@ class Bucket(ABC, Generic[GeneralManagerType]):
|
|
277
277
|
self, item: int | slice
|
278
278
|
) -> (
|
279
279
|
GeneralManagerType
|
280
|
-
|
|
280
|
+
| GroupManager[GeneralManagerType]
|
281
281
|
| Bucket[GeneralManagerType]
|
282
282
|
):
|
283
283
|
raise NotImplementedError
|
@@ -32,6 +32,15 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
32
32
|
self._data = self.__buildGroupedManager(data)
|
33
33
|
self._basis_data = data
|
34
34
|
|
35
|
+
def __eq__(self, other: object) -> bool:
|
36
|
+
if not isinstance(other, self.__class__):
|
37
|
+
return False
|
38
|
+
return (
|
39
|
+
self._data == other._data
|
40
|
+
and self._manager_class == other._manager_class
|
41
|
+
and self._group_by_keys == other._group_by_keys
|
42
|
+
)
|
43
|
+
|
35
44
|
def __checkGroupByArguments(self, group_by_keys: tuple[str, ...]) -> None:
|
36
45
|
"""
|
37
46
|
This method checks if the given arguments are valid for the groupBy method.
|
@@ -50,7 +59,7 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
50
59
|
def __buildGroupedManager(
|
51
60
|
self,
|
52
61
|
data: Bucket[GeneralManagerType],
|
53
|
-
) -> list[
|
62
|
+
) -> list[GroupManager[GeneralManagerType]]:
|
54
63
|
"""
|
55
64
|
This method builds the grouped manager.
|
56
65
|
It returns a GroupBucket with the grouped data.
|
@@ -63,11 +72,11 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
63
72
|
group_by_values.add(json.dumps(group_by_value))
|
64
73
|
|
65
74
|
groups = []
|
66
|
-
for group_by_value in group_by_values:
|
75
|
+
for group_by_value in sorted(group_by_values):
|
67
76
|
group_by_value = json.loads(group_by_value)
|
68
77
|
grouped_manager_objects = data.filter(**group_by_value)
|
69
78
|
groups.append(
|
70
|
-
|
79
|
+
GroupManager(
|
71
80
|
self._manager_class, group_by_value, grouped_manager_objects
|
72
81
|
)
|
73
82
|
)
|
@@ -84,7 +93,7 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
84
93
|
self._basis_data | other._basis_data,
|
85
94
|
)
|
86
95
|
|
87
|
-
def __iter__(self) -> Generator[
|
96
|
+
def __iter__(self) -> Generator[GroupManager[GeneralManagerType]]:
|
88
97
|
for grouped_manager in self._data:
|
89
98
|
yield grouped_manager
|
90
99
|
|
@@ -104,13 +113,13 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
104
113
|
new_basis_data,
|
105
114
|
)
|
106
115
|
|
107
|
-
def first(self) ->
|
116
|
+
def first(self) -> GroupManager[GeneralManagerType] | None:
|
108
117
|
try:
|
109
118
|
return next(iter(self))
|
110
119
|
except StopIteration:
|
111
120
|
return None
|
112
121
|
|
113
|
-
def last(self) ->
|
122
|
+
def last(self) -> GroupManager[GeneralManagerType] | None:
|
114
123
|
items = list(self)
|
115
124
|
if items:
|
116
125
|
return items[-1]
|
@@ -122,7 +131,7 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
122
131
|
def all(self) -> Bucket[GeneralManagerType]:
|
123
132
|
return self
|
124
133
|
|
125
|
-
def get(self, **kwargs: Any) ->
|
134
|
+
def get(self, **kwargs: Any) -> GroupManager[GeneralManagerType]:
|
126
135
|
first_value = self.filter(**kwargs).first()
|
127
136
|
if first_value is None:
|
128
137
|
raise ValueError(
|
@@ -132,7 +141,7 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
132
141
|
|
133
142
|
def __getitem__(
|
134
143
|
self, item: int | slice
|
135
|
-
) ->
|
144
|
+
) -> GroupManager[GeneralManagerType] | GroupBucket[GeneralManagerType]:
|
136
145
|
if isinstance(item, int):
|
137
146
|
return self._data[item]
|
138
147
|
elif isinstance(item, slice):
|
@@ -162,12 +171,14 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
162
171
|
if isinstance(key, str):
|
163
172
|
key = (key,)
|
164
173
|
if reverse:
|
165
|
-
sorted_data =
|
166
|
-
|
174
|
+
sorted_data = sorted(
|
175
|
+
self._data,
|
176
|
+
key=lambda x: tuple(getattr(x, k) for k in key),
|
177
|
+
reverse=True,
|
167
178
|
)
|
168
179
|
else:
|
169
|
-
sorted_data =
|
170
|
-
key=lambda x: tuple(
|
180
|
+
sorted_data = sorted(
|
181
|
+
self._data, key=lambda x: tuple(getattr(x, k) for k in key)
|
171
182
|
)
|
172
183
|
|
173
184
|
new_bucket = GroupBucket(
|
@@ -182,11 +193,13 @@ class GroupBucket(Bucket[GeneralManagerType]):
|
|
182
193
|
It returns a GroupBucket with the grouped data.
|
183
194
|
"""
|
184
195
|
return GroupBucket(
|
185
|
-
self._manager_class,
|
196
|
+
self._manager_class,
|
197
|
+
tuple([*self._group_by_keys, *group_by_keys]),
|
198
|
+
self._basis_data,
|
186
199
|
)
|
187
200
|
|
188
201
|
|
189
|
-
class
|
202
|
+
class GroupManager(Generic[GeneralManagerType]):
|
190
203
|
"""
|
191
204
|
This class is used to group the data of a GeneralManager.
|
192
205
|
It is used to create a new GeneralManager with the grouped data.
|
@@ -212,11 +225,6 @@ class GroupedManager(Generic[GeneralManagerType]):
|
|
212
225
|
and self._group_by_value == other._group_by_value
|
213
226
|
)
|
214
227
|
|
215
|
-
def __hash__(self) -> int:
|
216
|
-
return hash(
|
217
|
-
(self._manager_class, frozenset(self._group_by_value.items()), self._data)
|
218
|
-
)
|
219
|
-
|
220
228
|
def __repr__(self) -> str:
|
221
229
|
return f"{self.__class__.__name__}({self._manager_class}, {self._group_by_value}, {self._data})"
|
222
230
|
|
@@ -277,12 +285,16 @@ class GroupedManager(Generic[GeneralManagerType]):
|
|
277
285
|
for entry in total_data:
|
278
286
|
new_data.update(entry)
|
279
287
|
elif issubclass(data_type, str):
|
280
|
-
|
288
|
+
temp_data = []
|
289
|
+
for entry in total_data:
|
290
|
+
if entry not in temp_data:
|
291
|
+
temp_data.append(str(entry))
|
292
|
+
new_data = ", ".join(temp_data)
|
293
|
+
elif issubclass(data_type, bool):
|
294
|
+
new_data = any(total_data)
|
281
295
|
elif issubclass(data_type, (int, float, Measurement)):
|
282
296
|
new_data = sum(total_data)
|
283
297
|
elif issubclass(data_type, (datetime, date, time)):
|
284
298
|
new_data = max(total_data)
|
285
|
-
elif issubclass(data_type, bool):
|
286
|
-
new_data = any(total_data)
|
287
299
|
|
288
300
|
return new_data
|
general_manager/manager/meta.py
CHANGED
@@ -3,7 +3,7 @@ from general_manager.interface.baseInterface import (
|
|
3
3
|
InterfaceBase,
|
4
4
|
)
|
5
5
|
from django.conf import settings
|
6
|
-
from typing import Any, Type, TYPE_CHECKING, Generic, TypeVar
|
6
|
+
from typing import Any, Type, TYPE_CHECKING, Generic, TypeVar, Iterable
|
7
7
|
|
8
8
|
if TYPE_CHECKING:
|
9
9
|
from general_manager.interface.databaseInterface import ReadOnlyInterface
|
@@ -12,6 +12,10 @@ if TYPE_CHECKING:
|
|
12
12
|
GeneralManagerType = TypeVar("GeneralManagerType", bound="GeneralManager")
|
13
13
|
|
14
14
|
|
15
|
+
class _nonExistent:
|
16
|
+
pass
|
17
|
+
|
18
|
+
|
15
19
|
class GeneralManagerMeta(type):
|
16
20
|
all_classes: list[Type[GeneralManager]] = []
|
17
21
|
read_only_classes: list[Type[ReadOnlyInterface]] = []
|
@@ -48,7 +52,7 @@ class GeneralManagerMeta(type):
|
|
48
52
|
|
49
53
|
@staticmethod
|
50
54
|
def createAtPropertiesForAttributes(
|
51
|
-
attributes:
|
55
|
+
attributes: Iterable[str], new_class: Type[GeneralManager]
|
52
56
|
):
|
53
57
|
|
54
58
|
def desciptorMethod(attr_name: str, new_class: type):
|
@@ -64,12 +68,21 @@ class GeneralManagerMeta(type):
|
|
64
68
|
):
|
65
69
|
if instance is None:
|
66
70
|
return self.new_class.Interface.getFieldType(self.attr_name)
|
67
|
-
attribute = instance._attributes
|
71
|
+
attribute = instance._attributes.get(attr_name, _nonExistent)
|
72
|
+
if attribute is _nonExistent:
|
73
|
+
raise AttributeError(
|
74
|
+
f"{self.attr_name} not found in {instance.__class__.__name__}"
|
75
|
+
)
|
68
76
|
if callable(attribute):
|
69
|
-
|
77
|
+
try:
|
78
|
+
attribute = attribute(instance._interface)
|
79
|
+
except Exception as e:
|
80
|
+
raise AttributeError(
|
81
|
+
f"Error calling attribute {self.attr_name}: {e}"
|
82
|
+
) from e
|
70
83
|
return attribute
|
71
84
|
|
72
85
|
return Descriptor(attr_name, new_class)
|
73
86
|
|
74
|
-
for attr_name in attributes
|
87
|
+
for attr_name in attributes:
|
75
88
|
setattr(new_class, attr_name, desciptorMethod(attr_name, new_class))
|
@@ -1,5 +1,5 @@
|
|
1
1
|
general_manager/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
2
|
-
general_manager/apps.py,sha256
|
2
|
+
general_manager/apps.py,sha256=0QwuIAnhHm5u0wTlCiDVsl8k0RU0BEgfFjmBMl9zvsw,3320
|
3
3
|
general_manager/api/graphql.py,sha256=L-UUiDDOe1s5mhXs9nBNf0f7PXz9JLloUfyrXbjIfIs,27408
|
4
4
|
general_manager/api/mutation.py,sha256=uu5RVxc9wbb-Zrbtt4azegvyKymMqEsxk_CkerKCd9Q,5178
|
5
5
|
general_manager/api/property.py,sha256=oc93p1P8dcIvrNorRuqD1EJVsd6eYttYhZuAS0s28gs,696
|
@@ -20,14 +20,14 @@ general_manager/factory/autoFactory.py,sha256=WBhSuMVsxkPAPLhlZhYXwHVIqiomUveS7v
|
|
20
20
|
general_manager/factory/factories.py,sha256=F6_nYFyJRYYc3LQApfoVFdctfLzsWUDHKafn6xjckB8,7224
|
21
21
|
general_manager/factory/factoryMethods.py,sha256=9Bag891j0XHe3dUBAFi7gUKcKeUwcBZN3cDLBobyBiI,3225
|
22
22
|
general_manager/interface/__init__.py,sha256=6x5adQLefTugvrJeyPcAxstyqgLAYeaJ1EPdAbac9pE,213
|
23
|
-
general_manager/interface/baseInterface.py,sha256=
|
23
|
+
general_manager/interface/baseInterface.py,sha256=di6yUxosJCDVyMypJAHdlf0-nhXfhVTW1EKWYCoglNQ,10261
|
24
24
|
general_manager/interface/calculationInterface.py,sha256=GzSNXjU6Z7bFz60gHyMKkI5xNUDIPuniV8wbyVtQT50,14250
|
25
25
|
general_manager/interface/databaseInterface.py,sha256=1hQcgOQkEhniv7Mrx2CbqPaes_qqH9zTqSnlriZQfGo,28314
|
26
26
|
general_manager/manager/__init__.py,sha256=l3RYp62aEhj3Y975_XUTIzo35LUnkTJHkb_hgChnXXI,111
|
27
27
|
general_manager/manager/generalManager.py,sha256=L470Jevvh87doI5leUbTa9P6weIdekRZ6OTorqN-WpY,6091
|
28
|
-
general_manager/manager/groupManager.py,sha256=
|
28
|
+
general_manager/manager/groupManager.py,sha256=Ge5WtUXE-x2Z9PtjJ2wa31WED_H7UvnX3x1hUCGp7d8,10476
|
29
29
|
general_manager/manager/input.py,sha256=iKawV3P1QICz-0AQUF00OvH7LZYxussg3svpvCUl8hE,2977
|
30
|
-
general_manager/manager/meta.py,sha256=
|
30
|
+
general_manager/manager/meta.py,sha256=Km4axFpDKI_Wx000dOok5jUwjJVqq5QJG9XhrWRw5mo,3624
|
31
31
|
general_manager/measurement/__init__.py,sha256=X97meFujBldE5v0WMF7SmKeGpC5R0JTczfLo_Lq1Xek,84
|
32
32
|
general_manager/measurement/measurement.py,sha256=e_FjHieeJbBtjXGCO9J7vRPw6KCkMrOxwWjaD0m8ee4,11777
|
33
33
|
general_manager/measurement/measurementField.py,sha256=iq9Hqe6ZGX8CxXm4nIqTAWTRkQVptzpqE9ExX-jFyNs,5928
|
@@ -40,8 +40,8 @@ general_manager/permission/permissionDataManager.py,sha256=Ji7fsnuaKTa6M8yzCGyzr
|
|
40
40
|
general_manager/rule/__init__.py,sha256=4Har5cfPD1fmOsilTDod-ZUz3Com-tkl58jz7yY4fD0,23
|
41
41
|
general_manager/rule/handler.py,sha256=z8SFHTIZ0LbLh3fV56Mud0V4_OvWkqJjlHvFqau7Qfk,7334
|
42
42
|
general_manager/rule/rule.py,sha256=3FVCKGL7BTVoStdgOTdWQwuoVRIxAIAilV4VOzouDpc,10759
|
43
|
-
generalmanager-0.
|
44
|
-
generalmanager-0.
|
45
|
-
generalmanager-0.
|
46
|
-
generalmanager-0.
|
47
|
-
generalmanager-0.
|
43
|
+
generalmanager-0.5.1.dist-info/licenses/LICENSE,sha256=YGFm0ieb4KpkMRRt2qnWue6uFh0cUMtobwEBkHwajhc,1450
|
44
|
+
generalmanager-0.5.1.dist-info/METADATA,sha256=v2MleXEYMzDIUCyvT5bjv3vJgdran7wyPFKk-C4F7mM,6528
|
45
|
+
generalmanager-0.5.1.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
46
|
+
generalmanager-0.5.1.dist-info/top_level.txt,sha256=sTDtExP9ga-YP3h3h42yivUY-A2Q23C2nw6LNKOho4I,16
|
47
|
+
generalmanager-0.5.1.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|