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
@@ -0,0 +1,107 @@
|
|
1
|
+
from __future__ import annotations
|
2
|
+
import json
|
3
|
+
|
4
|
+
from typing import Type, Any, Callable, TYPE_CHECKING
|
5
|
+
from django.db import models, transaction
|
6
|
+
from general_manager.interface.databaseBasedInterface import (
|
7
|
+
DBBasedInterface,
|
8
|
+
GeneralManagerModel,
|
9
|
+
classPreCreationMethod,
|
10
|
+
classPostCreationMethod,
|
11
|
+
)
|
12
|
+
|
13
|
+
if TYPE_CHECKING:
|
14
|
+
from general_manager.manager.generalManager import GeneralManager
|
15
|
+
from general_manager.manager.meta import GeneralManagerMeta
|
16
|
+
|
17
|
+
|
18
|
+
class ReadOnlyInterface(DBBasedInterface):
|
19
|
+
_interface_type = "readonly"
|
20
|
+
|
21
|
+
@classmethod
|
22
|
+
def sync_data(cls) -> None:
|
23
|
+
"""
|
24
|
+
Synchronizes the database model with JSON data, ensuring exact correspondence.
|
25
|
+
|
26
|
+
This method parses JSON data from the parent class and updates the associated Django model so that its records exactly match the JSON content. It creates or updates instances based on unique fields and deletes any database entries not present in the JSON data. Raises a ValueError if required attributes are missing or if the JSON data is invalid.
|
27
|
+
"""
|
28
|
+
model: Type[models.Model] | None = getattr(cls, "_model", None)
|
29
|
+
parent_class = getattr(cls, "_parent_class", None)
|
30
|
+
if model is None or parent_class is None:
|
31
|
+
raise ValueError("Attribute '_model' and '_parent_class' must be set.")
|
32
|
+
json_data = getattr(parent_class, "_json_data", None)
|
33
|
+
if not json_data:
|
34
|
+
raise ValueError(
|
35
|
+
f"For ReadOnlyInterface '{parent_class.__name__}' must be set '_json_data'"
|
36
|
+
)
|
37
|
+
|
38
|
+
# JSON-Daten parsen
|
39
|
+
if isinstance(json_data, str):
|
40
|
+
data_list = json.loads(json_data)
|
41
|
+
elif isinstance(json_data, list):
|
42
|
+
data_list: list[Any] = json_data
|
43
|
+
else:
|
44
|
+
raise ValueError(
|
45
|
+
"_json_data must be a JSON string or a list of dictionaries"
|
46
|
+
)
|
47
|
+
|
48
|
+
unique_fields = getattr(parent_class, "_unique_fields", [])
|
49
|
+
if not unique_fields:
|
50
|
+
raise ValueError(
|
51
|
+
f"For ReadOnlyInterface '{parent_class.__name__}' must be defined '_unique_fields'"
|
52
|
+
)
|
53
|
+
|
54
|
+
with transaction.atomic():
|
55
|
+
json_unique_values: set[Any] = set()
|
56
|
+
|
57
|
+
# Daten synchronisieren
|
58
|
+
for data in data_list:
|
59
|
+
lookup = {field: data[field] for field in unique_fields}
|
60
|
+
unique_identifier = tuple(lookup[field] for field in unique_fields)
|
61
|
+
json_unique_values.add(unique_identifier)
|
62
|
+
|
63
|
+
instance, _ = model.objects.get_or_create(**lookup)
|
64
|
+
updated = False
|
65
|
+
for field_name, value in data.items():
|
66
|
+
if getattr(instance, field_name, None) != value:
|
67
|
+
setattr(instance, field_name, value)
|
68
|
+
updated = True
|
69
|
+
if updated:
|
70
|
+
instance.save()
|
71
|
+
|
72
|
+
# Existierende Einträge abrufen und löschen, wenn nicht im JSON vorhanden
|
73
|
+
existing_instances = model.objects.all()
|
74
|
+
for instance in existing_instances:
|
75
|
+
lookup = {field: getattr(instance, field) for field in unique_fields}
|
76
|
+
unique_identifier = tuple(lookup[field] for field in unique_fields)
|
77
|
+
if unique_identifier not in json_unique_values:
|
78
|
+
instance.delete()
|
79
|
+
|
80
|
+
@staticmethod
|
81
|
+
def readOnlyPostCreate(func: Callable[..., Any]) -> Callable[..., Any]:
|
82
|
+
"""
|
83
|
+
Decorator for post-creation hooks that registers the interface class as read-only.
|
84
|
+
|
85
|
+
Wraps a function to be called after a class creation event, then appends the interface
|
86
|
+
class to the meta-class's `read_only_classes` list.
|
87
|
+
"""
|
88
|
+
|
89
|
+
def wrapper(
|
90
|
+
mcs: Type[GeneralManagerMeta],
|
91
|
+
new_class: Type[GeneralManager],
|
92
|
+
interface_cls: Type[ReadOnlyInterface],
|
93
|
+
model: Type[GeneralManagerModel],
|
94
|
+
):
|
95
|
+
func(mcs, new_class, interface_cls, model)
|
96
|
+
mcs.read_only_classes.append(interface_cls)
|
97
|
+
|
98
|
+
return wrapper
|
99
|
+
|
100
|
+
@classmethod
|
101
|
+
def handleInterface(cls) -> tuple[classPreCreationMethod, classPostCreationMethod]:
|
102
|
+
"""
|
103
|
+
Returns pre- and post-creation methods for integrating the interface with a GeneralManager.
|
104
|
+
|
105
|
+
The pre-creation method modifies keyword arguments before a GeneralManager instance is created. The post-creation method, wrapped with a decorator, modifies the instance after creation to add additional data. These methods are intended for use by the GeneralManagerMeta class during the manager's lifecycle.
|
106
|
+
"""
|
107
|
+
return cls._preCreate, cls.readOnlyPostCreate(cls._postCreate)
|
@@ -1,17 +1,18 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
from typing import Generic, Type, Any, TYPE_CHECKING
|
2
|
+
from typing import Generic, Type, Any, TYPE_CHECKING, TypeVar
|
3
3
|
from general_manager.manager.meta import GeneralManagerMeta
|
4
|
-
|
5
|
-
InterfaceBase,
|
6
|
-
Bucket,
|
7
|
-
GeneralManagerType,
|
8
|
-
)
|
4
|
+
|
9
5
|
from general_manager.api.property import GraphQLProperty
|
10
6
|
from general_manager.cache.cacheTracker import DependencyTracker
|
11
7
|
from general_manager.cache.signals import dataChange
|
8
|
+
from general_manager.bucket.baseBucket import Bucket
|
12
9
|
|
13
10
|
if TYPE_CHECKING:
|
14
11
|
from general_manager.permission.basePermission import BasePermission
|
12
|
+
from general_manager.interface.baseInterface import (
|
13
|
+
InterfaceBase,
|
14
|
+
)
|
15
|
+
GeneralManagerType = TypeVar("GeneralManagerType", bound="GeneralManager")
|
15
16
|
|
16
17
|
|
17
18
|
class GeneralManager(Generic[GeneralManagerType], metaclass=GeneralManagerMeta):
|
@@ -129,15 +130,15 @@ class GeneralManager(Generic[GeneralManagerType], metaclass=GeneralManagerMeta):
|
|
129
130
|
@staticmethod
|
130
131
|
def __parse_identification(kwargs: dict[str, Any]) -> dict[str, Any] | None:
|
131
132
|
"""
|
132
|
-
|
133
|
+
Processes a dictionary by replacing GeneralManager instances with their identifications.
|
133
134
|
|
134
|
-
For each key-value pair,
|
135
|
+
For each key-value pair, replaces any GeneralManager instance with its identification. Lists and tuples are processed recursively, substituting contained GeneralManager instances with their identifications. Returns None if the resulting dictionary is empty.
|
135
136
|
|
136
137
|
Args:
|
137
|
-
kwargs: Dictionary
|
138
|
+
kwargs: Dictionary to process.
|
138
139
|
|
139
140
|
Returns:
|
140
|
-
A new dictionary with GeneralManager instances replaced by their identifications, or None if
|
141
|
+
A new dictionary with GeneralManager instances replaced by their identifications, or None if empty.
|
141
142
|
"""
|
142
143
|
output = {}
|
143
144
|
for key, value in kwargs.items():
|
@@ -1,204 +1,21 @@
|
|
1
1
|
from __future__ import annotations
|
2
2
|
from typing import (
|
3
3
|
Type,
|
4
|
-
Generator,
|
5
4
|
Any,
|
6
5
|
Generic,
|
7
6
|
get_args,
|
8
7
|
cast,
|
9
8
|
)
|
10
|
-
import json
|
11
9
|
from datetime import datetime, date, time
|
12
10
|
from general_manager.api.graphql import GraphQLProperty
|
13
11
|
from general_manager.measurement import Measurement
|
14
12
|
from general_manager.manager.generalManager import GeneralManager
|
15
|
-
from general_manager.
|
13
|
+
from general_manager.bucket.baseBucket import (
|
16
14
|
Bucket,
|
17
15
|
GeneralManagerType,
|
18
16
|
)
|
19
17
|
|
20
18
|
|
21
|
-
class GroupBucket(Bucket[GeneralManagerType]):
|
22
|
-
|
23
|
-
def __init__(
|
24
|
-
self,
|
25
|
-
manager_class: Type[GeneralManagerType],
|
26
|
-
group_by_keys: tuple[str, ...],
|
27
|
-
data: Bucket[GeneralManagerType],
|
28
|
-
):
|
29
|
-
super().__init__(manager_class)
|
30
|
-
self.__checkGroupByArguments(group_by_keys)
|
31
|
-
self._group_by_keys = group_by_keys
|
32
|
-
self._data = self.__buildGroupedManager(data)
|
33
|
-
self._basis_data = data
|
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
|
-
|
44
|
-
def __checkGroupByArguments(self, group_by_keys: tuple[str, ...]) -> None:
|
45
|
-
"""
|
46
|
-
This method checks if the given arguments are valid for the groupBy method.
|
47
|
-
It raises a TypeError if the arguments are not valid.
|
48
|
-
"""
|
49
|
-
if not all(isinstance(arg, str) for arg in group_by_keys):
|
50
|
-
raise TypeError("groupBy() argument must be a string")
|
51
|
-
if not all(
|
52
|
-
arg in self._manager_class.Interface.getAttributes().keys()
|
53
|
-
for arg in group_by_keys
|
54
|
-
):
|
55
|
-
raise TypeError(
|
56
|
-
f"groupBy() argument must be a valid attribute of {self._manager_class.__name__}"
|
57
|
-
)
|
58
|
-
|
59
|
-
def __buildGroupedManager(
|
60
|
-
self,
|
61
|
-
data: Bucket[GeneralManagerType],
|
62
|
-
) -> list[GroupManager[GeneralManagerType]]:
|
63
|
-
"""
|
64
|
-
This method builds the grouped manager.
|
65
|
-
It returns a GroupBucket with the grouped data.
|
66
|
-
"""
|
67
|
-
group_by_values = set()
|
68
|
-
for entry in data:
|
69
|
-
group_by_value = {}
|
70
|
-
for arg in self._group_by_keys:
|
71
|
-
group_by_value[arg] = getattr(entry, arg)
|
72
|
-
group_by_values.add(json.dumps(group_by_value))
|
73
|
-
|
74
|
-
groups = []
|
75
|
-
for group_by_value in sorted(group_by_values):
|
76
|
-
group_by_value = json.loads(group_by_value)
|
77
|
-
grouped_manager_objects = data.filter(**group_by_value)
|
78
|
-
groups.append(
|
79
|
-
GroupManager(
|
80
|
-
self._manager_class, group_by_value, grouped_manager_objects
|
81
|
-
)
|
82
|
-
)
|
83
|
-
return groups
|
84
|
-
|
85
|
-
def __or__(self, other: object) -> GroupBucket[GeneralManagerType]:
|
86
|
-
if not isinstance(other, self.__class__):
|
87
|
-
raise ValueError("Cannot combine different bucket types")
|
88
|
-
if self._manager_class != other._manager_class:
|
89
|
-
raise ValueError("Cannot combine different manager classes")
|
90
|
-
return GroupBucket(
|
91
|
-
self._manager_class,
|
92
|
-
self._group_by_keys,
|
93
|
-
self._basis_data | other._basis_data,
|
94
|
-
)
|
95
|
-
|
96
|
-
def __iter__(self) -> Generator[GroupManager[GeneralManagerType]]:
|
97
|
-
for grouped_manager in self._data:
|
98
|
-
yield grouped_manager
|
99
|
-
|
100
|
-
def filter(self, **kwargs: Any) -> GroupBucket[GeneralManagerType]:
|
101
|
-
new_basis_data = self._basis_data.filter(**kwargs)
|
102
|
-
return GroupBucket(
|
103
|
-
self._manager_class,
|
104
|
-
self._group_by_keys,
|
105
|
-
new_basis_data,
|
106
|
-
)
|
107
|
-
|
108
|
-
def exclude(self, **kwargs: Any) -> GroupBucket[GeneralManagerType]:
|
109
|
-
new_basis_data = self._basis_data.exclude(**kwargs)
|
110
|
-
return GroupBucket(
|
111
|
-
self._manager_class,
|
112
|
-
self._group_by_keys,
|
113
|
-
new_basis_data,
|
114
|
-
)
|
115
|
-
|
116
|
-
def first(self) -> GroupManager[GeneralManagerType] | None:
|
117
|
-
try:
|
118
|
-
return next(iter(self))
|
119
|
-
except StopIteration:
|
120
|
-
return None
|
121
|
-
|
122
|
-
def last(self) -> GroupManager[GeneralManagerType] | None:
|
123
|
-
items = list(self)
|
124
|
-
if items:
|
125
|
-
return items[-1]
|
126
|
-
return None
|
127
|
-
|
128
|
-
def count(self) -> int:
|
129
|
-
return sum(1 for _ in self)
|
130
|
-
|
131
|
-
def all(self) -> Bucket[GeneralManagerType]:
|
132
|
-
return self
|
133
|
-
|
134
|
-
def get(self, **kwargs: Any) -> GroupManager[GeneralManagerType]:
|
135
|
-
first_value = self.filter(**kwargs).first()
|
136
|
-
if first_value is None:
|
137
|
-
raise ValueError(
|
138
|
-
f"Cannot find {self._manager_class.__name__} with {kwargs}"
|
139
|
-
)
|
140
|
-
return first_value
|
141
|
-
|
142
|
-
def __getitem__(
|
143
|
-
self, item: int | slice
|
144
|
-
) -> GroupManager[GeneralManagerType] | GroupBucket[GeneralManagerType]:
|
145
|
-
if isinstance(item, int):
|
146
|
-
return self._data[item]
|
147
|
-
elif isinstance(item, slice):
|
148
|
-
new_data = self._data[item]
|
149
|
-
new_base_data = None
|
150
|
-
for manager in new_data:
|
151
|
-
if new_base_data is None:
|
152
|
-
new_base_data = manager._data
|
153
|
-
else:
|
154
|
-
new_base_data = new_base_data | manager._data
|
155
|
-
if new_base_data is None:
|
156
|
-
raise ValueError("Cannot slice an empty GroupBucket")
|
157
|
-
return GroupBucket(self._manager_class, self._group_by_keys, new_base_data)
|
158
|
-
raise TypeError(f"Invalid argument type: {type(item)}. Expected int or slice.")
|
159
|
-
|
160
|
-
def __len__(self) -> int:
|
161
|
-
return self.count()
|
162
|
-
|
163
|
-
def __contains__(self, item: GeneralManagerType) -> bool:
|
164
|
-
return item in self._basis_data
|
165
|
-
|
166
|
-
def sort(
|
167
|
-
self,
|
168
|
-
key: tuple[str] | str,
|
169
|
-
reverse: bool = False,
|
170
|
-
) -> Bucket[GeneralManagerType]:
|
171
|
-
if isinstance(key, str):
|
172
|
-
key = (key,)
|
173
|
-
if reverse:
|
174
|
-
sorted_data = sorted(
|
175
|
-
self._data,
|
176
|
-
key=lambda x: tuple(getattr(x, k) for k in key),
|
177
|
-
reverse=True,
|
178
|
-
)
|
179
|
-
else:
|
180
|
-
sorted_data = sorted(
|
181
|
-
self._data, key=lambda x: tuple(getattr(x, k) for k in key)
|
182
|
-
)
|
183
|
-
|
184
|
-
new_bucket = GroupBucket(
|
185
|
-
self._manager_class, self._group_by_keys, self._basis_data
|
186
|
-
)
|
187
|
-
new_bucket._data = sorted_data
|
188
|
-
return new_bucket
|
189
|
-
|
190
|
-
def group_by(self, *group_by_keys: str) -> GroupBucket[GeneralManagerType]:
|
191
|
-
"""
|
192
|
-
This method groups the data by the given arguments.
|
193
|
-
It returns a GroupBucket with the grouped data.
|
194
|
-
"""
|
195
|
-
return GroupBucket(
|
196
|
-
self._manager_class,
|
197
|
-
tuple([*self._group_by_keys, *group_by_keys]),
|
198
|
-
self._basis_data,
|
199
|
-
)
|
200
|
-
|
201
|
-
|
202
19
|
class GroupManager(Generic[GeneralManagerType]):
|
203
20
|
"""
|
204
21
|
This class is used to group the data of a GeneralManager.
|
@@ -216,13 +33,21 @@ class GroupManager(Generic[GeneralManagerType]):
|
|
216
33
|
self._data = data
|
217
34
|
self._grouped_data: dict[str, Any] = {}
|
218
35
|
|
36
|
+
def __hash__(self) -> int:
|
37
|
+
return hash(
|
38
|
+
(
|
39
|
+
self._manager_class,
|
40
|
+
tuple(self._group_by_value.items()),
|
41
|
+
frozenset(self._data),
|
42
|
+
)
|
43
|
+
)
|
44
|
+
|
219
45
|
def __eq__(self, other: object) -> bool:
|
220
|
-
if not isinstance(other, self.__class__):
|
221
|
-
return False
|
222
46
|
return (
|
223
|
-
self.
|
47
|
+
isinstance(other, self.__class__)
|
224
48
|
and self._manager_class == other._manager_class
|
225
49
|
and self._group_by_value == other._group_by_value
|
50
|
+
and frozenset(self._data) == frozenset(other._data)
|
226
51
|
)
|
227
52
|
|
228
53
|
def __repr__(self) -> str:
|
general_manager/manager/meta.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
from __future__ import annotations
|
2
|
-
|
3
|
-
InterfaceBase,
|
4
|
-
)
|
2
|
+
|
5
3
|
from django.conf import settings
|
6
4
|
from typing import Any, Type, TYPE_CHECKING, Generic, TypeVar, Iterable
|
5
|
+
from general_manager.interface.baseInterface import InterfaceBase
|
7
6
|
|
8
7
|
if TYPE_CHECKING:
|
9
|
-
from general_manager.interface.
|
8
|
+
from general_manager.interface.readOnlyInterface import ReadOnlyInterface
|
10
9
|
from general_manager.manager.generalManager import GeneralManager
|
11
10
|
|
11
|
+
|
12
12
|
GeneralManagerType = TypeVar("GeneralManagerType", bound="GeneralManager")
|
13
13
|
|
14
14
|
|
@@ -24,6 +24,20 @@ class GeneralManagerMeta(type):
|
|
24
24
|
Interface: type[InterfaceBase]
|
25
25
|
|
26
26
|
def __new__(mcs, name: str, bases: tuple[type, ...], attrs: dict[str, Any]) -> type:
|
27
|
+
|
28
|
+
"""
|
29
|
+
Creates a new class, handling interface integration and registration for the general manager framework.
|
30
|
+
|
31
|
+
If an 'Interface' attribute is present in the class definition, validates and processes it using the interface's pre- and post-creation hooks, then registers the resulting class for attribute initialization and tracking. If the 'AUTOCREATE_GRAPHQL' setting is enabled, also registers the class for pending GraphQL interface creation.
|
32
|
+
|
33
|
+
Args:
|
34
|
+
name: The name of the class being created.
|
35
|
+
bases: Base classes for the new class.
|
36
|
+
attrs: Attribute dictionary for the new class.
|
37
|
+
|
38
|
+
Returns:
|
39
|
+
The newly created class, possibly augmented with interface and registration logic.
|
40
|
+
"""
|
27
41
|
def createNewGeneralManagerClass(
|
28
42
|
mcs, name: str, bases: tuple[type, ...], attrs: dict[str, Any]
|
29
43
|
) -> Type[GeneralManager]:
|
@@ -33,7 +47,7 @@ class GeneralManagerMeta(type):
|
|
33
47
|
interface = attrs.pop("Interface")
|
34
48
|
if not issubclass(interface, InterfaceBase):
|
35
49
|
raise TypeError(
|
36
|
-
f"
|
50
|
+
f"{interface.__name__} must be a subclass of InterfaceBase"
|
37
51
|
)
|
38
52
|
preCreation, postCreation = interface.handleInterface()
|
39
53
|
attrs, interface_cls, model = preCreation(name, attrs, interface)
|
@@ -6,12 +6,10 @@ from general_manager.permission.permissionChecks import (
|
|
6
6
|
permission_filter,
|
7
7
|
)
|
8
8
|
|
9
|
+
from django.contrib.auth.models import AnonymousUser, AbstractUser
|
10
|
+
from general_manager.permission.permissionDataManager import PermissionDataManager
|
9
11
|
|
10
12
|
if TYPE_CHECKING:
|
11
|
-
from django.contrib.auth.models import AbstractUser, AnonymousUser
|
12
|
-
from general_manager.permission.permissionDataManager import (
|
13
|
-
PermissionDataManager,
|
14
|
-
)
|
15
13
|
from general_manager.manager.generalManager import GeneralManager
|
16
14
|
from general_manager.manager.meta import GeneralManagerMeta
|
17
15
|
|
@@ -66,7 +64,7 @@ class BasePermission(ABC):
|
|
66
64
|
request_user = cls.getUserWithId(request_user)
|
67
65
|
|
68
66
|
errors = []
|
69
|
-
permission_data = PermissionDataManager
|
67
|
+
permission_data = PermissionDataManager.forUpdate(
|
70
68
|
base_data=old_manager_instance, update_data=data
|
71
69
|
)
|
72
70
|
Permission = cls(permission_data, request_user)
|
@@ -90,7 +88,7 @@ class BasePermission(ABC):
|
|
90
88
|
request_user = cls.getUserWithId(request_user)
|
91
89
|
|
92
90
|
errors = []
|
93
|
-
permission_data = PermissionDataManager
|
91
|
+
permission_data = PermissionDataManager(manager_instance)
|
94
92
|
Permission = cls(permission_data, request_user)
|
95
93
|
for key in manager_instance.__dict__.keys():
|
96
94
|
is_allowed = Permission.checkPermission("delete", key)
|
@@ -1,7 +1,7 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GeneralManager
|
3
|
-
Version: 0.
|
4
|
-
Summary:
|
3
|
+
Version: 0.6.0
|
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
|
7
7
|
Requires-Python: >=3.12
|
@@ -37,51 +37,51 @@ Dynamic: license-file
|
|
37
37
|
|
38
38
|
# GeneralManager
|
39
39
|
|
40
|
-
##
|
40
|
+
## Overview
|
41
41
|
|
42
|
-
|
42
|
+
GeneralManager is a powerful and flexible framework designed for managing and processing data. It provides a modular structure that enables developers to implement complex business logic efficiently. The module is written entirely in Python and uses Django as the backend framework.
|
43
43
|
|
44
|
-
##
|
44
|
+
## Key Features
|
45
45
|
|
46
|
-
### 1. **
|
47
|
-
- **
|
48
|
-
- **
|
49
|
-
- **
|
46
|
+
### 1. **Data Management**
|
47
|
+
- **Flexibility**: Supports managing all kinds of data, not just projects and derivatives.
|
48
|
+
- **Database Integration**: Seamless integration with the Django ORM for database operations.
|
49
|
+
- **External Interfaces**: Support for interfaces to other programs, such as Excel.
|
50
50
|
|
51
|
-
### 2. **
|
52
|
-
- **Django
|
53
|
-
- **
|
51
|
+
### 2. **Data Modeling**
|
52
|
+
- **Django Models**: The data structure is based on Django models, extended by custom fields like `MeasurementField`.
|
53
|
+
- **Rules and Validations**: Define rules for data validation, e.g., ensuring that a project's start date is before its end date.
|
54
54
|
|
55
|
-
### 3. **GraphQL
|
56
|
-
-
|
57
|
-
-
|
55
|
+
### 3. **GraphQL Integration**
|
56
|
+
- Automatic generation of GraphQL interfaces for all models.
|
57
|
+
- Support for custom queries and mutations.
|
58
58
|
|
59
|
-
### 4. **
|
60
|
-
- **ManagerBasedPermission**:
|
61
|
-
-
|
59
|
+
### 4. **Permission System**
|
60
|
+
- **ManagerBasedPermission**: A flexible permission system based on user roles and attributes.
|
61
|
+
- Attribute-level CRUD permissions.
|
62
62
|
|
63
63
|
### 5. **Interfaces**
|
64
|
-
- **CalculationInterface**:
|
65
|
-
- **DatabaseInterface**:
|
66
|
-
- **ReadOnlyInterface**:
|
64
|
+
- **CalculationInterface**: Allows the implementation of calculation logic.
|
65
|
+
- **DatabaseInterface**: Provides a standardized interface for database operations.
|
66
|
+
- **ReadOnlyInterface**: For read-only data access.
|
67
67
|
|
68
|
-
### 6. **
|
69
|
-
- **
|
70
|
-
- **
|
68
|
+
### 6. **Data Distribution and Calculations**
|
69
|
+
- **Volume Distribution**: Automatically calculates and distributes volume over multiple years.
|
70
|
+
- **Commercial Calculations**: Calculates total volume, shipping costs, and revenue for projects.
|
71
71
|
|
72
|
-
##
|
72
|
+
## Usage
|
73
73
|
|
74
74
|
### Installation
|
75
75
|
|
76
|
-
|
76
|
+
Install the module via `pip`:
|
77
77
|
|
78
78
|
```bash
|
79
79
|
pip install GeneralManager
|
80
80
|
```
|
81
81
|
|
82
|
-
###
|
82
|
+
### Example Code
|
83
83
|
|
84
|
-
|
84
|
+
The following example demonstrates how to create a GeneralManager and generate sample data (in this case 10 projects):
|
85
85
|
|
86
86
|
```python
|
87
87
|
from general_manager import GeneralManager
|
@@ -134,11 +134,11 @@ class Project(GeneralManager):
|
|
134
134
|
Project.Factory.createBatch(10)
|
135
135
|
```
|
136
136
|
|
137
|
-
### GraphQL
|
137
|
+
### GraphQL Integration
|
138
138
|
|
139
|
-
|
139
|
+
The module automatically generates GraphQL endpoints for all models. You can run queries and mutations through the GraphQL URL defined in your Django settings.
|
140
140
|
|
141
|
-
|
141
|
+
Example of a GraphQL query:
|
142
142
|
|
143
143
|
```graphql
|
144
144
|
query {
|
@@ -154,26 +154,26 @@ query {
|
|
154
154
|
}
|
155
155
|
```
|
156
156
|
|
157
|
-
##
|
157
|
+
## Benefits
|
158
158
|
|
159
|
-
- **
|
160
|
-
- **
|
161
|
-
- **Integration**:
|
162
|
-
- **
|
163
|
-
- **
|
164
|
-
- **Caching**:
|
159
|
+
- **Modularity**: Easy to extend and adapt.
|
160
|
+
- **Flexibility**: Supports complex business logic and calculations.
|
161
|
+
- **Integration**: Seamless integration with Django and GraphQL.
|
162
|
+
- **Permissions**: Fine-grained permissions for users and attributes.
|
163
|
+
- **Data Validation**: Automatic validation of data through rules and constraints.
|
164
|
+
- **Caching**: Automatic cache generation with the `@cached` decorator to improve performance.
|
165
165
|
|
166
|
-
##
|
166
|
+
## Requirements
|
167
167
|
|
168
168
|
- Python >= 3.12
|
169
169
|
- Django >= 5.2
|
170
|
-
-
|
170
|
+
- Additional dependencies (see `requirements.txt`):
|
171
171
|
- `graphene`
|
172
172
|
- `numpy`
|
173
173
|
- `Pint`
|
174
174
|
- `factory_boy`
|
175
|
-
-
|
175
|
+
- and more.
|
176
176
|
|
177
|
-
##
|
177
|
+
## License
|
178
178
|
|
179
|
-
|
179
|
+
This project is distributed under the **Non-Commercial MIT License**. It may only be used for non-commercial purposes. For further details see the [LICENSE](./LICENSE) file.
|