django-bulk-hooks 0.1.82__tar.gz → 0.1.84__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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.3
2
2
  Name: django-bulk-hooks
3
- Version: 0.1.82
3
+ Version: 0.1.84
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
@@ -57,32 +57,36 @@ class HookModelMixin(models.Model):
57
57
 
58
58
  def save(self, *args, **kwargs):
59
59
  is_create = self.pk is None
60
+ ctx = HookContext(self.__class__)
60
61
 
61
62
  if is_create:
62
- # For create operations, we don't have old records
63
- ctx = HookContext(self.__class__)
63
+ # For create operations, run BEFORE hooks first
64
64
  run(self.__class__, BEFORE_CREATE, [self], ctx=ctx)
65
-
65
+
66
+ # Then let Django save
66
67
  super().save(*args, **kwargs)
67
-
68
+
69
+ # Then run AFTER hooks
68
70
  run(self.__class__, AFTER_CREATE, [self], ctx=ctx)
69
71
  else:
70
72
  # For update operations, we need to get the old record
71
73
  try:
72
74
  old_instance = self.__class__.objects.get(pk=self.pk)
73
- ctx = HookContext(self.__class__)
75
+
76
+ # Run BEFORE hooks first
74
77
  run(self.__class__, BEFORE_UPDATE, [self], [old_instance], ctx=ctx)
75
-
78
+
79
+ # Then let Django save
76
80
  super().save(*args, **kwargs)
77
-
81
+
82
+ # Then run AFTER hooks
78
83
  run(self.__class__, AFTER_UPDATE, [self], [old_instance], ctx=ctx)
79
84
  except self.__class__.DoesNotExist:
80
85
  # If the old instance doesn't exist, treat as create
81
- ctx = HookContext(self.__class__)
82
86
  run(self.__class__, BEFORE_CREATE, [self], ctx=ctx)
83
-
87
+
84
88
  super().save(*args, **kwargs)
85
-
89
+
86
90
  run(self.__class__, AFTER_CREATE, [self], ctx=ctx)
87
91
 
88
92
  return self
@@ -1,6 +1,6 @@
1
1
  [tool.poetry]
2
2
  name = "django-bulk-hooks"
3
- version = "0.1.82"
3
+ version = "0.1.84"
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"