GeneralManager 0.12.0__tar.gz → 0.12.2__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.12.0 → generalmanager-0.12.2}/GeneralManager.egg-info/PKG-INFO +1 -1
- {generalmanager-0.12.0 → generalmanager-0.12.2}/PKG-INFO +1 -1
- {generalmanager-0.12.0 → generalmanager-0.12.2}/pyproject.toml +1 -1
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/api/graphql.py +124 -103
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/databaseBasedInterface.py +46 -9
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/databaseInterface.py +12 -8
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/models.py +1 -1
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/measurement/measurement.py +14 -12
- generalmanager-0.12.2/src/general_manager/measurement/measurementField.py +271 -0
- generalmanager-0.12.0/src/general_manager/measurement/measurementField.py +0 -168
- {generalmanager-0.12.0 → generalmanager-0.12.2}/GeneralManager.egg-info/SOURCES.txt +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/GeneralManager.egg-info/dependency_links.txt +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/GeneralManager.egg-info/requires.txt +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/GeneralManager.egg-info/top_level.txt +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/LICENSE +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/README.md +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/setup.cfg +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/api/mutation.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/api/property.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/apps.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/bucket/baseBucket.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/bucket/calculationBucket.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/bucket/databaseBucket.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/bucket/groupBucket.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/cache/cacheDecorator.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/cache/cacheTracker.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/cache/dependencyIndex.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/cache/modelDependencyCollector.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/cache/signals.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/factory/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/factory/autoFactory.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/factory/factories.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/factory/factoryMethods.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/baseInterface.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/calculationInterface.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/readOnlyInterface.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/manager/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/manager/generalManager.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/manager/groupManager.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/manager/input.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/manager/meta.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/measurement/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/basePermission.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/fileBasedPermission.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/managerBasedPermission.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/mutationPermission.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/permissionChecks.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/permissionDataManager.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/permission/utils.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/rule/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/rule/handler.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/rule/rule.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/__init__.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/argsToKwargs.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/filterParser.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/formatString.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/jsonEncoder.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/makeCacheKey.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/noneToZero.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/pathMapping.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/utils/testing.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/tests/test_settings.py +0 -0
- {generalmanager-0.12.0 → generalmanager-0.12.2}/tests/test_urls.py +0 -0
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GeneralManager
|
3
|
-
Version: 0.12.
|
3
|
+
Version: 0.12.2
|
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
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GeneralManager
|
3
|
-
Version: 0.12.
|
3
|
+
Version: 0.12.2
|
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.12.
|
7
|
+
version = "0.12.2"
|
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" }]
|
@@ -4,6 +4,7 @@ from typing import Any, Callable, get_args, TYPE_CHECKING, cast, Type
|
|
4
4
|
from decimal import Decimal
|
5
5
|
from datetime import date, datetime
|
6
6
|
import json
|
7
|
+
from graphql.language import ast
|
7
8
|
|
8
9
|
from general_manager.measurement.measurement import Measurement
|
9
10
|
from general_manager.manager.generalManager import GeneralManagerMeta, GeneralManager
|
@@ -26,6 +27,28 @@ class MeasurementType(graphene.ObjectType):
|
|
26
27
|
unit = graphene.String()
|
27
28
|
|
28
29
|
|
30
|
+
class MeasurementScalar(graphene.Scalar):
|
31
|
+
"""
|
32
|
+
A measurement in format "value unit", e.g. "12.5 m/s".
|
33
|
+
"""
|
34
|
+
|
35
|
+
@staticmethod
|
36
|
+
def serialize(value: Measurement) -> str:
|
37
|
+
if not isinstance(value, Measurement):
|
38
|
+
raise TypeError(f"Expected Measurement, got {type(value)}")
|
39
|
+
return str(value)
|
40
|
+
|
41
|
+
@staticmethod
|
42
|
+
def parse_value(value: str) -> Measurement:
|
43
|
+
return Measurement.from_string(value)
|
44
|
+
|
45
|
+
@staticmethod
|
46
|
+
def parse_literal(node: Any) -> Measurement | None:
|
47
|
+
if isinstance(node, ast.StringValueNode):
|
48
|
+
return Measurement.from_string(node.value)
|
49
|
+
return None
|
50
|
+
|
51
|
+
|
29
52
|
class PageInfo(graphene.ObjectType):
|
30
53
|
total_count = graphene.Int(required=True)
|
31
54
|
page_size = graphene.Int(required=False)
|
@@ -38,9 +61,9 @@ def getReadPermissionFilter(
|
|
38
61
|
info: GraphQLResolveInfo,
|
39
62
|
) -> list[tuple[dict[str, Any], dict[str, Any]]]:
|
40
63
|
"""
|
41
|
-
Returns
|
42
|
-
|
43
|
-
|
64
|
+
Returns permission-based filter and exclude constraints for querying instances of a manager class.
|
65
|
+
|
66
|
+
For the given manager class and user context, retrieves a list of (filter, exclude) dictionary pairs that represent the read access restrictions to be applied to queries. Returns an empty list if no permission class is defined.
|
44
67
|
"""
|
45
68
|
filters = []
|
46
69
|
PermissionClass: type[BasePermission] | None = getattr(
|
@@ -74,9 +97,9 @@ class GraphQL:
|
|
74
97
|
@classmethod
|
75
98
|
def createGraphqlMutation(cls, generalManagerClass: type[GeneralManager]) -> None:
|
76
99
|
"""
|
77
|
-
|
78
|
-
|
79
|
-
For each supported mutation,
|
100
|
+
Generates and registers GraphQL mutation classes for create, update, and delete operations on the specified manager class if its interface provides custom implementations.
|
101
|
+
|
102
|
+
For each supported mutation, a corresponding GraphQL mutation class is created and added to the mutation registry, enabling dynamic mutation support in the schema.
|
80
103
|
"""
|
81
104
|
|
82
105
|
interface_cls: InterfaceBase | None = getattr(
|
@@ -112,9 +135,9 @@ class GraphQL:
|
|
112
135
|
@classmethod
|
113
136
|
def createGraphqlInterface(cls, generalManagerClass: GeneralManagerMeta) -> None:
|
114
137
|
"""
|
115
|
-
Creates and registers a GraphQL ObjectType for
|
116
|
-
|
117
|
-
|
138
|
+
Creates and registers a GraphQL ObjectType for a GeneralManager subclass.
|
139
|
+
|
140
|
+
Introspects the manager's interface and GraphQLProperty fields, maps them to Graphene fields with appropriate resolvers, registers the resulting type in the internal registry, and adds corresponding query fields to the schema.
|
118
141
|
"""
|
119
142
|
interface_cls: InterfaceBase | None = getattr(
|
120
143
|
generalManagerClass, "Interface", None
|
@@ -155,10 +178,10 @@ class GraphQL:
|
|
155
178
|
generalManagerClass: GeneralManagerMeta,
|
156
179
|
) -> type[graphene.Enum] | None:
|
157
180
|
"""
|
158
|
-
|
159
|
-
|
181
|
+
Creates a Graphene Enum type representing sortable fields for a given GeneralManager class.
|
182
|
+
|
160
183
|
Returns:
|
161
|
-
A Graphene Enum type with options for each sortable attribute, including separate
|
184
|
+
A Graphene Enum type with options for each sortable attribute, including separate entries for the value and unit of Measurement fields. Returns None if there are no sortable fields.
|
162
185
|
"""
|
163
186
|
sort_options = []
|
164
187
|
for (
|
@@ -168,9 +191,6 @@ class GraphQL:
|
|
168
191
|
field_type = field_info["type"]
|
169
192
|
if issubclass(field_type, GeneralManager):
|
170
193
|
continue
|
171
|
-
elif issubclass(field_type, Measurement):
|
172
|
-
sort_options.append(f"{field_name}_value")
|
173
|
-
sort_options.append(f"{field_name}_unit")
|
174
194
|
else:
|
175
195
|
sort_options.append(field_name)
|
176
196
|
|
@@ -189,8 +209,15 @@ class GraphQL:
|
|
189
209
|
) -> type[graphene.InputObjectType] | None:
|
190
210
|
"""
|
191
211
|
Dynamically generates a Graphene InputObjectType for filtering fields of a GeneralManager subclass.
|
192
|
-
|
212
|
+
|
193
213
|
Creates filter fields for each attribute based on its type, supporting numeric and string filter operations, and specialized handling for Measurement attributes. Returns the generated InputObjectType, or None if no applicable filter fields exist.
|
214
|
+
|
215
|
+
Parameters:
|
216
|
+
field_name (str): The name of the field to generate filter options for.
|
217
|
+
field_type (GeneralManagerMeta): The manager class whose attributes are used to build filter fields.
|
218
|
+
|
219
|
+
Returns:
|
220
|
+
type[graphene.InputObjectType] | None: The generated filter input type, or None if no filter fields are applicable.
|
194
221
|
"""
|
195
222
|
number_options = ["exact", "gt", "gte", "lt", "lte"]
|
196
223
|
string_options = [
|
@@ -212,11 +239,9 @@ class GraphQL:
|
|
212
239
|
if issubclass(attr_type, GeneralManager):
|
213
240
|
continue
|
214
241
|
elif issubclass(attr_type, Measurement):
|
215
|
-
filter_fields[f"{attr_name}
|
216
|
-
filter_fields[f"{attr_name}_unit"] = graphene.String()
|
242
|
+
filter_fields[f"{attr_name}"] = MeasurementScalar()
|
217
243
|
for option in number_options:
|
218
|
-
filter_fields[f"{attr_name}
|
219
|
-
filter_fields[f"{attr_name}_unit__{option}"] = graphene.String()
|
244
|
+
filter_fields[f"{attr_name}__{option}"] = MeasurementScalar()
|
220
245
|
else:
|
221
246
|
filter_fields[attr_name] = GraphQL._mapFieldToGrapheneRead(
|
222
247
|
attr_type, attr_name
|
@@ -246,8 +271,8 @@ class GraphQL:
|
|
246
271
|
def _mapFieldToGrapheneRead(field_type: type, field_name: str) -> Any:
|
247
272
|
"""
|
248
273
|
Maps a Python field type and name to the appropriate Graphene field for GraphQL schema generation.
|
249
|
-
|
250
|
-
For `Measurement` fields, returns a field with an optional `target_unit` argument. For `GeneralManager` subclasses, returns a paginated field with filtering, exclusion, sorting, pagination, and grouping arguments if the field name ends with `_list`; otherwise, returns a single object field. For all other types, returns the corresponding Graphene scalar field.
|
274
|
+
|
275
|
+
For `Measurement` fields, returns a Graphene field with an optional `target_unit` argument. For `GeneralManager` subclasses, returns a paginated field with filtering, exclusion, sorting, pagination, and grouping arguments if the field name ends with `_list`; otherwise, returns a single object field. For all other types, returns the corresponding Graphene scalar field.
|
251
276
|
"""
|
252
277
|
if issubclass(field_type, Measurement):
|
253
278
|
return graphene.Field(MeasurementType, target_unit=graphene.String())
|
@@ -299,6 +324,8 @@ class GraphQL:
|
|
299
324
|
return graphene.Float
|
300
325
|
elif issubclass(field_type, (date, datetime)):
|
301
326
|
return graphene.Date
|
327
|
+
elif issubclass(field_type, Measurement):
|
328
|
+
return MeasurementScalar
|
302
329
|
else:
|
303
330
|
return graphene.String
|
304
331
|
|
@@ -325,17 +352,16 @@ class GraphQL:
|
|
325
352
|
reverse: bool,
|
326
353
|
) -> Bucket[GeneralManager]:
|
327
354
|
"""
|
328
|
-
|
329
|
-
|
355
|
+
Apply filtering, exclusion, and sorting to a queryset based on provided parameters.
|
356
|
+
|
330
357
|
Parameters:
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
358
|
+
filter_input: Filters to apply, as a dictionary or JSON string.
|
359
|
+
exclude_input: Exclusions to apply, as a dictionary or JSON string.
|
360
|
+
sort_by: Field to sort by, as a Graphene Enum value.
|
361
|
+
reverse: If True, reverses the sort order.
|
362
|
+
|
337
363
|
Returns:
|
338
|
-
|
364
|
+
The queryset after applying filters, exclusions, and sorting.
|
339
365
|
"""
|
340
366
|
filters = GraphQL._parseInput(filter_input)
|
341
367
|
if filters:
|
@@ -389,9 +415,9 @@ class GraphQL:
|
|
389
415
|
base_getter: Callable[[Any], Any], fallback_manager_class: type[GeneralManager]
|
390
416
|
) -> Callable[..., Any]:
|
391
417
|
"""
|
392
|
-
Creates a resolver for GraphQL list fields that returns paginated, filtered, sorted, and optionally grouped results with permission checks
|
393
|
-
|
394
|
-
The
|
418
|
+
Creates a resolver for GraphQL list fields that returns paginated, filtered, sorted, and optionally grouped results with permission checks.
|
419
|
+
|
420
|
+
The generated resolver applies permission-based filtering, user-specified filters and exclusions, sorting, grouping, and pagination to the list field. It returns a dictionary containing the resulting items and pagination metadata.
|
395
421
|
"""
|
396
422
|
|
397
423
|
def resolver(
|
@@ -406,19 +432,19 @@ class GraphQL:
|
|
406
432
|
group_by: list[str] | None = None,
|
407
433
|
) -> dict[str, Any]:
|
408
434
|
"""
|
409
|
-
Resolves a list field by returning
|
410
|
-
|
435
|
+
Resolves a list field by returning filtered, excluded, sorted, grouped, and paginated results with permission checks.
|
436
|
+
|
411
437
|
Parameters:
|
412
|
-
filter
|
413
|
-
exclude
|
414
|
-
sort_by
|
415
|
-
reverse
|
416
|
-
page
|
417
|
-
page_size
|
418
|
-
group_by
|
419
|
-
|
438
|
+
filter: Filter criteria as a dictionary or JSON string.
|
439
|
+
exclude: Exclusion criteria as a dictionary or JSON string.
|
440
|
+
sort_by: Field to sort by, as a Graphene Enum.
|
441
|
+
reverse: If True, reverses the sort order.
|
442
|
+
page: Page number for pagination.
|
443
|
+
page_size: Number of items per page.
|
444
|
+
group_by: List of field names to group results by.
|
445
|
+
|
420
446
|
Returns:
|
421
|
-
|
447
|
+
A dictionary containing the paginated items under "items" and pagination metadata under "pageInfo".
|
422
448
|
"""
|
423
449
|
base_queryset = base_getter(self)
|
424
450
|
# use _manager_class from the attribute if available, otherwise fallback
|
@@ -453,9 +479,16 @@ class GraphQL:
|
|
453
479
|
queryset: Bucket[GeneralManager], page: int | None, page_size: int | None
|
454
480
|
) -> Bucket[GeneralManager]:
|
455
481
|
"""
|
456
|
-
|
457
|
-
|
458
|
-
If
|
482
|
+
Returns a paginated subset of the queryset based on the given page number and page size.
|
483
|
+
|
484
|
+
If neither `page` nor `page_size` is provided, the entire queryset is returned. Defaults to page 1 and page size 10 if only one parameter is specified.
|
485
|
+
|
486
|
+
Parameters:
|
487
|
+
page (int | None): The page number to retrieve (1-based).
|
488
|
+
page_size (int | None): The number of items per page.
|
489
|
+
|
490
|
+
Returns:
|
491
|
+
Bucket[GeneralManager]: The paginated queryset.
|
459
492
|
"""
|
460
493
|
if page is not None or page_size is not None:
|
461
494
|
page = page or 1
|
@@ -469,8 +502,8 @@ class GraphQL:
|
|
469
502
|
queryset: Bucket[GeneralManager], group_by: list[str] | None
|
470
503
|
) -> Bucket[GeneralManager]:
|
471
504
|
"""
|
472
|
-
|
473
|
-
|
505
|
+
Groups the queryset by the specified fields.
|
506
|
+
|
474
507
|
If `group_by` is `[""]`, groups by all default fields. If `group_by` is a list of field names, groups by those fields. Returns the grouped queryset.
|
475
508
|
"""
|
476
509
|
if group_by is not None:
|
@@ -483,13 +516,9 @@ class GraphQL:
|
|
483
516
|
@staticmethod
|
484
517
|
def _createMeasurementResolver(field_name: str) -> Callable[..., Any]:
|
485
518
|
"""
|
486
|
-
Creates a resolver
|
487
|
-
|
488
|
-
|
489
|
-
field_name (str): The name of the Measurement field to resolve.
|
490
|
-
|
491
|
-
Returns:
|
492
|
-
Callable[..., dict[str, Any] | None]: A resolver that returns a dictionary with 'value' and 'unit' keys, or None if permission is denied or the field is not a Measurement.
|
519
|
+
Creates a resolver for a Measurement field that returns its value and unit, with optional unit conversion.
|
520
|
+
|
521
|
+
The generated resolver checks read permissions for the specified field. If permitted and the field is a Measurement, it returns a dictionary containing the measurement's value and unit, converting to the specified target unit if provided. Returns None if permission is denied or the field is not a Measurement.
|
493
522
|
"""
|
494
523
|
|
495
524
|
def resolver(
|
@@ -527,9 +556,9 @@ class GraphQL:
|
|
527
556
|
@classmethod
|
528
557
|
def _createResolver(cls, field_name: str, field_type: type) -> Callable[..., Any]:
|
529
558
|
"""
|
530
|
-
|
531
|
-
|
532
|
-
For fields ending with `_list`
|
559
|
+
Returns a resolver function for a field, selecting list, measurement, or standard resolution based on the field's type and name.
|
560
|
+
|
561
|
+
For fields ending with `_list` referencing a `GeneralManager` subclass, provides a resolver supporting pagination and filtering. For `Measurement` fields, returns a resolver that handles unit conversion and permission checks. For all other fields, returns a standard resolver with permission enforcement.
|
533
562
|
"""
|
534
563
|
if field_name.endswith("_list") and issubclass(field_type, GeneralManager):
|
535
564
|
return cls._createListResolver(
|
@@ -546,13 +575,9 @@ class GraphQL:
|
|
546
575
|
item_type: type[graphene.ObjectType] | Callable[[], type[graphene.ObjectType]],
|
547
576
|
) -> type[graphene.ObjectType]:
|
548
577
|
"""
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
page_type_name (str): The name to use for the paginated type.
|
553
|
-
|
554
|
-
Returns:
|
555
|
-
type[graphene.ObjectType]: A GraphQL ObjectType with `items` (list of item_type) and `pageInfo` (pagination metadata).
|
578
|
+
Returns a paginated GraphQL ObjectType for the specified item type, creating and caching it if it does not already exist.
|
579
|
+
|
580
|
+
The returned ObjectType includes an `items` field (a required list of the item type) and a `pageInfo` field (pagination metadata).
|
556
581
|
"""
|
557
582
|
if page_type_name not in cls._page_type_registry:
|
558
583
|
cls._page_type_registry[page_type_name] = type(
|
@@ -571,8 +596,8 @@ class GraphQL:
|
|
571
596
|
) -> None:
|
572
597
|
"""
|
573
598
|
Adds paginated list and single-item query fields for a GeneralManager subclass to the GraphQL schema.
|
574
|
-
|
575
|
-
The list query field
|
599
|
+
|
600
|
+
The list query field enables filtering, exclusion, sorting, pagination, and grouping, returning a paginated result with metadata. The single-item query field retrieves an instance by its identification fields. Both queries are registered with their respective resolvers.
|
576
601
|
"""
|
577
602
|
if not issubclass(generalManagerClass, GeneralManager):
|
578
603
|
raise TypeError(
|
@@ -642,10 +667,10 @@ class GraphQL:
|
|
642
667
|
@classmethod
|
643
668
|
def createWriteFields(cls, interface_cls: InterfaceBase) -> dict[str, Any]:
|
644
669
|
"""
|
645
|
-
|
646
|
-
|
647
|
-
Skips system-managed and derived attributes. For attributes referencing `GeneralManager` subclasses, uses an ID or list of IDs as appropriate. Other types are mapped to their corresponding Graphene scalar types. Each field is annotated with an `editable` attribute.
|
648
|
-
|
670
|
+
Generates a dictionary of Graphene input fields for mutations based on the attributes of the provided interface class.
|
671
|
+
|
672
|
+
Skips system-managed and derived attributes. For attributes referencing `GeneralManager` subclasses, uses an ID or list of IDs as appropriate. Other types are mapped to their corresponding Graphene scalar types. Each field is annotated with an `editable` attribute. Always includes an optional `history_comment` field marked as editable.
|
673
|
+
|
649
674
|
Returns:
|
650
675
|
dict[str, Any]: Mapping of attribute names to Graphene input fields for mutation arguments.
|
651
676
|
"""
|
@@ -698,11 +723,11 @@ class GraphQL:
|
|
698
723
|
) -> type[graphene.Mutation] | None:
|
699
724
|
"""
|
700
725
|
Dynamically generates a Graphene mutation class for creating an instance of a specified GeneralManager subclass.
|
701
|
-
|
702
|
-
The generated mutation class
|
703
|
-
|
726
|
+
|
727
|
+
The generated mutation class uses the manager's interface to define input arguments, filters out fields with `NOT_PROVIDED` values, and invokes the manager's `create` method with the provided data and the current user's ID. On success, it returns a dictionary with a success flag and the created instance; on failure, it raises a GraphQL error. Returns `None` if the manager class does not define an interface.
|
728
|
+
|
704
729
|
Returns:
|
705
|
-
The generated Graphene mutation class, or None if the manager class does not define an interface.
|
730
|
+
The generated Graphene mutation class, or `None` if the manager class does not define an interface.
|
706
731
|
"""
|
707
732
|
interface_cls: InterfaceBase | None = getattr(
|
708
733
|
generalManagerClass, "Interface", None
|
@@ -716,9 +741,9 @@ class GraphQL:
|
|
716
741
|
**kwargs: Any,
|
717
742
|
) -> dict:
|
718
743
|
"""
|
719
|
-
Creates a new instance of the manager class
|
720
|
-
|
721
|
-
Filters out fields set to `NOT_PROVIDED` before creation. Returns a dictionary
|
744
|
+
Creates a new instance of the manager class using the provided arguments.
|
745
|
+
|
746
|
+
Filters out any fields set to `NOT_PROVIDED` before invoking the creation method. Returns a dictionary with a success flag and the created instance keyed by the manager class name. If creation fails, raises a GraphQL error and returns a dictionary with `success` set to `False`.
|
722
747
|
"""
|
723
748
|
try:
|
724
749
|
kwargs = {
|
@@ -769,11 +794,11 @@ class GraphQL:
|
|
769
794
|
) -> type[graphene.Mutation] | None:
|
770
795
|
"""
|
771
796
|
Generates a GraphQL mutation class for updating an instance of a GeneralManager subclass.
|
772
|
-
|
773
|
-
The generated mutation accepts editable fields as arguments,
|
774
|
-
|
797
|
+
|
798
|
+
The generated mutation accepts editable fields as arguments, calls the manager's `update` method with the provided values and the current user's ID, and returns a dictionary containing a success flag and the updated instance. Returns `None` if the manager class does not define an `Interface`.
|
799
|
+
|
775
800
|
Returns:
|
776
|
-
The generated Graphene mutation class, or None if no interface is defined.
|
801
|
+
The generated Graphene mutation class, or `None` if no interface is defined.
|
777
802
|
"""
|
778
803
|
interface_cls: InterfaceBase | None = getattr(
|
779
804
|
generalManagerClass, "Interface", None
|
@@ -787,14 +812,14 @@ class GraphQL:
|
|
787
812
|
**kwargs: Any,
|
788
813
|
) -> dict:
|
789
814
|
"""
|
790
|
-
Updates an instance of
|
791
|
-
|
815
|
+
Updates an instance of a GeneralManager subclass with the specified field values.
|
816
|
+
|
792
817
|
Parameters:
|
793
|
-
info (GraphQLResolveInfo): The GraphQL resolver context,
|
794
|
-
**kwargs:
|
795
|
-
|
818
|
+
info (GraphQLResolveInfo): The GraphQL resolver context, including user and request data.
|
819
|
+
**kwargs: Field values to update, including the required 'id' of the instance.
|
820
|
+
|
796
821
|
Returns:
|
797
|
-
dict:
|
822
|
+
dict: A dictionary with 'success' (bool) and the updated instance keyed by its class name.
|
798
823
|
"""
|
799
824
|
try:
|
800
825
|
manager_id = kwargs.pop("id", None)
|
@@ -841,9 +866,9 @@ class GraphQL:
|
|
841
866
|
) -> type[graphene.Mutation] | None:
|
842
867
|
"""
|
843
868
|
Generates a GraphQL mutation class for deactivating (soft-deleting) an instance of a GeneralManager subclass.
|
844
|
-
|
845
|
-
The generated mutation accepts input fields defined by the manager's interface, deactivates the specified instance using its ID, and returns a dictionary containing a success status and the deactivated instance keyed by the class name.
|
846
|
-
|
869
|
+
|
870
|
+
The generated mutation accepts input fields defined by the manager's interface, deactivates the specified instance using its ID, and returns a dictionary containing a success status and the deactivated instance keyed by the class name. Returns None if the manager class does not define an interface.
|
871
|
+
|
847
872
|
Returns:
|
848
873
|
The generated Graphene mutation class, or None if no interface is defined.
|
849
874
|
"""
|
@@ -859,14 +884,10 @@ class GraphQL:
|
|
859
884
|
**kwargs: Any,
|
860
885
|
) -> dict:
|
861
886
|
"""
|
862
|
-
Deactivates an instance of
|
863
|
-
|
864
|
-
Parameters:
|
865
|
-
info (GraphQLResolveInfo): GraphQL resolver context containing user information.
|
866
|
-
**kwargs: Arguments including the instance ID to deactivate.
|
867
|
-
|
887
|
+
Deactivates an instance of a GeneralManager subclass and returns the operation result.
|
888
|
+
|
868
889
|
Returns:
|
869
|
-
dict:
|
890
|
+
dict: A dictionary with a "success" boolean and the deactivated instance keyed by its class name.
|
870
891
|
"""
|
871
892
|
try:
|
872
893
|
manager_id = kwargs.pop("id", None)
|
@@ -908,9 +929,9 @@ class GraphQL:
|
|
908
929
|
@staticmethod
|
909
930
|
def _handleGraphQLError(error: Exception) -> None:
|
910
931
|
"""
|
911
|
-
Raises a GraphQLError with
|
912
|
-
|
913
|
-
|
932
|
+
Raises a GraphQLError with a specific error code based on the exception type.
|
933
|
+
|
934
|
+
PermissionError results in "PERMISSION_DENIED", ValueError or ValidationError in "BAD_USER_INPUT", and all other exceptions in "INTERNAL_SERVER_ERROR".
|
914
935
|
"""
|
915
936
|
if isinstance(error, PermissionError):
|
916
937
|
raise GraphQLError(
|
@@ -1,6 +1,7 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
from typing import Type, Any, Callable, TYPE_CHECKING, TypeVar, Generic, cast
|
3
3
|
from django.db import models
|
4
|
+
|
4
5
|
from datetime import datetime, timedelta
|
5
6
|
from general_manager.measurement.measurement import Measurement
|
6
7
|
from general_manager.measurement.measurementField import MeasurementField
|
@@ -66,6 +67,25 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
66
67
|
instance = self.getHistoricalRecord(instance, search_date)
|
67
68
|
return instance
|
68
69
|
|
70
|
+
@staticmethod
|
71
|
+
def __parseKwargs(**kwargs: Any) -> dict[str, Any]:
|
72
|
+
"""
|
73
|
+
Parses keyword arguments to ensure they are compatible with the model's fields.
|
74
|
+
|
75
|
+
Converts GeneralManager instances to their primary key values and returns a dictionary of parsed arguments.
|
76
|
+
"""
|
77
|
+
from general_manager.manager.generalManager import GeneralManager
|
78
|
+
|
79
|
+
parsed_kwargs: dict[str, Any] = {}
|
80
|
+
for key, value in kwargs.items():
|
81
|
+
if isinstance(value, GeneralManager):
|
82
|
+
parsed_kwargs[key] = getattr(
|
83
|
+
value._interface, "_instance", value.identification["id"]
|
84
|
+
)
|
85
|
+
else:
|
86
|
+
parsed_kwargs[key] = value
|
87
|
+
return parsed_kwargs
|
88
|
+
|
69
89
|
@classmethod
|
70
90
|
def filter(cls, **kwargs: Any) -> DatabaseBucket:
|
71
91
|
"""
|
@@ -77,6 +97,9 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
77
97
|
Returns:
|
78
98
|
A DatabaseBucket wrapping the filtered queryset and associated metadata.
|
79
99
|
"""
|
100
|
+
|
101
|
+
kwargs = cls.__parseKwargs(**kwargs)
|
102
|
+
|
80
103
|
return DatabaseBucket(
|
81
104
|
cls._model.objects.filter(**kwargs),
|
82
105
|
cls._parent_class,
|
@@ -94,6 +117,8 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
94
117
|
Returns:
|
95
118
|
A DatabaseBucket wrapping the queryset of excluded model instances.
|
96
119
|
"""
|
120
|
+
kwargs = cls.__parseKwargs(**kwargs)
|
121
|
+
|
97
122
|
return DatabaseBucket(
|
98
123
|
cls._model.objects.exclude(**kwargs),
|
99
124
|
cls._parent_class,
|
@@ -135,9 +160,9 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
135
160
|
@classmethod
|
136
161
|
def getAttributeTypes(cls) -> dict[str, AttributeTypedDict]:
|
137
162
|
"""
|
138
|
-
Return a dictionary mapping each attribute name
|
163
|
+
Return a dictionary mapping each model attribute name to its type information and metadata.
|
139
164
|
|
140
|
-
|
165
|
+
Includes standard fields, custom fields, foreign keys, many-to-many, and reverse relation fields, excluding GenericForeignKey fields. For each attribute, provides its Python type (translated from Django field types when possible), required and editable status, whether it is derived, and its default value. For related models with a general manager class, the type is set to that class.
|
141
166
|
|
142
167
|
Returns:
|
143
168
|
dict[str, AttributeTypedDict]: Mapping of attribute names to their type information and metadata.
|
@@ -178,7 +203,8 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
178
203
|
fields[field_name] = {
|
179
204
|
"type": type(field),
|
180
205
|
"is_derived": False,
|
181
|
-
"is_required": not field.null
|
206
|
+
"is_required": not field.null
|
207
|
+
and field.default is models.NOT_PROVIDED,
|
182
208
|
"is_editable": field.editable,
|
183
209
|
"default": field.default,
|
184
210
|
}
|
@@ -196,7 +222,7 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
196
222
|
):
|
197
223
|
related_model = related_model._general_manager_class # type: ignore
|
198
224
|
|
199
|
-
|
225
|
+
if related_model is not None:
|
200
226
|
default = None
|
201
227
|
if hasattr(field, "default"):
|
202
228
|
default = field.default # type: ignore
|
@@ -247,12 +273,12 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
247
273
|
@classmethod
|
248
274
|
def getAttributes(cls) -> dict[str, Callable[[DBBasedInterface], Any]]:
|
249
275
|
"""
|
250
|
-
Return a
|
276
|
+
Return a mapping of attribute names to callables that extract values from a DBBasedInterface instance.
|
251
277
|
|
252
|
-
The
|
278
|
+
The returned dictionary includes accessors for custom fields, standard model fields, foreign keys, many-to-many relations, and reverse relations. For related models with a general manager class, the accessor returns an instance or queryset of that class; otherwise, it returns the related object or queryset directly. Raises a ValueError if a field name conflict is detected.
|
253
279
|
|
254
280
|
Returns:
|
255
|
-
dict
|
281
|
+
dict[str, Callable[[DBBasedInterface], Any]]: Mapping of attribute names to callables for retrieving values from a DBBasedInterface instance.
|
256
282
|
"""
|
257
283
|
from general_manager.manager.generalManager import GeneralManager
|
258
284
|
|
@@ -306,12 +332,22 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
306
332
|
cls._model._meta.get_field(field_name).related_model,
|
307
333
|
"_general_manager_class",
|
308
334
|
):
|
335
|
+
related_model = cast(
|
336
|
+
Type[models.Model],
|
337
|
+
cls._model._meta.get_field(field_name).related_model,
|
338
|
+
)
|
339
|
+
related_fields = [
|
340
|
+
f
|
341
|
+
for f in related_model._meta.get_fields()
|
342
|
+
if f.related_model == cls._model
|
343
|
+
]
|
344
|
+
|
309
345
|
field_values[
|
310
346
|
f"{field_name}_list"
|
311
|
-
] = lambda self, field_name=field_name: self._instance._meta.get_field(
|
347
|
+
] = lambda self, field_name=field_name, related_fields=related_fields: self._instance._meta.get_field(
|
312
348
|
field_name
|
313
349
|
).related_model._general_manager_class.filter(
|
314
|
-
**{
|
350
|
+
**{related_field.name: self.pk for related_field in related_fields}
|
315
351
|
)
|
316
352
|
else:
|
317
353
|
field_values[f"{field_name}_list"] = (
|
@@ -319,6 +355,7 @@ class DBBasedInterface(InterfaceBase, Generic[MODEL_TYPE]):
|
|
319
355
|
self._instance, field_call
|
320
356
|
).all()
|
321
357
|
)
|
358
|
+
|
322
359
|
return field_values
|
323
360
|
|
324
361
|
@staticmethod
|
{generalmanager-0.12.0 → generalmanager-0.12.2}/src/general_manager/interface/databaseInterface.py
RENAMED
@@ -84,19 +84,23 @@ class DatabaseInterface(DBBasedInterface[GeneralManagerModel]):
|
|
84
84
|
instance: GeneralManagerModel, many_to_many_kwargs: dict[str, list[Any]]
|
85
85
|
) -> GeneralManagerModel:
|
86
86
|
"""
|
87
|
-
|
87
|
+
Set many-to-many relationship fields on a model instance using provided values.
|
88
88
|
|
89
|
-
|
90
|
-
instance: The model instance to update.
|
91
|
-
many_to_many_kwargs: A dictionary containing many-to-many field names and their corresponding values.
|
92
|
-
|
93
|
-
Returns:
|
94
|
-
The updated model instance.
|
89
|
+
Converts lists of `GeneralManager` instances to their corresponding IDs before updating the relationships. Returns the updated instance.
|
95
90
|
"""
|
91
|
+
from general_manager.manager.generalManager import GeneralManager
|
92
|
+
|
96
93
|
for key, value in many_to_many_kwargs.items():
|
97
94
|
if not value:
|
98
95
|
continue
|
99
|
-
field_name = key.
|
96
|
+
field_name = key.removesuffix("_id_list")
|
97
|
+
if isinstance(value, list) and all(
|
98
|
+
isinstance(v, GeneralManager) for v in value
|
99
|
+
):
|
100
|
+
value = [
|
101
|
+
v.identification["id"] if hasattr(v, "identification") else v
|
102
|
+
for v in value
|
103
|
+
]
|
100
104
|
getattr(instance, field_name).set(value)
|
101
105
|
|
102
106
|
return instance
|
@@ -39,7 +39,7 @@ def getFullCleanMethode(model: Type[models.Model]) -> Callable[..., None]:
|
|
39
39
|
except ValidationError as e:
|
40
40
|
errors.update(e.message_dict)
|
41
41
|
|
42
|
-
rules: list[Rule] = getattr(self._meta, "rules")
|
42
|
+
rules: list[Rule] = getattr(self._meta, "rules", [])
|
43
43
|
for rule in rules:
|
44
44
|
if rule.evaluate(self) is False:
|
45
45
|
error_message = rule.getErrorMessage()
|