Browse Source

Armadilha para descobrir deleção de registros

pull/169/head 3.0.68
Sesóstris Vieira 1 year ago
parent
commit
ab2580311a
  1. 5
      sigi/apps/espacos/apps.py
  2. 22
      sigi/apps/espacos/signals.py

5
sigi/apps/espacos/apps.py

@ -7,3 +7,8 @@ class EspacosConfig(AppConfig):
name = "espacos" name = "espacos"
name = "sigi.apps.espacos" name = "sigi.apps.espacos"
verbose_name = _("Agenda de espaços") verbose_name = _("Agenda de espaços")
def ready(self):
from . import signals
return super().ready()

22
sigi/apps/espacos/signals.py

@ -0,0 +1,22 @@
import traceback
from django.conf import settings
from django.core.mail import send_mail
from django.db.models.signals import pre_delete
from django.dispatch import receiver
from django.utils import timezone
from sigi.apps.espacos.models import Reserva
@receiver(pre_delete, sender=Reserva)
def reserva_pre_delete(sender, **kwargs):
origin = kwargs.get("origin", None)
if origin and origin.count() == Reserva.objects.count():
stack_array = [f"At {timezone.localtime()} all records deleted:"]
stack_array.extend(traceback.format_stack())
send_mail(
subject="Armadilha deleção de reservas",
message="\n".join(stack_array),
from_email=settings.DEFAULT_FROM_EMAIL,
recipient_list=[email for name, email in settings.ADMINS],
fail_silently=True,
)
Loading…
Cancel
Save