From 03608edfae773ee2cc07cd84593a5b611ab2f363 Mon Sep 17 00:00:00 2001 From: Etzelia Date: Sat, 17 Jul 2021 01:55:45 +0000 Subject: [PATCH] Fix receiver for pre_delete (#12) Fix receiver for pre_delete Signed-off-by: Etzelia Reviewed-on: https://git.canopymc.net/Canopy/minecraft_manager/pulls/12 Co-Authored-By: Etzelia Co-Committed-By: Etzelia --- apps.py | 5 ----- models.py | 24 ++++++++++++++++++------ signals/__init__.py | 0 signals/pre_delete.py | 2 -- 4 files changed, 18 insertions(+), 13 deletions(-) delete mode 100644 signals/__init__.py delete mode 100644 signals/pre_delete.py diff --git a/apps.py b/apps.py index a5fc31c..cc3695e 100644 --- a/apps.py +++ b/apps.py @@ -1,12 +1,7 @@ from django.apps import AppConfig -from django.db.models.signals import pre_delete -from minecraft_manager.signals.pre_delete import attachment_delete class MinecraftManagerAppConfig(AppConfig): name = 'minecraft_manager' verbose_name = "Minecraft Manager" - def ready(self): - pre_delete.connect(attachment_delete) - diff --git a/models.py b/models.py index c447198..c3246ad 100644 --- a/models.py +++ b/models.py @@ -1,10 +1,17 @@ -from django.db import models -from django.contrib.auth.models import User -from django.db.models import Q -from os.path import basename -import logging, yaml, pytz, json, os -from django.conf import settings +import json +import logging +import os +import pytz +import yaml from datetime import datetime +from os.path import basename + +from django.conf import settings +from django.contrib.auth.models import User +from django.db import models +from django.db.models import Q +from django.db.models.signals import pre_delete +from django.dispatch import receiver logger = logging.getLogger(__name__) @@ -376,6 +383,11 @@ class Attachment(models.Model): return self.file.name +@receiver(pre_delete, sender=Attachment, dispatch_uid="delete_attachments") +def attachment_delete(sender, instance, **kwargs): + instance.file.delete(False) + + class IPManager(models.Manager): def get_queryset(self): users = User.objects.filter(is_active=True) diff --git a/signals/__init__.py b/signals/__init__.py deleted file mode 100644 index e69de29..0000000 diff --git a/signals/pre_delete.py b/signals/pre_delete.py deleted file mode 100644 index cb46ea4..0000000 --- a/signals/pre_delete.py +++ /dev/null @@ -1,2 +0,0 @@ -def attachment_delete(sender, instance, **kwargs): - instance.file.delete(False)