GeneralManager 0.9.1__tar.gz → 0.10.1__tar.gz
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.
- {generalmanager-0.9.1 → generalmanager-0.10.1}/GeneralManager.egg-info/PKG-INFO +1 -1
- {generalmanager-0.9.1 → generalmanager-0.10.1}/GeneralManager.egg-info/SOURCES.txt +8 -8
- {generalmanager-0.9.1 → generalmanager-0.10.1}/PKG-INFO +1 -1
- {generalmanager-0.9.1 → generalmanager-0.10.1}/pyproject.toml +1 -1
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/api/mutation.py +4 -4
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/apps.py +31 -8
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/bucket/calculationBucket.py +11 -6
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/cache/cacheDecorator.py +1 -1
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/baseInterface.py +1 -1
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/databaseBasedInterface.py +7 -7
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/databaseInterface.py +4 -1
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/manager/generalManager.py +20 -22
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/manager/meta.py +7 -5
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/measurement/measurement.py +67 -61
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/makeCacheKey.py +4 -4
- generalmanager-0.10.1/src/general_manager/utils/testing.py +232 -0
- generalmanager-0.9.1/src/general_manager/utils/testing.py +0 -124
- {generalmanager-0.9.1 → generalmanager-0.10.1}/GeneralManager.egg-info/dependency_links.txt +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/GeneralManager.egg-info/requires.txt +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/GeneralManager.egg-info/top_level.txt +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/LICENSE +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/README.md +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/setup.cfg +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/api/graphql.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/api/property.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/bucket/baseBucket.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/bucket/databaseBucket.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/bucket/groupBucket.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/cache/cacheTracker.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/cache/dependencyIndex.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/cache/modelDependencyCollector.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/cache/signals.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/factory/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/factory/autoFactory.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/factory/factories.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/factory/factoryMethods.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/calculationInterface.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/models.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/readOnlyInterface.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/manager/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/manager/groupManager.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/manager/input.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/measurement/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/measurement/measurementField.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/permission/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/permission/basePermission.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/permission/fileBasedPermission.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/permission/managerBasedPermission.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/permission/permissionChecks.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/permission/permissionDataManager.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/rule/__init__.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/rule/handler.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/rule/rule.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/__init__.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/argsToKwargs.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/filterParser.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/formatString.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/jsonEncoder.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/noneToZero.py +0 -0
- {generalmanager-0.9.1/src/general_manager/auxiliary → generalmanager-0.10.1/src/general_manager/utils}/pathMapping.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/tests/test_settings.py +0 -0
- {generalmanager-0.9.1 → generalmanager-0.10.1}/tests/test_urls.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GeneralManager
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.10.1
|
4
4
|
Summary: Modular Django-based data management framework with ORM, GraphQL, fine-grained permissions, rule validation, calculations and caching.
|
5
5
|
Author-email: Tim Kleindick <tkleindick@yahoo.de>
|
6
6
|
License-Expression: MIT
|
@@ -11,14 +11,6 @@ src/general_manager/apps.py
|
|
11
11
|
src/general_manager/api/graphql.py
|
12
12
|
src/general_manager/api/mutation.py
|
13
13
|
src/general_manager/api/property.py
|
14
|
-
src/general_manager/auxiliary/__init__.py
|
15
|
-
src/general_manager/auxiliary/argsToKwargs.py
|
16
|
-
src/general_manager/auxiliary/filterParser.py
|
17
|
-
src/general_manager/auxiliary/formatString.py
|
18
|
-
src/general_manager/auxiliary/jsonEncoder.py
|
19
|
-
src/general_manager/auxiliary/makeCacheKey.py
|
20
|
-
src/general_manager/auxiliary/noneToZero.py
|
21
|
-
src/general_manager/auxiliary/pathMapping.py
|
22
14
|
src/general_manager/bucket/baseBucket.py
|
23
15
|
src/general_manager/bucket/calculationBucket.py
|
24
16
|
src/general_manager/bucket/databaseBucket.py
|
@@ -56,6 +48,14 @@ src/general_manager/permission/permissionDataManager.py
|
|
56
48
|
src/general_manager/rule/__init__.py
|
57
49
|
src/general_manager/rule/handler.py
|
58
50
|
src/general_manager/rule/rule.py
|
51
|
+
src/general_manager/utils/__init__.py
|
52
|
+
src/general_manager/utils/argsToKwargs.py
|
53
|
+
src/general_manager/utils/filterParser.py
|
54
|
+
src/general_manager/utils/formatString.py
|
55
|
+
src/general_manager/utils/jsonEncoder.py
|
56
|
+
src/general_manager/utils/makeCacheKey.py
|
57
|
+
src/general_manager/utils/noneToZero.py
|
58
|
+
src/general_manager/utils/pathMapping.py
|
59
59
|
src/general_manager/utils/testing.py
|
60
60
|
tests/test_settings.py
|
61
61
|
tests/test_urls.py
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GeneralManager
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.10.1
|
4
4
|
Summary: Modular Django-based data management framework with ORM, GraphQL, fine-grained permissions, rule validation, calculations and caching.
|
5
5
|
Author-email: Tim Kleindick <tkleindick@yahoo.de>
|
6
6
|
License-Expression: MIT
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
4
4
|
|
5
5
|
[project]
|
6
6
|
name = "GeneralManager"
|
7
|
-
version = "0.
|
7
|
+
version = "0.10.1"
|
8
8
|
description = "Modular Django-based data management framework with ORM, GraphQL, fine-grained permissions, rule validation, calculations and caching."
|
9
9
|
readme = "README.md"
|
10
10
|
authors = [{ name = "Tim Kleindick", email = "tkleindick@yahoo.de" }]
|
@@ -5,19 +5,19 @@ import graphene
|
|
5
5
|
from general_manager.api.graphql import GraphQL
|
6
6
|
from general_manager.manager.generalManager import GeneralManager
|
7
7
|
|
8
|
-
from general_manager.
|
8
|
+
from general_manager.utils.formatString import snake_to_camel
|
9
9
|
|
10
10
|
|
11
11
|
def graphQlMutation(needs_role: Optional[str] = None, auth_required: bool = False):
|
12
12
|
"""
|
13
13
|
Decorator that transforms a function into a GraphQL mutation class and registers it for use in a Graphene-based API.
|
14
|
-
|
14
|
+
|
15
15
|
The decorated function must have type hints for all parameters (except `info`) and a return annotation. The decorator dynamically generates a mutation class with arguments and output fields based on the function's signature and return type. It also enforces authentication if `auth_required` is set to True, returning an error if the user is not authenticated.
|
16
|
-
|
16
|
+
|
17
17
|
Parameters:
|
18
18
|
needs_role (Optional[str]): Reserved for future use to specify a required user role.
|
19
19
|
auth_required (bool): If True, the mutation requires an authenticated user.
|
20
|
-
|
20
|
+
|
21
21
|
Returns:
|
22
22
|
Callable: A decorator that registers the mutation and returns the original function.
|
23
23
|
"""
|
@@ -30,7 +30,7 @@ class GeneralmanagerConfig(AppConfig):
|
|
30
30
|
def ready(self):
|
31
31
|
"""
|
32
32
|
Performs initialization tasks for the general_manager app when Django starts.
|
33
|
-
|
33
|
+
|
34
34
|
Sets up synchronization and schema validation for read-only interfaces, initializes attributes and property accessors for general manager classes, and configures the GraphQL schema and endpoint if enabled in settings.
|
35
35
|
"""
|
36
36
|
self.handleReadOnlyInterface(GeneralManagerMeta.read_only_classes)
|
@@ -47,7 +47,7 @@ class GeneralmanagerConfig(AppConfig):
|
|
47
47
|
):
|
48
48
|
"""
|
49
49
|
Configures synchronization and schema validation for the provided read-only interface classes.
|
50
|
-
|
50
|
+
|
51
51
|
Ensures that each read-only interface is synchronized before Django management commands run, and registers system checks to validate that their schemas are up to date.
|
52
52
|
"""
|
53
53
|
GeneralmanagerConfig.patchReadOnlyInterfaceSync(read_only_classes)
|
@@ -72,7 +72,7 @@ class GeneralmanagerConfig(AppConfig):
|
|
72
72
|
):
|
73
73
|
"""
|
74
74
|
Monkey-patches Django's management command runner to synchronize all provided read-only interfaces before executing any management command, except during autoreload subprocesses of 'runserver'.
|
75
|
-
|
75
|
+
|
76
76
|
For each class in `general_manager_classes`, the associated read-only interface's `syncData` method is called prior to command execution, ensuring data consistency before management operations.
|
77
77
|
"""
|
78
78
|
from general_manager.interface.readOnlyInterface import ReadOnlyInterface
|
@@ -83,10 +83,10 @@ class GeneralmanagerConfig(AppConfig):
|
|
83
83
|
# Ensure syncData is only called at real run of runserver
|
84
84
|
"""
|
85
85
|
Executes a Django management command, synchronizing all registered read-only interfaces before execution unless running in an autoreload subprocess of 'runserver'.
|
86
|
-
|
86
|
+
|
87
87
|
Parameters:
|
88
88
|
argv (list): Command-line arguments for the management command.
|
89
|
-
|
89
|
+
|
90
90
|
Returns:
|
91
91
|
The result of the original management command execution.
|
92
92
|
"""
|
@@ -113,7 +113,7 @@ class GeneralmanagerConfig(AppConfig):
|
|
113
113
|
):
|
114
114
|
"""
|
115
115
|
Initializes attributes and establishes dynamic relationships for GeneralManager classes.
|
116
|
-
|
116
|
+
|
117
117
|
For each class pending attribute initialization, assigns interface attributes and creates property accessors. Then, for all registered GeneralManager classes, connects input fields referencing other GeneralManager subclasses by adding GraphQL properties to enable filtered access to related objects.
|
118
118
|
"""
|
119
119
|
logger.debug("Initializing GeneralManager classes...")
|
@@ -144,6 +144,8 @@ class GeneralmanagerConfig(AppConfig):
|
|
144
144
|
f"{general_manager_class.__name__.lower()}_list",
|
145
145
|
graphQlProperty(func),
|
146
146
|
)
|
147
|
+
for general_manager_class in all_classes:
|
148
|
+
GeneralmanagerConfig.checkPermissionClass(general_manager_class)
|
147
149
|
|
148
150
|
@staticmethod
|
149
151
|
def handleGraphQL(
|
@@ -177,10 +179,10 @@ class GeneralmanagerConfig(AppConfig):
|
|
177
179
|
def addGraphqlUrl(schema):
|
178
180
|
"""
|
179
181
|
Adds a GraphQL endpoint to the Django URL configuration using the provided schema.
|
180
|
-
|
182
|
+
|
181
183
|
Parameters:
|
182
184
|
schema: The GraphQL schema to use for the endpoint.
|
183
|
-
|
185
|
+
|
184
186
|
Raises:
|
185
187
|
Exception: If the ROOT_URLCONF setting is not defined in Django settings.
|
186
188
|
"""
|
@@ -196,3 +198,24 @@ class GeneralmanagerConfig(AppConfig):
|
|
196
198
|
GraphQLView.as_view(graphiql=True, schema=schema),
|
197
199
|
)
|
198
200
|
)
|
201
|
+
|
202
|
+
@staticmethod
|
203
|
+
def checkPermissionClass(general_manager_class: Type[GeneralManager]):
|
204
|
+
"""
|
205
|
+
Checks if the class has a Permission attribute and if it is a subclass of BasePermission.
|
206
|
+
If so, it sets the Permission attribute on the class.
|
207
|
+
"""
|
208
|
+
from general_manager.permission.basePermission import BasePermission
|
209
|
+
from general_manager.permission.managerBasedPermission import (
|
210
|
+
ManagerBasedPermission,
|
211
|
+
)
|
212
|
+
|
213
|
+
if hasattr(general_manager_class, "Permission"):
|
214
|
+
permission = general_manager_class.Permission
|
215
|
+
if not issubclass(permission, BasePermission):
|
216
|
+
raise TypeError(
|
217
|
+
f"{permission.__name__} must be a subclass of BasePermission"
|
218
|
+
)
|
219
|
+
general_manager_class.Permission = permission
|
220
|
+
else:
|
221
|
+
general_manager_class.Permission = ManagerBasedPermission
|
{generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/bucket/calculationBucket.py
RENAMED
@@ -15,10 +15,11 @@ from general_manager.interface.baseInterface import (
|
|
15
15
|
)
|
16
16
|
from general_manager.bucket.baseBucket import Bucket
|
17
17
|
from general_manager.manager.input import Input
|
18
|
-
from general_manager.
|
18
|
+
from general_manager.utils.filterParser import parse_filters
|
19
19
|
|
20
20
|
if TYPE_CHECKING:
|
21
21
|
from general_manager.manager.generalManager import GeneralManager
|
22
|
+
from general_manager.interface.calculationInterface import CalculationInterface
|
22
23
|
|
23
24
|
|
24
25
|
class CalculationBucket(Bucket[GeneralManagerType]):
|
@@ -90,7 +91,11 @@ class CalculationBucket(Bucket[GeneralManagerType]):
|
|
90
91
|
self._current_combinations = state.get("current_combinations")
|
91
92
|
|
92
93
|
def __or__(
|
93
|
-
self,
|
94
|
+
self,
|
95
|
+
other: (
|
96
|
+
Bucket[GeneralManagerType]
|
97
|
+
| GeneralManager[GeneralManagerType, CalculationInterface]
|
98
|
+
),
|
94
99
|
) -> CalculationBucket[GeneralManagerType]:
|
95
100
|
"""
|
96
101
|
Combines this CalculationBucket with another bucket or manager of the same type.
|
@@ -158,7 +163,7 @@ class CalculationBucket(Bucket[GeneralManagerType]):
|
|
158
163
|
def filter(self, **kwargs: Any) -> CalculationBucket:
|
159
164
|
"""
|
160
165
|
Returns a new CalculationBucket with additional filters applied.
|
161
|
-
|
166
|
+
|
162
167
|
Merges the provided filter criteria with existing filters to further restrict valid input combinations.
|
163
168
|
"""
|
164
169
|
filters = self.filters.copy()
|
@@ -316,12 +321,12 @@ class CalculationBucket(Bucket[GeneralManagerType]):
|
|
316
321
|
) -> List[dict[str, Any]]:
|
317
322
|
"""
|
318
323
|
Recursively generates all valid input combinations for the specified input fields, applying filters and exclusions.
|
319
|
-
|
324
|
+
|
320
325
|
Args:
|
321
326
|
sorted_inputs: Input field names ordered to respect dependency constraints.
|
322
327
|
filters: Mapping of input field names to filter definitions.
|
323
328
|
excludes: Mapping of input field names to exclusion definitions.
|
324
|
-
|
329
|
+
|
325
330
|
Returns:
|
326
331
|
A list of dictionaries, each representing a valid combination of input values that satisfy all filters and exclusions.
|
327
332
|
"""
|
@@ -329,7 +334,7 @@ class CalculationBucket(Bucket[GeneralManagerType]):
|
|
329
334
|
def helper(index, current_combo):
|
330
335
|
"""
|
331
336
|
Recursively generates all valid input combinations for calculation inputs.
|
332
|
-
|
337
|
+
|
333
338
|
Yields:
|
334
339
|
Dict[str, Any]: A dictionary representing a valid combination of input values, filtered and excluded according to the provided criteria.
|
335
340
|
"""
|
@@ -4,7 +4,7 @@ from django.core.cache import cache as django_cache
|
|
4
4
|
from general_manager.cache.cacheTracker import DependencyTracker
|
5
5
|
from general_manager.cache.dependencyIndex import record_dependencies, Dependency
|
6
6
|
from general_manager.cache.modelDependencyCollector import ModelDependencyCollector
|
7
|
-
from general_manager.
|
7
|
+
from general_manager.utils.makeCacheKey import make_cache_key
|
8
8
|
|
9
9
|
|
10
10
|
class CacheBackend(Protocol):
|
{generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/baseInterface.py
RENAMED
@@ -13,7 +13,7 @@ from typing import (
|
|
13
13
|
from datetime import datetime
|
14
14
|
from django.conf import settings
|
15
15
|
from django.db.models import Model
|
16
|
-
from general_manager.
|
16
|
+
from general_manager.utils import args_to_kwargs
|
17
17
|
|
18
18
|
if TYPE_CHECKING:
|
19
19
|
from general_manager.manager.input import Input
|
@@ -52,7 +52,7 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
52
52
|
):
|
53
53
|
"""
|
54
54
|
Initialize the interface and load the associated model instance.
|
55
|
-
|
55
|
+
|
56
56
|
If `search_date` is provided, loads the historical record as of that date; otherwise, loads the current record.
|
57
57
|
"""
|
58
58
|
super().__init__(*args, **kwargs)
|
@@ -141,9 +141,9 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
141
141
|
def getAttributeTypes(cls) -> dict[str, AttributeTypedDict]:
|
142
142
|
"""
|
143
143
|
Return a dictionary mapping attribute names to metadata describing their types and properties.
|
144
|
-
|
144
|
+
|
145
145
|
The dictionary includes all model fields, custom fields, foreign keys, many-to-many, and reverse relation fields. For each attribute, the metadata specifies its Python type (translated from Django field types when possible), whether it is required, editable, derived, and its default value. For related models with a general manager class, the type is set to that class.
|
146
|
-
|
146
|
+
|
147
147
|
Returns:
|
148
148
|
dict[str, AttributeTypedDict]: Mapping of attribute names to their type information and metadata.
|
149
149
|
"""
|
@@ -309,7 +309,7 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
309
309
|
model: Type[models.Model] | models.Model,
|
310
310
|
) -> tuple[list[str], list[str]]:
|
311
311
|
"""
|
312
|
-
Identifies custom fields on a model and their associated
|
312
|
+
Identifies custom fields on a model and their associated utils fields to ignore.
|
313
313
|
|
314
314
|
Returns:
|
315
315
|
A tuple containing a list of custom field names and a list of related field names
|
@@ -401,15 +401,15 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
401
401
|
# Felder aus der Interface-Klasse sammeln
|
402
402
|
"""
|
403
403
|
Dynamically generates a Django model class, its associated interface class, and a factory class from an interface definition.
|
404
|
-
|
404
|
+
|
405
405
|
This method collects fields and metadata from the provided interface class, creates a new Django model inheriting from the specified base model class, attaches custom validation rules if present, and constructs corresponding interface and factory classes. The updated attributes dictionary, the new interface class, and the newly created model class are returned for integration into the general manager framework.
|
406
|
-
|
406
|
+
|
407
407
|
Parameters:
|
408
408
|
name: The name for the dynamically created model class.
|
409
409
|
attrs: The attributes dictionary to be updated with the new interface and factory classes.
|
410
410
|
interface: The interface base class defining the model structure and metadata.
|
411
411
|
base_model_class: The base class to use for the new model (defaults to GeneralManagerModel).
|
412
|
-
|
412
|
+
|
413
413
|
Returns:
|
414
414
|
tuple: A tuple containing the updated attributes dictionary, the new interface class, and the newly created model class.
|
415
415
|
"""
|
{generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/interface/databaseInterface.py
RENAMED
@@ -9,6 +9,7 @@ from general_manager.interface.databaseBasedInterface import (
|
|
9
9
|
DBBasedInterface,
|
10
10
|
GeneralManagerModel,
|
11
11
|
)
|
12
|
+
from django.db.models import NOT_PROVIDED
|
12
13
|
|
13
14
|
|
14
15
|
class DatabaseInterface(DBBasedInterface[GeneralManagerModel]):
|
@@ -111,6 +112,8 @@ class DatabaseInterface(DBBasedInterface[GeneralManagerModel]):
|
|
111
112
|
if isinstance(value, GeneralManager):
|
112
113
|
value = value.identification["id"]
|
113
114
|
key = f"{key}_id"
|
115
|
+
if value is NOT_PROVIDED:
|
116
|
+
continue
|
114
117
|
try:
|
115
118
|
setattr(instance, key, value)
|
116
119
|
except ValueError as e:
|
@@ -158,8 +161,8 @@ class DatabaseInterface(DBBasedInterface[GeneralManagerModel]):
|
|
158
161
|
"""
|
159
162
|
instance.changed_by_id = creator_id
|
160
163
|
instance.full_clean()
|
164
|
+
instance.save()
|
161
165
|
if history_comment:
|
162
166
|
update_change_reason(instance, history_comment)
|
163
|
-
instance.save()
|
164
167
|
|
165
168
|
return instance.pk
|
{generalmanager-0.9.1 → generalmanager-0.10.1}/src/general_manager/manager/generalManager.py
RENAMED
@@ -20,12 +20,13 @@ class GeneralManager(
|
|
20
20
|
Generic[GeneralManagerType, InterfaceType], metaclass=GeneralManagerMeta
|
21
21
|
):
|
22
22
|
Interface: Type[InterfaceType]
|
23
|
+
Permission: Type[BasePermission]
|
23
24
|
_attributes: dict[str, Any]
|
24
25
|
|
25
26
|
def __init__(self, *args: Any, **kwargs: Any):
|
26
27
|
"""
|
27
28
|
Initialize the manager by creating an interface instance with the provided arguments and storing its identification.
|
28
|
-
|
29
|
+
|
29
30
|
The identification is registered with the dependency tracker for tracking purposes.
|
30
31
|
"""
|
31
32
|
self._interface = self.Interface(*args, **kwargs)
|
@@ -55,9 +56,9 @@ class GeneralManager(
|
|
55
56
|
) -> Bucket[GeneralManagerType]:
|
56
57
|
"""
|
57
58
|
Combine this manager with another manager of the same class or a Bucket using the union operator.
|
58
|
-
|
59
|
+
|
59
60
|
If combined with a Bucket, returns the union of the Bucket and this manager. If combined with another manager of the same class, returns a Bucket containing both instances. Raises a TypeError for unsupported types.
|
60
|
-
|
61
|
+
|
61
62
|
Returns:
|
62
63
|
Bucket[GeneralManagerType]: A Bucket containing the union of the involved managers.
|
63
64
|
"""
|
@@ -93,20 +94,19 @@ class GeneralManager(
|
|
93
94
|
) -> GeneralManager[GeneralManagerType, InterfaceType]:
|
94
95
|
"""
|
95
96
|
Creates a new managed object using the underlying interface and returns a corresponding manager instance.
|
96
|
-
|
97
|
+
|
97
98
|
Performs a permission check if a `Permission` class is defined and permission checks are not ignored. Passes all provided arguments to the interface's `create` method.
|
98
|
-
|
99
|
+
|
99
100
|
Parameters:
|
100
101
|
creator_id (int | None): Optional identifier for the creator of the object.
|
101
102
|
history_comment (str | None): Optional comment for audit or history tracking.
|
102
103
|
ignore_permission (bool): If True, skips the permission check.
|
103
|
-
|
104
|
+
|
104
105
|
Returns:
|
105
106
|
GeneralManager[GeneralManagerType, InterfaceType]: A new manager instance for the created object.
|
106
107
|
"""
|
107
|
-
|
108
|
-
|
109
|
-
Permission.checkCreatePermission(kwargs, cls, creator_id)
|
108
|
+
if not ignore_permission:
|
109
|
+
cls.Permission.checkCreatePermission(kwargs, cls, creator_id)
|
110
110
|
identification = cls.Interface.create(
|
111
111
|
creator_id=creator_id, history_comment=history_comment, **kwargs
|
112
112
|
)
|
@@ -122,19 +122,18 @@ class GeneralManager(
|
|
122
122
|
) -> GeneralManager[GeneralManagerType, InterfaceType]:
|
123
123
|
"""
|
124
124
|
Update the underlying interface object with new data and return a new manager instance.
|
125
|
-
|
125
|
+
|
126
126
|
Parameters:
|
127
127
|
creator_id (int | None): Optional identifier for the user performing the update.
|
128
128
|
history_comment (str | None): Optional comment describing the update.
|
129
129
|
ignore_permission (bool): If True, skips permission checks.
|
130
130
|
**kwargs: Additional fields to update on the interface object.
|
131
|
-
|
131
|
+
|
132
132
|
Returns:
|
133
133
|
GeneralManager[GeneralManagerType, InterfaceType]: A new manager instance reflecting the updated object.
|
134
134
|
"""
|
135
|
-
|
136
|
-
|
137
|
-
Permission.checkUpdatePermission(kwargs, self, creator_id)
|
135
|
+
if not ignore_permission:
|
136
|
+
self.Permission.checkUpdatePermission(kwargs, self, creator_id)
|
138
137
|
self._interface.update(
|
139
138
|
creator_id=creator_id,
|
140
139
|
history_comment=history_comment,
|
@@ -151,18 +150,17 @@ class GeneralManager(
|
|
151
150
|
) -> GeneralManager[GeneralManagerType, InterfaceType]:
|
152
151
|
"""
|
153
152
|
Deactivates the underlying interface object and returns a new manager instance.
|
154
|
-
|
153
|
+
|
155
154
|
Parameters:
|
156
155
|
creator_id (int | None): Optional identifier for the user performing the deactivation.
|
157
156
|
history_comment (str | None): Optional comment describing the reason for deactivation.
|
158
157
|
ignore_permission (bool): If True, skips permission checks.
|
159
|
-
|
158
|
+
|
160
159
|
Returns:
|
161
160
|
GeneralManager[GeneralManagerType, InterfaceType]: A new instance representing the deactivated object.
|
162
161
|
"""
|
163
|
-
|
164
|
-
|
165
|
-
Permission.checkDeletePermission(self, creator_id)
|
162
|
+
if not ignore_permission:
|
163
|
+
self.Permission.checkDeletePermission(self, creator_id)
|
166
164
|
self._interface.deactivate(
|
167
165
|
creator_id=creator_id, history_comment=history_comment
|
168
166
|
)
|
@@ -190,12 +188,12 @@ class GeneralManager(
|
|
190
188
|
def __parse_identification(kwargs: dict[str, Any]) -> dict[str, Any] | None:
|
191
189
|
"""
|
192
190
|
Return a dictionary with all GeneralManager instances in the input replaced by their identification dictionaries.
|
193
|
-
|
191
|
+
|
194
192
|
For each key-value pair in the input, any GeneralManager instance is replaced by its identification. Lists and tuples are processed recursively, substituting contained GeneralManager instances with their identifications. Returns None if the resulting dictionary is empty.
|
195
|
-
|
193
|
+
|
196
194
|
Parameters:
|
197
195
|
kwargs (dict[str, Any]): Dictionary to process.
|
198
|
-
|
196
|
+
|
199
197
|
Returns:
|
200
198
|
dict[str, Any] | None: Processed dictionary with identifications, or None if empty.
|
201
199
|
"""
|
@@ -26,9 +26,9 @@ class GeneralManagerMeta(type):
|
|
26
26
|
def __new__(mcs, name: str, bases: tuple[type, ...], attrs: dict[str, Any]) -> type:
|
27
27
|
"""
|
28
28
|
Creates a new class using the metaclass, integrating interface hooks and registering the class for attribute initialization and tracking.
|
29
|
-
|
29
|
+
|
30
30
|
If the class definition includes an `Interface` attribute, validates it as a subclass of `InterfaceBase`, applies pre- and post-creation hooks from the interface, and registers the resulting class for attribute initialization and management. Regardless of interface presence, the new class is tracked for pending GraphQL interface creation.
|
31
|
-
|
31
|
+
|
32
32
|
Returns:
|
33
33
|
The newly created class, potentially augmented with interface integration and registration logic.
|
34
34
|
"""
|
@@ -38,7 +38,7 @@ class GeneralManagerMeta(type):
|
|
38
38
|
) -> Type[GeneralManager]:
|
39
39
|
"""
|
40
40
|
Create a new GeneralManager class using the standard metaclass instantiation process.
|
41
|
-
|
41
|
+
|
42
42
|
Returns:
|
43
43
|
The newly created GeneralManager subclass.
|
44
44
|
"""
|
@@ -59,6 +59,7 @@ class GeneralManagerMeta(type):
|
|
59
59
|
|
60
60
|
else:
|
61
61
|
new_class = createNewGeneralManagerClass(mcs, name, bases, attrs)
|
62
|
+
|
62
63
|
if getattr(settings, "AUTOCREATE_GRAPHQL", False):
|
63
64
|
mcs.pending_graphql_interfaces.append(new_class)
|
64
65
|
|
@@ -70,7 +71,7 @@ class GeneralManagerMeta(type):
|
|
70
71
|
):
|
71
72
|
"""
|
72
73
|
Dynamically assigns property descriptors to a class for each specified attribute name.
|
73
|
-
|
74
|
+
|
74
75
|
For each attribute, creates a descriptor that:
|
75
76
|
- Returns the field type from the class's interface when accessed on the class.
|
76
77
|
- Retrieves the value from the instance's `_attributes` dictionary when accessed on an instance.
|
@@ -81,9 +82,10 @@ class GeneralManagerMeta(type):
|
|
81
82
|
def desciptorMethod(attr_name: str, new_class: type):
|
82
83
|
"""
|
83
84
|
Creates a property descriptor for an attribute, enabling dynamic access and callable resolution.
|
84
|
-
|
85
|
+
|
85
86
|
When accessed on the class, returns the field type from the associated interface. When accessed on an instance, retrieves the attribute value from the instance's `_attributes` dictionary, invoking it with the instance's interface if the value is callable. Raises `AttributeError` if the attribute is missing or if a callable attribute raises an exception.
|
86
87
|
"""
|
88
|
+
|
87
89
|
class Descriptor(Generic[GeneralManagerType]):
|
88
90
|
def __init__(self, attr_name: str, new_class: Type[GeneralManager]):
|
89
91
|
self.attr_name = attr_name
|