GeneralManager 0.5.1__py3-none-any.whl → 0.6.0__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/api/graphql.py +2 -1
- general_manager/bucket/baseBucket.py +240 -0
- general_manager/bucket/calculationBucket.py +477 -0
- general_manager/bucket/databaseBucket.py +235 -0
- general_manager/bucket/groupBucket.py +296 -0
- general_manager/cache/modelDependencyCollector.py +5 -8
- general_manager/interface/__init__.py +0 -3
- general_manager/interface/baseInterface.py +28 -105
- general_manager/interface/calculationInterface.py +12 -299
- general_manager/interface/databaseBasedInterface.py +538 -0
- general_manager/interface/databaseInterface.py +16 -655
- general_manager/interface/readOnlyInterface.py +107 -0
- general_manager/manager/generalManager.py +11 -10
- general_manager/manager/groupManager.py +12 -187
- general_manager/manager/meta.py +19 -5
- general_manager/permission/basePermission.py +4 -6
- {generalmanager-0.5.1.dist-info → generalmanager-0.6.0.dist-info}/METADATA +43 -43
- {generalmanager-0.5.1.dist-info → generalmanager-0.6.0.dist-info}/RECORD +21 -15
- {generalmanager-0.5.1.dist-info → generalmanager-0.6.0.dist-info}/WHEEL +0 -0
- {generalmanager-0.5.1.dist-info → generalmanager-0.6.0.dist-info}/licenses/LICENSE +0 -0
- {generalmanager-0.5.1.dist-info → generalmanager-0.6.0.dist-info}/top_level.txt +0 -0
general_manager/api/graphql.py
CHANGED
@@ -9,7 +9,8 @@ import json
|
|
9
9
|
from general_manager.measurement.measurement import Measurement
|
10
10
|
from general_manager.manager.generalManager import GeneralManagerMeta, GeneralManager
|
11
11
|
from general_manager.api.property import GraphQLProperty
|
12
|
-
from general_manager.
|
12
|
+
from general_manager.bucket.baseBucket import Bucket
|
13
|
+
from general_manager.interface.baseInterface import InterfaceBase
|
13
14
|
|
14
15
|
if TYPE_CHECKING:
|
15
16
|
from general_manager.permission.basePermission import BasePermission
|
@@ -0,0 +1,240 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
from abc import ABC, abstractmethod
|
3
|
+
from typing import (
|
4
|
+
Type,
|
5
|
+
Generator,
|
6
|
+
TYPE_CHECKING,
|
7
|
+
Any,
|
8
|
+
Generic,
|
9
|
+
TypeVar,
|
10
|
+
)
|
11
|
+
|
12
|
+
GeneralManagerType = TypeVar("GeneralManagerType", bound="GeneralManager")
|
13
|
+
|
14
|
+
if TYPE_CHECKING:
|
15
|
+
from general_manager.manager.generalManager import GeneralManager
|
16
|
+
from general_manager.manager.groupManager import GroupManager
|
17
|
+
from general_manager.bucket.groupBucket import GroupBucket
|
18
|
+
|
19
|
+
|
20
|
+
class Bucket(ABC, Generic[GeneralManagerType]):
|
21
|
+
|
22
|
+
def __init__(self, manager_class: Type[GeneralManagerType]):
|
23
|
+
"""
|
24
|
+
Initializes the Bucket with a specified manager class.
|
25
|
+
|
26
|
+
Args:
|
27
|
+
manager_class: The class of manager objects this bucket will manage.
|
28
|
+
"""
|
29
|
+
self._manager_class = manager_class
|
30
|
+
self._data = None
|
31
|
+
self.excludes = {}
|
32
|
+
self.filters = {}
|
33
|
+
|
34
|
+
def __eq__(self, other: object) -> bool:
|
35
|
+
"""
|
36
|
+
Checks if this Bucket is equal to another by comparing class, data, and manager class.
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
True if both objects are of the same class and have equal internal data and manager class; otherwise, False.
|
40
|
+
"""
|
41
|
+
if not isinstance(other, self.__class__):
|
42
|
+
return False
|
43
|
+
return self._data == other._data and self._manager_class == other._manager_class
|
44
|
+
|
45
|
+
def __reduce__(self) -> str | tuple[Any, ...]:
|
46
|
+
"""
|
47
|
+
Prepares the object for pickling by returning the class and initialization arguments.
|
48
|
+
|
49
|
+
Returns:
|
50
|
+
A tuple containing the class and a tuple of arguments needed to reconstruct the object during unpickling.
|
51
|
+
"""
|
52
|
+
return (
|
53
|
+
self.__class__,
|
54
|
+
(None, self._manager_class, self.filters, self.excludes),
|
55
|
+
)
|
56
|
+
|
57
|
+
@abstractmethod
|
58
|
+
def __or__(
|
59
|
+
self, other: Bucket[GeneralManagerType] | GeneralManager[GeneralManagerType]
|
60
|
+
) -> Bucket[GeneralManagerType]:
|
61
|
+
"""
|
62
|
+
Returns a new bucket representing the union of this bucket and another bucket or manager instance.
|
63
|
+
|
64
|
+
Args:
|
65
|
+
other: Another bucket or a single manager instance to combine with this bucket.
|
66
|
+
|
67
|
+
Returns:
|
68
|
+
A new bucket containing all unique items from both sources.
|
69
|
+
"""
|
70
|
+
raise NotImplementedError
|
71
|
+
|
72
|
+
@abstractmethod
|
73
|
+
def __iter__(
|
74
|
+
self,
|
75
|
+
) -> Generator[GeneralManagerType | GroupManager[GeneralManagerType]]:
|
76
|
+
"""
|
77
|
+
Returns an iterator over the items in the bucket.
|
78
|
+
|
79
|
+
Yields:
|
80
|
+
Instances of the managed type or group manager contained in the bucket.
|
81
|
+
"""
|
82
|
+
raise NotImplementedError
|
83
|
+
|
84
|
+
@abstractmethod
|
85
|
+
def filter(self, **kwargs: Any) -> Bucket[GeneralManagerType]:
|
86
|
+
"""
|
87
|
+
Returns a new bucket containing only items that match the specified filter criteria.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
**kwargs: Field-value pairs used to filter items in the bucket.
|
91
|
+
|
92
|
+
Returns:
|
93
|
+
A new Bucket instance with items matching the given criteria.
|
94
|
+
"""
|
95
|
+
raise NotImplementedError
|
96
|
+
|
97
|
+
@abstractmethod
|
98
|
+
def exclude(self, **kwargs: Any) -> Bucket[GeneralManagerType]:
|
99
|
+
"""
|
100
|
+
Returns a new Bucket excluding items that match the specified criteria.
|
101
|
+
|
102
|
+
Args:
|
103
|
+
**kwargs: Field-value pairs specifying the exclusion criteria.
|
104
|
+
|
105
|
+
Returns:
|
106
|
+
A new Bucket instance with items matching the criteria excluded.
|
107
|
+
"""
|
108
|
+
raise NotImplementedError
|
109
|
+
|
110
|
+
@abstractmethod
|
111
|
+
def first(self) -> GeneralManagerType | GroupManager[GeneralManagerType] | None:
|
112
|
+
"""
|
113
|
+
Returns the first item in the bucket, or None if the bucket is empty.
|
114
|
+
|
115
|
+
Returns:
|
116
|
+
The first GeneralManager or GroupManager instance, or None if no items exist.
|
117
|
+
"""
|
118
|
+
raise NotImplementedError
|
119
|
+
|
120
|
+
@abstractmethod
|
121
|
+
def last(self) -> GeneralManagerType | GroupManager[GeneralManagerType] | None:
|
122
|
+
"""
|
123
|
+
Returns the last item in the bucket, or None if the bucket is empty.
|
124
|
+
|
125
|
+
Returns:
|
126
|
+
The last GeneralManager or GroupManager instance, or None if no items exist.
|
127
|
+
"""
|
128
|
+
raise NotImplementedError
|
129
|
+
|
130
|
+
@abstractmethod
|
131
|
+
def count(self) -> int:
|
132
|
+
"""
|
133
|
+
Returns the number of items in the bucket.
|
134
|
+
|
135
|
+
Subclasses must implement this method to provide the count of contained elements.
|
136
|
+
"""
|
137
|
+
raise NotImplementedError
|
138
|
+
|
139
|
+
@abstractmethod
|
140
|
+
def all(self) -> Bucket[GeneralManagerType]:
|
141
|
+
"""
|
142
|
+
Returns a bucket containing all items managed by this instance.
|
143
|
+
|
144
|
+
Subclasses must implement this method to provide access to the complete collection without filters or exclusions applied.
|
145
|
+
"""
|
146
|
+
raise NotImplementedError
|
147
|
+
|
148
|
+
@abstractmethod
|
149
|
+
def get(
|
150
|
+
self, **kwargs: Any
|
151
|
+
) -> GeneralManagerType | GroupManager[GeneralManagerType]:
|
152
|
+
"""
|
153
|
+
Retrieves a single item matching the specified criteria.
|
154
|
+
|
155
|
+
Args:
|
156
|
+
**kwargs: Field-value pairs used to identify the item.
|
157
|
+
|
158
|
+
Returns:
|
159
|
+
The matching GeneralManager or GroupManager instance.
|
160
|
+
|
161
|
+
Raises:
|
162
|
+
NotImplementedError: If the method is not implemented by a subclass.
|
163
|
+
"""
|
164
|
+
raise NotImplementedError
|
165
|
+
|
166
|
+
@abstractmethod
|
167
|
+
def __getitem__(
|
168
|
+
self, item: int | slice
|
169
|
+
) -> (
|
170
|
+
GeneralManagerType
|
171
|
+
| GroupManager[GeneralManagerType]
|
172
|
+
| Bucket[GeneralManagerType]
|
173
|
+
):
|
174
|
+
"""
|
175
|
+
Retrieves an item or a slice from the bucket.
|
176
|
+
|
177
|
+
Args:
|
178
|
+
item: An integer index to retrieve a single element, or a slice to retrieve a subset.
|
179
|
+
|
180
|
+
Returns:
|
181
|
+
A single manager instance if an integer is provided, or a new Bucket containing the sliced elements if a slice is provided.
|
182
|
+
|
183
|
+
Raises:
|
184
|
+
NotImplementedError: This method must be implemented by subclasses.
|
185
|
+
"""
|
186
|
+
raise NotImplementedError
|
187
|
+
|
188
|
+
@abstractmethod
|
189
|
+
def __len__(self) -> int:
|
190
|
+
"""
|
191
|
+
Returns the number of items in the bucket.
|
192
|
+
|
193
|
+
Subclasses must implement this method to provide the count of contained elements.
|
194
|
+
"""
|
195
|
+
raise NotImplementedError
|
196
|
+
|
197
|
+
@abstractmethod
|
198
|
+
def __contains__(self, item: GeneralManagerType) -> bool:
|
199
|
+
"""
|
200
|
+
Checks whether the specified item is present in the bucket.
|
201
|
+
|
202
|
+
Args:
|
203
|
+
item: The manager instance to check for membership.
|
204
|
+
|
205
|
+
Returns:
|
206
|
+
True if the item is contained in the bucket, otherwise False.
|
207
|
+
"""
|
208
|
+
raise NotImplementedError
|
209
|
+
|
210
|
+
@abstractmethod
|
211
|
+
def sort(
|
212
|
+
self,
|
213
|
+
key: tuple[str] | str,
|
214
|
+
reverse: bool = False,
|
215
|
+
) -> Bucket[GeneralManagerType]:
|
216
|
+
"""
|
217
|
+
Returns a new Bucket with items sorted by the specified key or keys.
|
218
|
+
|
219
|
+
Args:
|
220
|
+
key: A string or tuple of strings specifying the attribute(s) to sort by.
|
221
|
+
reverse: If True, sorts in descending order. Defaults to False.
|
222
|
+
|
223
|
+
Returns:
|
224
|
+
A new Bucket instance with items sorted according to the given key(s).
|
225
|
+
"""
|
226
|
+
raise NotImplementedError
|
227
|
+
|
228
|
+
def group_by(self, *group_by_keys: str) -> GroupBucket[GeneralManagerType]:
|
229
|
+
"""
|
230
|
+
Groups the bucket's data by one or more specified keys.
|
231
|
+
|
232
|
+
Args:
|
233
|
+
*group_by_keys: One or more attribute names to group the data by.
|
234
|
+
|
235
|
+
Returns:
|
236
|
+
A GroupBucket instance containing the grouped data.
|
237
|
+
"""
|
238
|
+
from general_manager.bucket.groupBucket import GroupBucket
|
239
|
+
|
240
|
+
return GroupBucket(self._manager_class, group_by_keys, self)
|