django-bulk-hooks 0.1.71__tar.gz → 0.1.72__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.
Potentially problematic release.
This version of django-bulk-hooks might be problematic. Click here for more details.
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/PKG-INFO +3 -3
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/manager.py +28 -9
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/pyproject.toml +1 -1
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/LICENSE +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/README.md +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/__init__.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/constants.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/engine.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/handler.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/queryset.py +0 -0
- {django_bulk_hooks-0.1.71 → django_bulk_hooks-0.1.72}/django_bulk_hooks/registry.py +0 -0
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
2
|
Name: django-bulk-hooks
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.72
|
|
4
4
|
Summary: Hook-style hooks for Django bulk operations like bulk_create and bulk_update.
|
|
5
|
+
Home-page: https://github.com/AugendLimited/django-bulk-hooks
|
|
5
6
|
License: MIT
|
|
6
7
|
Keywords: django,bulk,hooks
|
|
7
8
|
Author: Konrad Beck
|
|
@@ -13,7 +14,6 @@ Classifier: Programming Language :: Python :: 3.11
|
|
|
13
14
|
Classifier: Programming Language :: Python :: 3.12
|
|
14
15
|
Classifier: Programming Language :: Python :: 3.13
|
|
15
16
|
Requires-Dist: Django (>=4.0)
|
|
16
|
-
Project-URL: Homepage, https://github.com/AugendLimited/django-bulk-hooks
|
|
17
17
|
Project-URL: Repository, https://github.com/AugendLimited/django-bulk-hooks
|
|
18
18
|
Description-Content-Type: text/markdown
|
|
19
19
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
from django.db import models, transaction
|
|
2
|
+
|
|
2
3
|
from django_bulk_hooks import engine
|
|
3
4
|
from django_bulk_hooks.constants import (
|
|
4
5
|
AFTER_CREATE,
|
|
@@ -8,8 +9,8 @@ from django_bulk_hooks.constants import (
|
|
|
8
9
|
BEFORE_DELETE,
|
|
9
10
|
BEFORE_UPDATE,
|
|
10
11
|
VALIDATE_CREATE,
|
|
11
|
-
VALIDATE_UPDATE,
|
|
12
12
|
VALIDATE_DELETE,
|
|
13
|
+
VALIDATE_UPDATE,
|
|
13
14
|
)
|
|
14
15
|
from django_bulk_hooks.context import HookContext
|
|
15
16
|
from django_bulk_hooks.queryset import HookQuerySet
|
|
@@ -22,7 +23,9 @@ class BulkHookManager(models.Manager):
|
|
|
22
23
|
return HookQuerySet(self.model, using=self._db)
|
|
23
24
|
|
|
24
25
|
@transaction.atomic
|
|
25
|
-
def bulk_update(
|
|
26
|
+
def bulk_update(
|
|
27
|
+
self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
|
|
28
|
+
):
|
|
26
29
|
if not objs:
|
|
27
30
|
return []
|
|
28
31
|
|
|
@@ -34,13 +37,27 @@ class BulkHookManager(models.Manager):
|
|
|
34
37
|
)
|
|
35
38
|
|
|
36
39
|
if not bypass_hooks:
|
|
37
|
-
|
|
40
|
+
# Check if we're already in a hook context (recursive call)
|
|
41
|
+
# If so, refetch the current database state like Salesforce does
|
|
42
|
+
import threading
|
|
43
|
+
|
|
44
|
+
if hasattr(threading.current_thread(), "_hook_context"):
|
|
45
|
+
# We're in a recursive call - refetch current DB state
|
|
46
|
+
originals = list(
|
|
47
|
+
model_cls.objects.filter(pk__in=[obj.pk for obj in objs])
|
|
48
|
+
)
|
|
49
|
+
else:
|
|
50
|
+
# First call - use the passed originals
|
|
51
|
+
originals = list(
|
|
52
|
+
model_cls.objects.filter(pk__in=[obj.pk for obj in objs])
|
|
53
|
+
)
|
|
54
|
+
|
|
38
55
|
ctx = HookContext(model_cls)
|
|
39
|
-
|
|
56
|
+
|
|
40
57
|
# Run validation hooks first
|
|
41
58
|
if not bypass_validation:
|
|
42
59
|
engine.run(model_cls, VALIDATE_UPDATE, objs, originals, ctx=ctx)
|
|
43
|
-
|
|
60
|
+
|
|
44
61
|
# Then run business logic hooks
|
|
45
62
|
engine.run(model_cls, BEFORE_UPDATE, objs, originals, ctx=ctx)
|
|
46
63
|
|
|
@@ -118,11 +135,11 @@ class BulkHookManager(models.Manager):
|
|
|
118
135
|
|
|
119
136
|
if not bypass_hooks:
|
|
120
137
|
ctx = HookContext(model_cls)
|
|
121
|
-
|
|
138
|
+
|
|
122
139
|
# Run validation hooks first
|
|
123
140
|
if not bypass_validation:
|
|
124
141
|
engine.run(model_cls, VALIDATE_CREATE, objs, ctx=ctx)
|
|
125
|
-
|
|
142
|
+
|
|
126
143
|
# Then run business logic hooks
|
|
127
144
|
engine.run(model_cls, BEFORE_CREATE, objs, ctx=ctx)
|
|
128
145
|
|
|
@@ -136,7 +153,9 @@ class BulkHookManager(models.Manager):
|
|
|
136
153
|
return result
|
|
137
154
|
|
|
138
155
|
@transaction.atomic
|
|
139
|
-
def bulk_delete(
|
|
156
|
+
def bulk_delete(
|
|
157
|
+
self, objs, batch_size=None, bypass_hooks=False, bypass_validation=False
|
|
158
|
+
):
|
|
140
159
|
if not objs:
|
|
141
160
|
return []
|
|
142
161
|
|
|
@@ -153,7 +172,7 @@ class BulkHookManager(models.Manager):
|
|
|
153
172
|
# Run validation hooks first
|
|
154
173
|
if not bypass_validation:
|
|
155
174
|
engine.run(model_cls, VALIDATE_DELETE, objs, ctx=ctx)
|
|
156
|
-
|
|
175
|
+
|
|
157
176
|
# Then run business logic hooks
|
|
158
177
|
engine.run(model_cls, BEFORE_DELETE, objs, ctx=ctx)
|
|
159
178
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|