Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-yin committed Jan 24, 2024
1 parent 39a8f4e commit 06fa4d2
Showing 1 changed file with 5 additions and 13 deletions.
18 changes: 5 additions & 13 deletions src/turbo_helper/signals.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
from functools import partial

from django.db import transaction
from django.db.models.signals import post_delete, post_save


def after_create_commit(sender):
def decorator(handler_func):
def wrapper(sender, instance, created, **kwargs):
if created:
transaction.on_commit(
# Call the original signal handler function
partial(handler_func, instance, created=created, **kwargs)
handler_func(
sender=sender, instance=instance, created=created, **kwargs
)

# Connect the wrapper function to the post_save signal
Expand All @@ -27,9 +23,8 @@ def after_update_commit(sender):
def decorator(handler_func):
def wrapper(sender, instance, created, **kwargs):
if not created:
transaction.on_commit(
# Call the original signal handler function
partial(handler_func, instance, created=created, **kwargs)
handler_func(
sender=sender, instance=instance, created=created, **kwargs
)

# Connect the wrapper function to the post_save signal
Expand All @@ -45,10 +40,7 @@ def wrapper(sender, instance, created, **kwargs):
def after_delete_commit(sender):
def decorator(handler_func):
def wrapper(sender, instance, **kwargs):
transaction.on_commit(
# Call the original signal handler function
partial(handler_func, instance, **kwargs)
)
handler_func(sender=sender, instance=instance, **kwargs)

# Connect the wrapper function to the post_delete signal
post_delete.connect(wrapper, sender=sender)
Expand Down

0 comments on commit 06fa4d2

Please sign in to comment.