-
-
Notifications
You must be signed in to change notification settings - Fork 128
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove attachment files from storage on Instance objects deletion
- Loading branch information
1 parent
a6a49d4
commit 127a84b
Showing
5 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,13 @@ | ||
# coding: utf-8 | ||
from django.apps import AppConfig | ||
|
||
|
||
class LoggerAppConfig(AppConfig): | ||
|
||
name = 'onadata.apps.logger' | ||
|
||
def ready(self): | ||
# Makes sure all signal handlers are connected | ||
# Uncomment the lines below if you need signals | ||
from onadata.apps.logger import signals | ||
super().ready() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# coding: utf-8 | ||
import logging | ||
from django.db.models.signals import pre_delete | ||
from django.dispatch import receiver | ||
|
||
from onadata.apps.logger.models.attachment import Attachment | ||
|
||
|
||
@receiver(pre_delete, sender=Attachment) | ||
def post_delete_asset(instance, **kwargs): | ||
# Unfortunately, it seems that Django does not call Model.delete() on | ||
# delete CASCADE. But this signal is called though. | ||
# We want to delete all files when an Instance (or Attachment) object is | ||
# deleted. | ||
try: | ||
instance.media_file.delete() | ||
except Exception as e: | ||
logger = logging.getLogger('console_logger') | ||
logger.error(str(e), exc_info=True) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters