django-bulk-hooks 0.1.94__py3-none-any.whl → 0.1.96__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.

@@ -15,6 +15,7 @@ from django_bulk_hooks.conditions import (
15
15
  IsEqual,
16
16
  IsNotEqual,
17
17
  WasEqual,
18
+ IsBlank,
18
19
  safe_get_related_object,
19
20
  safe_get_related_attr,
20
21
  is_field_set,
@@ -47,4 +48,5 @@ __all__ = [
47
48
  "IsEqual",
48
49
  "IsNotEqual",
49
50
  "WasEqual",
51
+ "IsBlank",
50
52
  ]
@@ -195,13 +195,33 @@ class WasEqual(HookCondition):
195
195
 
196
196
 
197
197
  class HasChanged(HookCondition):
198
- def __init__(self, field_name):
198
+ def __init__(self, field_name, has_changed=True):
199
+ """
200
+ Check if a field's value has changed or remained the same.
201
+
202
+ Args:
203
+ field_name: The field name to check
204
+ has_changed: If True (default), condition passes when field has changed.
205
+ If False, condition passes when field has remained the same.
206
+ This is useful for:
207
+ - Detecting stable/unchanged fields
208
+ - Validating field immutability
209
+ - Ensuring critical fields remain constant
210
+ - State machine validations
211
+ """
199
212
  self.field_name = field_name
213
+ self.has_changed = has_changed
200
214
 
201
215
  def check(self, instance, original_instance=None):
202
216
  if original_instance is None:
203
- return True
204
- return getattr(instance, self.field_name, None) != getattr(original_instance, self.field_name, None)
217
+ # For new instances:
218
+ # - If we're checking for changes (has_changed=True), return True since it's a new record
219
+ # - If we're checking for stability (has_changed=False), return False since it's technically changed from nothing
220
+ return self.has_changed
221
+
222
+ current_value = getattr(instance, self.field_name, None)
223
+ original_value = getattr(original_instance, self.field_name, None)
224
+ return (current_value != original_value) == self.has_changed
205
225
 
206
226
  def get_required_fields(self):
207
227
  return {self.field_name}
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.94
3
+ Version: 0.1.96
4
4
  Summary: Hook-style hooks for Django bulk operations like bulk_create and bulk_update.
5
5
  License: MIT
6
6
  Keywords: django,bulk,hooks
@@ -1,5 +1,5 @@
1
- django_bulk_hooks/__init__.py,sha256=2PcJ6xz7t7Du0nmLO_5732G6u_oZTygogG0fKESRHHk,1082
2
- django_bulk_hooks/conditions.py,sha256=HTavJ6K6xJtk2pZS9YBcgAW495myDCNxpLo60YiXeDY,7747
1
+ django_bulk_hooks/__init__.py,sha256=4iIXH8sefZKmawDYnhNa90x3jcRA2XFs7Z2hJmas_C0,1110
2
+ django_bulk_hooks/conditions.py,sha256=CONeUfaP9p8fa4itBpPHlyed4V9-mt8oalVdugaJ2S4,8801
3
3
  django_bulk_hooks/constants.py,sha256=3x1H1fSUUNo0DZONN7GUVDuySZctTR-jtByBHmAIX5w,303
4
4
  django_bulk_hooks/context.py,sha256=HVDT73uSzvgrOR6mdXTvsBm3hLOgBU8ant_mB7VlFuM,380
5
5
  django_bulk_hooks/decorators.py,sha256=zstmb27dKcOHu3Atg7cauewCTzPvUmq03mzVKJRi56o,7230
@@ -10,7 +10,7 @@ django_bulk_hooks/manager.py,sha256=DcVosEA4RS79KSYgw3Z14_a9Sd8CfxNNc5F3eSb8xc0,
10
10
  django_bulk_hooks/models.py,sha256=a9XoGgIG4Sfi_kvGnPBbG2DlvgZDz6Qck4VG-DGqFT0,4981
11
11
  django_bulk_hooks/queryset.py,sha256=7lLqhZ-XOYsZ1I3Loxi4Nhz79M8HlTYE413AW8nyeDI,1330
12
12
  django_bulk_hooks/registry.py,sha256=Vh78exKYcdZhM27120kQm-iXGOjd_kf9ZUYBZ8eQ2V0,683
13
- django_bulk_hooks-0.1.94.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
14
- django_bulk_hooks-0.1.94.dist-info/METADATA,sha256=33bEnBka7zaJnRj3ov8NcZRU_CCTe-7GNlsDPU0Yjng,9051
15
- django_bulk_hooks-0.1.94.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
16
- django_bulk_hooks-0.1.94.dist-info/RECORD,,
13
+ django_bulk_hooks-0.1.96.dist-info/LICENSE,sha256=dguKIcbDGeZD-vXWdLyErPUALYOvtX_fO4Zjhq481uk,1088
14
+ django_bulk_hooks-0.1.96.dist-info/METADATA,sha256=v9GLOUbWn6EHccUvWtOnsILpHKKkPqykcR2L8ZPVs9s,9051
15
+ django_bulk_hooks-0.1.96.dist-info/WHEEL,sha256=b4K_helf-jlQoXBBETfwnf4B04YC67LOev0jo4fX5m8,88
16
+ django_bulk_hooks-0.1.96.dist-info/RECORD,,