django-bulk-hooks 0.1.176__tar.gz → 0.1.177__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.176 → django_bulk_hooks-0.1.177}/PKG-INFO +1 -1
- django_bulk_hooks-0.1.177/django_bulk_hooks/manager.py +99 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/queryset.py +4 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/pyproject.toml +1 -1
- django_bulk_hooks-0.1.176/django_bulk_hooks/manager.py +0 -153
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/LICENSE +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/README.md +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/__init__.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/conditions.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/constants.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/context.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/decorators.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/engine.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/enums.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/handler.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/models.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/priority.py +0 -0
- {django_bulk_hooks-0.1.176 → django_bulk_hooks-0.1.177}/django_bulk_hooks/registry.py +0 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
from django.db import models
|
|
2
|
+
|
|
3
|
+
from django_bulk_hooks.queryset import HookQuerySet
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class BulkHookManager(models.Manager):
|
|
7
|
+
def get_queryset(self):
|
|
8
|
+
queryset = HookQuerySet(self.model, using=self._db)
|
|
9
|
+
return queryset
|
|
10
|
+
|
|
11
|
+
def bulk_create(
|
|
12
|
+
self,
|
|
13
|
+
objs,
|
|
14
|
+
batch_size=None,
|
|
15
|
+
ignore_conflicts=False,
|
|
16
|
+
update_conflicts=False,
|
|
17
|
+
update_fields=None,
|
|
18
|
+
unique_fields=None,
|
|
19
|
+
bypass_hooks=False,
|
|
20
|
+
bypass_validation=False,
|
|
21
|
+
**kwargs,
|
|
22
|
+
):
|
|
23
|
+
"""
|
|
24
|
+
Delegate to QuerySet's bulk_create implementation.
|
|
25
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
26
|
+
"""
|
|
27
|
+
return self.get_queryset().bulk_create(
|
|
28
|
+
objs,
|
|
29
|
+
bypass_hooks=bypass_hooks,
|
|
30
|
+
bypass_validation=bypass_validation,
|
|
31
|
+
batch_size=batch_size,
|
|
32
|
+
ignore_conflicts=ignore_conflicts,
|
|
33
|
+
update_conflicts=update_conflicts,
|
|
34
|
+
update_fields=update_fields,
|
|
35
|
+
unique_fields=unique_fields,
|
|
36
|
+
**kwargs,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
def bulk_update(
|
|
40
|
+
self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
|
|
41
|
+
):
|
|
42
|
+
"""
|
|
43
|
+
Delegate to QuerySet's bulk_update implementation.
|
|
44
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
45
|
+
"""
|
|
46
|
+
return self.get_queryset().bulk_update(
|
|
47
|
+
objs,
|
|
48
|
+
fields,
|
|
49
|
+
bypass_hooks=bypass_hooks,
|
|
50
|
+
bypass_validation=bypass_validation,
|
|
51
|
+
**kwargs,
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
def bulk_delete(
|
|
55
|
+
self,
|
|
56
|
+
objs,
|
|
57
|
+
batch_size=None,
|
|
58
|
+
bypass_hooks=False,
|
|
59
|
+
bypass_validation=False,
|
|
60
|
+
**kwargs,
|
|
61
|
+
):
|
|
62
|
+
"""
|
|
63
|
+
Delegate to QuerySet's bulk_delete implementation.
|
|
64
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
65
|
+
"""
|
|
66
|
+
return self.get_queryset().bulk_delete(
|
|
67
|
+
objs,
|
|
68
|
+
bypass_hooks=bypass_hooks,
|
|
69
|
+
bypass_validation=bypass_validation,
|
|
70
|
+
batch_size=batch_size,
|
|
71
|
+
**kwargs,
|
|
72
|
+
)
|
|
73
|
+
|
|
74
|
+
def delete(self):
|
|
75
|
+
"""
|
|
76
|
+
Delegate to QuerySet's delete implementation.
|
|
77
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
78
|
+
"""
|
|
79
|
+
return self.get_queryset().delete()
|
|
80
|
+
|
|
81
|
+
def update(self, **kwargs):
|
|
82
|
+
"""
|
|
83
|
+
Delegate to QuerySet's update implementation.
|
|
84
|
+
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
85
|
+
"""
|
|
86
|
+
return self.get_queryset().update(**kwargs)
|
|
87
|
+
|
|
88
|
+
def save(self, obj):
|
|
89
|
+
"""
|
|
90
|
+
Save a single object using the appropriate bulk operation.
|
|
91
|
+
"""
|
|
92
|
+
if obj.pk:
|
|
93
|
+
self.bulk_update(
|
|
94
|
+
[obj],
|
|
95
|
+
fields=[field.name for field in obj._meta.fields if field.name != "id"],
|
|
96
|
+
)
|
|
97
|
+
else:
|
|
98
|
+
self.bulk_create([obj])
|
|
99
|
+
return obj
|
|
@@ -302,6 +302,10 @@ class HookQuerySet(models.QuerySet):
|
|
|
302
302
|
if inheritance_chain is None:
|
|
303
303
|
inheritance_chain = self._get_inheritance_chain()
|
|
304
304
|
|
|
305
|
+
for inheritance in inheritance_chain:
|
|
306
|
+
print(inheritance)
|
|
307
|
+
|
|
308
|
+
|
|
305
309
|
# Safety check to prevent infinite recursion
|
|
306
310
|
if len(inheritance_chain) > 10: # Arbitrary limit to prevent infinite loops
|
|
307
311
|
raise ValueError(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[tool.poetry]
|
|
2
2
|
name = "django-bulk-hooks"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.177"
|
|
4
4
|
description = "Hook-style hooks for Django bulk operations like bulk_create and bulk_update."
|
|
5
5
|
authors = ["Konrad Beck <konrad.beck@merchantcapital.co.za>"]
|
|
6
6
|
readme = "README.md"
|
|
@@ -1,153 +0,0 @@
|
|
|
1
|
-
from django.db import models
|
|
2
|
-
|
|
3
|
-
from django_bulk_hooks.queryset import HookQuerySet
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class BulkHookManager(models.Manager):
|
|
7
|
-
def get_queryset(self):
|
|
8
|
-
qs = HookQuerySet(self.model, using=self._db)
|
|
9
|
-
return qs
|
|
10
|
-
|
|
11
|
-
def bulk_update(
|
|
12
|
-
self, objs, fields, bypass_hooks=False, bypass_validation=False, **kwargs
|
|
13
|
-
):
|
|
14
|
-
"""
|
|
15
|
-
Delegate to QuerySet's bulk_update implementation.
|
|
16
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
17
|
-
"""
|
|
18
|
-
import inspect
|
|
19
|
-
|
|
20
|
-
qs = self.get_queryset()
|
|
21
|
-
|
|
22
|
-
# Check if this is our HookQuerySet or a different QuerySet
|
|
23
|
-
if (
|
|
24
|
-
hasattr(qs, "bulk_update")
|
|
25
|
-
and "bypass_hooks" in inspect.signature(qs.bulk_update).parameters
|
|
26
|
-
):
|
|
27
|
-
# Our HookQuerySet - pass all parameters
|
|
28
|
-
return qs.bulk_update(
|
|
29
|
-
objs,
|
|
30
|
-
fields,
|
|
31
|
-
bypass_hooks=bypass_hooks,
|
|
32
|
-
bypass_validation=bypass_validation,
|
|
33
|
-
**kwargs,
|
|
34
|
-
)
|
|
35
|
-
else:
|
|
36
|
-
# Different QuerySet (like queryable_properties) - only pass standard parameters
|
|
37
|
-
django_kwargs = {
|
|
38
|
-
k: v
|
|
39
|
-
for k, v in kwargs.items()
|
|
40
|
-
if k not in ["bypass_hooks", "bypass_validation"]
|
|
41
|
-
}
|
|
42
|
-
return qs.bulk_update(objs, fields, **django_kwargs)
|
|
43
|
-
|
|
44
|
-
def bulk_create(
|
|
45
|
-
self,
|
|
46
|
-
objs,
|
|
47
|
-
batch_size=None,
|
|
48
|
-
ignore_conflicts=False,
|
|
49
|
-
update_conflicts=False,
|
|
50
|
-
update_fields=None,
|
|
51
|
-
unique_fields=None,
|
|
52
|
-
bypass_hooks=False,
|
|
53
|
-
bypass_validation=False,
|
|
54
|
-
):
|
|
55
|
-
"""
|
|
56
|
-
Delegate to QuerySet's bulk_create implementation.
|
|
57
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
58
|
-
"""
|
|
59
|
-
import inspect
|
|
60
|
-
|
|
61
|
-
queryset = self.get_queryset()
|
|
62
|
-
|
|
63
|
-
# Check if this is our HookQuerySet or a different QuerySet
|
|
64
|
-
if (
|
|
65
|
-
hasattr(queryset, "bulk_create")
|
|
66
|
-
and "bypass_hooks" in inspect.signature(queryset.bulk_create).parameters
|
|
67
|
-
):
|
|
68
|
-
# Our HookQuerySet - pass all parameters
|
|
69
|
-
kwargs = {
|
|
70
|
-
"batch_size": batch_size,
|
|
71
|
-
"ignore_conflicts": ignore_conflicts,
|
|
72
|
-
"update_conflicts": update_conflicts,
|
|
73
|
-
"update_fields": update_fields,
|
|
74
|
-
"unique_fields": unique_fields,
|
|
75
|
-
}
|
|
76
|
-
return queryset.bulk_create(
|
|
77
|
-
objs,
|
|
78
|
-
bypass_hooks=bypass_hooks,
|
|
79
|
-
bypass_validation=bypass_validation,
|
|
80
|
-
**kwargs,
|
|
81
|
-
)
|
|
82
|
-
else:
|
|
83
|
-
print("Different QuerySet")
|
|
84
|
-
|
|
85
|
-
# Different QuerySet - only pass standard parameters
|
|
86
|
-
kwargs = {
|
|
87
|
-
"batch_size": batch_size,
|
|
88
|
-
"ignore_conflicts": ignore_conflicts,
|
|
89
|
-
"update_conflicts": update_conflicts,
|
|
90
|
-
"update_fields": update_fields,
|
|
91
|
-
"unique_fields": unique_fields,
|
|
92
|
-
}
|
|
93
|
-
return queryset.bulk_create(objs, **kwargs)
|
|
94
|
-
|
|
95
|
-
def bulk_delete(
|
|
96
|
-
self, objs, batch_size=None, bypass_hooks=False, bypass_validation=False
|
|
97
|
-
):
|
|
98
|
-
"""
|
|
99
|
-
Delegate to QuerySet's bulk_delete implementation.
|
|
100
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
101
|
-
"""
|
|
102
|
-
import inspect
|
|
103
|
-
|
|
104
|
-
qs = self.get_queryset()
|
|
105
|
-
|
|
106
|
-
# Check if this is our HookQuerySet or a different QuerySet
|
|
107
|
-
if (
|
|
108
|
-
hasattr(qs, "bulk_delete")
|
|
109
|
-
and "bypass_hooks" in inspect.signature(qs.bulk_delete).parameters
|
|
110
|
-
):
|
|
111
|
-
# Our HookQuerySet - pass all parameters
|
|
112
|
-
kwargs = {
|
|
113
|
-
"batch_size": batch_size,
|
|
114
|
-
}
|
|
115
|
-
return qs.bulk_delete(
|
|
116
|
-
objs,
|
|
117
|
-
bypass_hooks=bypass_hooks,
|
|
118
|
-
bypass_validation=bypass_validation,
|
|
119
|
-
**kwargs,
|
|
120
|
-
)
|
|
121
|
-
else:
|
|
122
|
-
# Different QuerySet - only pass standard parameters
|
|
123
|
-
kwargs = {
|
|
124
|
-
"batch_size": batch_size,
|
|
125
|
-
}
|
|
126
|
-
return qs.bulk_delete(objs, **kwargs)
|
|
127
|
-
|
|
128
|
-
def update(self, **kwargs):
|
|
129
|
-
"""
|
|
130
|
-
Delegate to QuerySet's update implementation.
|
|
131
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
132
|
-
"""
|
|
133
|
-
return self.get_queryset().update(**kwargs)
|
|
134
|
-
|
|
135
|
-
def delete(self):
|
|
136
|
-
"""
|
|
137
|
-
Delegate to QuerySet's delete implementation.
|
|
138
|
-
This follows Django's pattern where Manager methods call QuerySet methods.
|
|
139
|
-
"""
|
|
140
|
-
return self.get_queryset().delete()
|
|
141
|
-
|
|
142
|
-
def save(self, obj):
|
|
143
|
-
"""
|
|
144
|
-
Save a single object using the appropriate bulk operation.
|
|
145
|
-
"""
|
|
146
|
-
if obj.pk:
|
|
147
|
-
self.bulk_update(
|
|
148
|
-
[obj],
|
|
149
|
-
fields=[field.name for field in obj._meta.fields if field.name != "id"],
|
|
150
|
-
)
|
|
151
|
-
else:
|
|
152
|
-
self.bulk_create([obj])
|
|
153
|
-
return obj
|
|
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
|