django-bulk-hooks 0.1.68__tar.gz → 0.1.69__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.68 → django_bulk_hooks-0.1.69}/PKG-INFO +4 -4
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/README.md +3 -3
- django_bulk_hooks-0.1.69/django_bulk_hooks/__init__.py +4 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/constants.py +0 -2
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/handler.py +5 -5
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/pyproject.toml +1 -1
- django_bulk_hooks-0.1.68/django_bulk_hooks/__init__.py +0 -4
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/LICENSE +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/engine.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/manager.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/queryset.py +0 -0
- {django_bulk_hooks-0.1.68 → django_bulk_hooks-0.1.69}/django_bulk_hooks/registry.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: django-bulk-hooks
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.69
|
|
4
4
|
Summary: Hook-style hooks for Django bulk operations like bulk_create and bulk_update.
|
|
5
5
|
Home-page: https://github.com/AugendLimited/django-bulk-hooks
|
|
6
6
|
License: MIT
|
|
@@ -54,11 +54,11 @@ class Account(HookModelMixin):
|
|
|
54
54
|
### Create a Hook Handler
|
|
55
55
|
|
|
56
56
|
```python
|
|
57
|
-
from django_bulk_hooks import hook, AFTER_UPDATE,
|
|
57
|
+
from django_bulk_hooks import hook, AFTER_UPDATE, Hook
|
|
58
58
|
from django_bulk_hooks.conditions import WhenFieldHasChanged
|
|
59
59
|
from .models import Account
|
|
60
60
|
|
|
61
|
-
class
|
|
61
|
+
class AccountHooks(Hook):
|
|
62
62
|
@hook(AFTER_UPDATE, model=Account, condition=WhenFieldHasChanged("balance"))
|
|
63
63
|
def log_balance_change(self, new_records, old_records):
|
|
64
64
|
print("Accounts updated:", [a.pk for a in new_records])
|
|
@@ -166,7 +166,7 @@ Account.objects.bulk_delete(accounts)
|
|
|
166
166
|
### Advanced Hook Usage
|
|
167
167
|
|
|
168
168
|
```python
|
|
169
|
-
class
|
|
169
|
+
class AdvancedAccountHooks(Hook):
|
|
170
170
|
@hook(BEFORE_UPDATE, model=Account, condition=WhenFieldHasChanged("balance"))
|
|
171
171
|
def validate_balance_change(self, new_records, old_records):
|
|
172
172
|
for new_account, old_account in zip(new_records, old_records):
|
|
@@ -35,11 +35,11 @@ class Account(HookModelMixin):
|
|
|
35
35
|
### Create a Hook Handler
|
|
36
36
|
|
|
37
37
|
```python
|
|
38
|
-
from django_bulk_hooks import hook, AFTER_UPDATE,
|
|
38
|
+
from django_bulk_hooks import hook, AFTER_UPDATE, Hook
|
|
39
39
|
from django_bulk_hooks.conditions import WhenFieldHasChanged
|
|
40
40
|
from .models import Account
|
|
41
41
|
|
|
42
|
-
class
|
|
42
|
+
class AccountHooks(Hook):
|
|
43
43
|
@hook(AFTER_UPDATE, model=Account, condition=WhenFieldHasChanged("balance"))
|
|
44
44
|
def log_balance_change(self, new_records, old_records):
|
|
45
45
|
print("Accounts updated:", [a.pk for a in new_records])
|
|
@@ -147,7 +147,7 @@ Account.objects.bulk_delete(accounts)
|
|
|
147
147
|
### Advanced Hook Usage
|
|
148
148
|
|
|
149
149
|
```python
|
|
150
|
-
class
|
|
150
|
+
class AdvancedAccountHooks(Hook):
|
|
151
151
|
@hook(BEFORE_UPDATE, model=Account, condition=WhenFieldHasChanged("balance"))
|
|
152
152
|
def validate_balance_change(self, new_records, old_records):
|
|
153
153
|
for new_account, old_account in zip(new_records, old_records):
|
|
@@ -4,8 +4,6 @@ BEFORE_UPDATE = "before_update"
|
|
|
4
4
|
AFTER_UPDATE = "after_update"
|
|
5
5
|
BEFORE_DELETE = "before_delete"
|
|
6
6
|
AFTER_DELETE = "after_delete"
|
|
7
|
-
|
|
8
|
-
# Validation constants - run during clean() for admin/form validation
|
|
9
7
|
VALIDATE_CREATE = "validate_create"
|
|
10
8
|
VALIDATE_UPDATE = "validate_update"
|
|
11
9
|
VALIDATE_DELETE = "validate_delete"
|
|
@@ -64,7 +64,7 @@ class HookContextState:
|
|
|
64
64
|
Hook = HookContextState()
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
class
|
|
67
|
+
class HookMeta(type):
|
|
68
68
|
_registered = set()
|
|
69
69
|
|
|
70
70
|
def __new__(mcs, name, bases, namespace):
|
|
@@ -73,9 +73,9 @@ class HookHandlerMeta(type):
|
|
|
73
73
|
if hasattr(method, "hooks_hooks"):
|
|
74
74
|
for model_cls, event, condition, priority in method.hooks_hooks:
|
|
75
75
|
key = (model_cls, event, cls, method_name)
|
|
76
|
-
if key not in
|
|
76
|
+
if key not in HookMeta._registered:
|
|
77
77
|
logger.info(
|
|
78
|
-
"Registering hook via
|
|
78
|
+
"Registering hook via HookMeta: model=%s, event=%s, handler_cls=%s, method_name=%s",
|
|
79
79
|
model_cls.__name__,
|
|
80
80
|
event,
|
|
81
81
|
cls.__name__,
|
|
@@ -89,11 +89,11 @@ class HookHandlerMeta(type):
|
|
|
89
89
|
condition=condition,
|
|
90
90
|
priority=priority,
|
|
91
91
|
)
|
|
92
|
-
|
|
92
|
+
HookMeta._registered.add(key)
|
|
93
93
|
return cls
|
|
94
94
|
|
|
95
95
|
|
|
96
|
-
class
|
|
96
|
+
class Hook(metaclass=HookMeta):
|
|
97
97
|
@classmethod
|
|
98
98
|
def handle(
|
|
99
99
|
cls,
|
|
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
|