django-bulk-hooks 0.1.77__py3-none-any.whl → 0.1.78__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.
Potentially problematic release.
This version of django-bulk-hooks might be problematic. Click here for more details.
- django_bulk_hooks/__init__.py +29 -3
- django_bulk_hooks/decorators.py +8 -12
- {django_bulk_hooks-0.1.77.dist-info → django_bulk_hooks-0.1.78.dist-info}/METADATA +1 -1
- {django_bulk_hooks-0.1.77.dist-info → django_bulk_hooks-0.1.78.dist-info}/RECORD +6 -6
- {django_bulk_hooks-0.1.77.dist-info → django_bulk_hooks-0.1.78.dist-info}/LICENSE +0 -0
- {django_bulk_hooks-0.1.77.dist-info → django_bulk_hooks-0.1.78.dist-info}/WHEEL +0 -0
django_bulk_hooks/__init__.py
CHANGED
|
@@ -1,4 +1,30 @@
|
|
|
1
|
-
from django_bulk_hooks.
|
|
2
|
-
|
|
1
|
+
from django_bulk_hooks.constants import (
|
|
2
|
+
AFTER_CREATE,
|
|
3
|
+
AFTER_DELETE,
|
|
4
|
+
AFTER_UPDATE,
|
|
5
|
+
BEFORE_CREATE,
|
|
6
|
+
BEFORE_DELETE,
|
|
7
|
+
BEFORE_UPDATE,
|
|
8
|
+
VALIDATE_CREATE,
|
|
9
|
+
VALIDATE_DELETE,
|
|
10
|
+
VALIDATE_UPDATE,
|
|
11
|
+
)
|
|
12
|
+
from django_bulk_hooks.engine import safe_get_related_object, safe_get_related_attr
|
|
13
|
+
from django_bulk_hooks.handler import HookHandler
|
|
14
|
+
from django_bulk_hooks.models import HookModelMixin
|
|
3
15
|
|
|
4
|
-
__all__ = [
|
|
16
|
+
__all__ = [
|
|
17
|
+
"HookHandler",
|
|
18
|
+
"HookModelMixin",
|
|
19
|
+
"BEFORE_CREATE",
|
|
20
|
+
"AFTER_CREATE",
|
|
21
|
+
"BEFORE_UPDATE",
|
|
22
|
+
"AFTER_UPDATE",
|
|
23
|
+
"BEFORE_DELETE",
|
|
24
|
+
"AFTER_DELETE",
|
|
25
|
+
"VALIDATE_CREATE",
|
|
26
|
+
"VALIDATE_UPDATE",
|
|
27
|
+
"VALIDATE_DELETE",
|
|
28
|
+
"safe_get_related_object",
|
|
29
|
+
"safe_get_related_attr",
|
|
30
|
+
]
|
django_bulk_hooks/decorators.py
CHANGED
|
@@ -4,6 +4,7 @@ from functools import wraps
|
|
|
4
4
|
from django.core.exceptions import FieldDoesNotExist
|
|
5
5
|
from django_bulk_hooks.enums import DEFAULT_PRIORITY
|
|
6
6
|
from django_bulk_hooks.registry import register_hook
|
|
7
|
+
from django_bulk_hooks.engine import safe_get_related_object
|
|
7
8
|
|
|
8
9
|
|
|
9
10
|
def hook(event, *, model, condition=None, priority=DEFAULT_PRIORITY):
|
|
@@ -133,18 +134,13 @@ def select_related(*related_fields):
|
|
|
133
134
|
# Check if the foreign key field is set
|
|
134
135
|
fk_field_name = f"{field}_id"
|
|
135
136
|
if hasattr(obj, fk_field_name) and getattr(obj, fk_field_name) is not None:
|
|
136
|
-
# The foreign key ID is set, so we can try to get the related object
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
obj._state.fields_cache[field] = rel_obj
|
|
144
|
-
except Exception:
|
|
145
|
-
# If we can't get the related object, that's okay
|
|
146
|
-
# The foreign key ID is set, so the relationship exists
|
|
147
|
-
pass
|
|
137
|
+
# The foreign key ID is set, so we can try to get the related object safely
|
|
138
|
+
rel_obj = safe_get_related_object(obj, field)
|
|
139
|
+
if rel_obj is not None:
|
|
140
|
+
# Ensure it's cached to prevent future queries
|
|
141
|
+
if not hasattr(obj._state, 'fields_cache'):
|
|
142
|
+
obj._state.fields_cache = {}
|
|
143
|
+
obj._state.fields_cache[field] = rel_obj
|
|
148
144
|
|
|
149
145
|
return func(*bound.args, **bound.kwargs)
|
|
150
146
|
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
django_bulk_hooks/__init__.py,sha256=
|
|
1
|
+
django_bulk_hooks/__init__.py,sha256=_Hu0OVtOtAMV4SJXAf60WanGDGNSmx4iekVFEnbiP7o,742
|
|
2
2
|
django_bulk_hooks/conditions.py,sha256=yPrWj1nA1ptpQFG5zhHmRwt4rswhnkKSWM4ZyicDF58,7094
|
|
3
3
|
django_bulk_hooks/constants.py,sha256=3x1H1fSUUNo0DZONN7GUVDuySZctTR-jtByBHmAIX5w,303
|
|
4
4
|
django_bulk_hooks/context.py,sha256=HVDT73uSzvgrOR6mdXTvsBm3hLOgBU8ant_mB7VlFuM,380
|
|
5
|
-
django_bulk_hooks/decorators.py,sha256=
|
|
5
|
+
django_bulk_hooks/decorators.py,sha256=zstmb27dKcOHu3Atg7cauewCTzPvUmq03mzVKJRi56o,7230
|
|
6
6
|
django_bulk_hooks/engine.py,sha256=5zj7R2Pot6T17RCq9BZ8ajc7vgRJJYAUODA3qzwSAe0,3162
|
|
7
7
|
django_bulk_hooks/enums.py,sha256=Zo8_tJzuzZ2IKfVc7gZ-0tWPT8q1QhqZbAyoh9ZVJbs,381
|
|
8
8
|
django_bulk_hooks/handler.py,sha256=xZt8iNdYF-ACz-MnKMY0co6scWINU5V5wC1lyDn844k,4854
|
|
@@ -11,7 +11,7 @@ django_bulk_hooks/models.py,sha256=7RG7GrOdHXFjGVPV4FPRZVNMIHHW-hMCi6hn9LH_hVI,3
|
|
|
11
11
|
django_bulk_hooks/priority.py,sha256=HG_2D35nga68lBCZmSXTcplXrjFoRgZFRDOy4ROKonY,376
|
|
12
12
|
django_bulk_hooks/queryset.py,sha256=7lLqhZ-XOYsZ1I3Loxi4Nhz79M8HlTYE413AW8nyeDI,1330
|
|
13
13
|
django_bulk_hooks/registry.py,sha256=-mQBizJ06nz_tajZBinViKx_uP2Tbc1tIpTEMv7lwKA,705
|
|
14
|
-
django_bulk_hooks-0.1.
|
|
15
|
-
django_bulk_hooks-0.1.
|
|
16
|
-
django_bulk_hooks-0.1.
|
|
17
|
-
django_bulk_hooks-0.1.
|
|
14
|
+
django_bulk_hooks-0.1.78.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
|
|
15
|
+
django_bulk_hooks-0.1.78.dist-info/METADATA,sha256=hS-l3fJebt6fVD4UaMpFrDzIyqKidkkoQ_8H8KlifxM,5930
|
|
16
|
+
django_bulk_hooks-0.1.78.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
|
|
17
|
+
django_bulk_hooks-0.1.78.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|