2021-01-13 09:49:03 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
#
|
2022-06-23 05:52:28 +00:00
|
|
|
from django.db.models.signals import post_save, m2m_changed
|
|
|
|
|
2023-02-08 02:14:09 +00:00
|
|
|
from common.decorators import on_transaction_commit
|
2021-01-13 09:49:03 +00:00
|
|
|
from common.utils import get_logger
|
2022-01-10 12:14:13 +00:00
|
|
|
from tickets.models import Ticket
|
2021-01-13 09:49:03 +00:00
|
|
|
|
|
|
|
logger = get_logger(__name__)
|
|
|
|
|
|
|
|
|
2022-06-23 05:52:28 +00:00
|
|
|
@on_transaction_commit
|
|
|
|
def after_save_set_rel_snapshot(sender, instance, update_fields=None, **kwargs):
|
|
|
|
if update_fields and list(update_fields)[0] == 'rel_snapshot':
|
|
|
|
return
|
|
|
|
instance.set_rel_snapshot()
|
|
|
|
|
|
|
|
|
|
|
|
@on_transaction_commit
|
|
|
|
def on_m2m_change(sender, action, instance, reverse=False, **kwargs):
|
|
|
|
if action.startswith('post'):
|
|
|
|
instance.set_rel_snapshot()
|
2022-01-10 12:14:13 +00:00
|
|
|
|
|
|
|
|
2022-06-23 05:52:28 +00:00
|
|
|
for ticket_cls in Ticket.__subclasses__():
|
|
|
|
post_save.connect(after_save_set_rel_snapshot, sender=ticket_cls)
|
|
|
|
m2m_changed.connect(on_m2m_change, sender=ticket_cls)
|