Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/images on s3 #33

Merged
merged 20 commits into from
Oct 9, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
updated image deletion to use storages
  • Loading branch information
erik-sn committed Oct 6, 2019
commit 352306b0a40e18abaafede44da16581ec8efc1f7
6 changes: 3 additions & 3 deletions scigym/images/signals.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import os

from django.db.models.signals import pre_delete
from django.dispatch import receiver
Expand All @@ -11,6 +10,7 @@


@receiver(pre_delete, sender=Image)
def delete_file(sender, instance, **kwargs):
def delete_file(sender, instance: Image, **kwargs):
if sender == Image:
delete_image(instance.file_path)
logger.info('Deleting image: {}'.format(instance.file_path))
delete_image(instance.name)
HendrikPN marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 3 additions & 3 deletions scigym/images/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,14 @@ def save_image(uploaded_file: InMemoryUploadedFile, user) -> Image:
)


def delete_image(file_path: str) -> None:
def delete_image(name: str) -> None:
"""removes an uploaded image

Parameters
----------
file_path - file path of the uploaded file
HendrikPN marked this conversation as resolved.
Show resolved Hide resolved

"""
logger.info(f'Deleting image with path: {file_path}')
logger.info(f'Deleting image with path: {name}')

os.unlink(file_path)
storage.delete(name)
HendrikPN marked this conversation as resolved.
Show resolved Hide resolved