Browse Source

Corrige bug das reservas desaparecidas. Remove armadilha

pull/169/head 3.0.69
Sesóstris Vieira 11 months ago
parent
commit
095a801062
  1. 5
      sigi/apps/espacos/apps.py
  2. 22
      sigi/apps/espacos/signals.py
  3. 2
      sigi/apps/eventos/models.py

5
sigi/apps/espacos/apps.py

@ -7,8 +7,3 @@ 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

@ -1,22 +0,0 @@
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,
)

2
sigi/apps/eventos/models.py

@ -698,13 +698,13 @@ class Evento(models.Model):
self.turma = f"{proximo:02}/{ano:04}" self.turma = f"{proximo:02}/{ano:04}"
# É preciso salvar para poder usar o relacionamento com convites # É preciso salvar para poder usar o relacionamento com convites
super().save(*args, **kwargs)
if self.reserva is None: if self.reserva is None:
reservas_remover = list(Reserva.objects.filter(evento=self)) reservas_remover = list(Reserva.objects.filter(evento=self))
else: else:
self.update_reserva() self.update_reserva()
self.reserva.save() self.reserva.save()
reservas_remover = Reserva.objects.none() reservas_remover = Reserva.objects.none()
super().save(*args, **kwargs)
for reserva in reservas_remover: for reserva in reservas_remover:
reserva.delete() reserva.delete()

Loading…
Cancel
Save