GeneralManager 0.6.1__py3-none-any.whl → 0.6.2__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/interface/databaseInterface.py +58 -34
- {generalmanager-0.6.1.dist-info → generalmanager-0.6.2.dist-info}/METADATA +1 -1
- {generalmanager-0.6.1.dist-info → generalmanager-0.6.2.dist-info}/RECORD +6 -6
- {generalmanager-0.6.1.dist-info → generalmanager-0.6.2.dist-info}/WHEEL +0 -0
- {generalmanager-0.6.1.dist-info → generalmanager-0.6.2.dist-info}/licenses/LICENSE +0 -0
- {generalmanager-0.6.1.dist-info → generalmanager-0.6.2.dist-info}/top_level.txt +0 -0
@@ -18,36 +18,24 @@ class DatabaseInterface(DBBasedInterface):
|
|
18
18
|
def create(
|
19
19
|
cls, creator_id: int, history_comment: str | None = None, **kwargs: Any
|
20
20
|
) -> int:
|
21
|
-
from general_manager.manager.generalManager import GeneralManager
|
22
21
|
|
23
|
-
cls.
|
24
|
-
kwargs, many_to_many_kwargs = cls.
|
25
|
-
instance = cls._model()
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
key = f"{key}_id"
|
30
|
-
setattr(instance, key, value)
|
31
|
-
for key, value in many_to_many_kwargs.items():
|
32
|
-
getattr(instance, key).set(value)
|
33
|
-
return cls.__save_with_history(instance, creator_id, history_comment)
|
22
|
+
cls._checkForInvalidKwargs(cls._model, kwargs=kwargs)
|
23
|
+
kwargs, many_to_many_kwargs = cls._sortKwargs(cls._model, kwargs)
|
24
|
+
instance = cls.__setAttrForWrite(cls._model(), kwargs)
|
25
|
+
pk = cls._save_with_history(instance, creator_id, history_comment)
|
26
|
+
cls.__setManyToManyAttributes(instance, many_to_many_kwargs)
|
27
|
+
return pk
|
34
28
|
|
35
29
|
def update(
|
36
30
|
self, creator_id: int, history_comment: str | None = None, **kwargs: Any
|
37
31
|
) -> int:
|
38
|
-
from general_manager.manager.generalManager import GeneralManager
|
39
32
|
|
40
|
-
self.
|
41
|
-
kwargs, many_to_many_kwargs = self.
|
42
|
-
instance = self._model.objects.get(pk=self.pk)
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
key = f"{key}_id"
|
47
|
-
setattr(instance, key, value)
|
48
|
-
for key, value in many_to_many_kwargs.items():
|
49
|
-
getattr(instance, key).set(value)
|
50
|
-
return self.__save_with_history(instance, creator_id, history_comment)
|
33
|
+
self._checkForInvalidKwargs(self._model, kwargs=kwargs)
|
34
|
+
kwargs, many_to_many_kwargs = self._sortKwargs(self._model, kwargs)
|
35
|
+
instance = self.__setAttrForWrite(self._model.objects.get(pk=self.pk), kwargs)
|
36
|
+
pk = self._save_with_history(instance, creator_id, history_comment)
|
37
|
+
self.__setManyToManyAttributes(instance, many_to_many_kwargs)
|
38
|
+
return pk
|
51
39
|
|
52
40
|
def deactivate(self, creator_id: int, history_comment: str | None = None) -> int:
|
53
41
|
instance = self._model.objects.get(pk=self.pk)
|
@@ -56,32 +44,68 @@ class DatabaseInterface(DBBasedInterface):
|
|
56
44
|
history_comment = f"{history_comment} (deactivated)"
|
57
45
|
else:
|
58
46
|
history_comment = "Deactivated"
|
59
|
-
return self.
|
47
|
+
return self._save_with_history(instance, creator_id, history_comment)
|
60
48
|
|
61
49
|
@staticmethod
|
62
|
-
def
|
50
|
+
def __setManyToManyAttributes(
|
51
|
+
instance: GeneralManagerModel, many_to_many_kwargs: dict[str, list[Any]]
|
52
|
+
) -> GeneralManagerModel:
|
53
|
+
"""
|
54
|
+
Sets many-to-many attributes for the given instance based on the provided kwargs.
|
55
|
+
|
56
|
+
Args:
|
57
|
+
instance: The model instance to update.
|
58
|
+
many_to_many_kwargs: A dictionary containing many-to-many field names and their corresponding values.
|
59
|
+
|
60
|
+
Returns:
|
61
|
+
The updated model instance.
|
62
|
+
"""
|
63
|
+
for key, value in many_to_many_kwargs.items():
|
64
|
+
if not value:
|
65
|
+
continue
|
66
|
+
field_name = key.split("_id_list")[0]
|
67
|
+
getattr(instance, field_name).set(value)
|
68
|
+
|
69
|
+
return instance
|
70
|
+
|
71
|
+
@staticmethod
|
72
|
+
def __setAttrForWrite(
|
73
|
+
instance: GeneralManagerModel,
|
74
|
+
kwargs: dict[str, Any],
|
75
|
+
) -> GeneralManagerModel:
|
76
|
+
from general_manager.manager.generalManager import GeneralManager
|
77
|
+
|
78
|
+
for key, value in kwargs.items():
|
79
|
+
if isinstance(value, GeneralManager):
|
80
|
+
value = value.identification["id"]
|
81
|
+
key = f"{key}_id"
|
82
|
+
setattr(instance, key, value)
|
83
|
+
return instance
|
84
|
+
|
85
|
+
@staticmethod
|
86
|
+
def _checkForInvalidKwargs(model: Type[models.Model], kwargs: dict[str, Any]):
|
63
87
|
attributes = vars(model)
|
64
|
-
|
88
|
+
field_names = {f.name for f in model._meta.get_fields()}
|
65
89
|
for key in kwargs:
|
66
|
-
|
90
|
+
temp_key = key.split("_id_list")[0] # Remove '_id_list' suffix
|
91
|
+
if temp_key not in attributes and temp_key not in field_names:
|
67
92
|
raise ValueError(f"{key} does not exsist in {model.__name__}")
|
68
93
|
|
69
94
|
@staticmethod
|
70
|
-
def
|
95
|
+
def _sortKwargs(
|
71
96
|
model: Type[models.Model], kwargs: dict[Any, Any]
|
72
97
|
) -> tuple[dict[str, Any], dict[str, list[Any]]]:
|
73
|
-
many_to_many_fields = model._meta.many_to_many
|
98
|
+
many_to_many_fields = [field.name for field in model._meta.many_to_many]
|
74
99
|
many_to_many_kwargs: dict[Any, Any] = {}
|
75
|
-
for key, value in kwargs.items():
|
100
|
+
for key, value in list(kwargs.items()):
|
76
101
|
many_to_many_key = key.split("_id_list")[0]
|
77
102
|
if many_to_many_key in many_to_many_fields:
|
78
|
-
many_to_many_kwargs[key] =
|
79
|
-
kwargs.pop(key)
|
103
|
+
many_to_many_kwargs[key] = kwargs.pop(key)
|
80
104
|
return kwargs, many_to_many_kwargs
|
81
105
|
|
82
106
|
@classmethod
|
83
107
|
@transaction.atomic
|
84
|
-
def
|
108
|
+
def _save_with_history(
|
85
109
|
cls, instance: GeneralManagerModel, creator_id: int, history_comment: str | None
|
86
110
|
) -> int:
|
87
111
|
"""
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.4
|
2
2
|
Name: GeneralManager
|
3
|
-
Version: 0.6.
|
3
|
+
Version: 0.6.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
|
@@ -27,7 +27,7 @@ general_manager/interface/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJW
|
|
27
27
|
general_manager/interface/baseInterface.py,sha256=b7MH-jVADcpGluvJMogPn2O3Yiy37uCnWOM9j0Ec0o0,8692
|
28
28
|
general_manager/interface/calculationInterface.py,sha256=Kg_OqLw67tcLwdzYNLq31eKVLzkM7taw-8Mzmk0CYi0,4232
|
29
29
|
general_manager/interface/databaseBasedInterface.py,sha256=K2PYxANuLQU8wzrajcl922tuWwko642KJAS3f3PnAmg,21566
|
30
|
-
general_manager/interface/databaseInterface.py,sha256=
|
30
|
+
general_manager/interface/databaseInterface.py,sha256=08dFgxoLQNa13RK2NQ4cDNbNPIG-X9ChLs3NvJcSp6Y,4923
|
31
31
|
general_manager/interface/readOnlyInterface.py,sha256=d2CM2gj5XZNEaVFZeNCgqZf46rwUAetVS3SyePCKNsY,4691
|
32
32
|
general_manager/manager/__init__.py,sha256=l3RYp62aEhj3Y975_XUTIzo35LUnkTJHkb_hgChnXXI,111
|
33
33
|
general_manager/manager/generalManager.py,sha256=HX69KhrnSGVkuJwHY_jzff5gS0VD-6fRxKnd59A5Ct4,6100
|
@@ -46,8 +46,8 @@ general_manager/permission/permissionDataManager.py,sha256=Ji7fsnuaKTa6M8yzCGyzr
|
|
46
46
|
general_manager/rule/__init__.py,sha256=4Har5cfPD1fmOsilTDod-ZUz3Com-tkl58jz7yY4fD0,23
|
47
47
|
general_manager/rule/handler.py,sha256=z8SFHTIZ0LbLh3fV56Mud0V4_OvWkqJjlHvFqau7Qfk,7334
|
48
48
|
general_manager/rule/rule.py,sha256=3FVCKGL7BTVoStdgOTdWQwuoVRIxAIAilV4VOzouDpc,10759
|
49
|
-
generalmanager-0.6.
|
50
|
-
generalmanager-0.6.
|
51
|
-
generalmanager-0.6.
|
52
|
-
generalmanager-0.6.
|
53
|
-
generalmanager-0.6.
|
49
|
+
generalmanager-0.6.2.dist-info/licenses/LICENSE,sha256=YGFm0ieb4KpkMRRt2qnWue6uFh0cUMtobwEBkHwajhc,1450
|
50
|
+
generalmanager-0.6.2.dist-info/METADATA,sha256=LpZhar2vKhlCPwavT15s1yWSeMCHH6M9rqtC69BjraQ,6205
|
51
|
+
generalmanager-0.6.2.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
52
|
+
generalmanager-0.6.2.dist-info/top_level.txt,sha256=sTDtExP9ga-YP3h3h42yivUY-A2Q23C2nw6LNKOho4I,16
|
53
|
+
generalmanager-0.6.2.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|