Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
6 changes: 1 addition & 5 deletions stdimage/management/commands/rendervariations.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
BAR = None


def class_to_path(cls):
return '.'.join((cls.__module__, cls.__class__.__name__))


class MemoryUsageWidget(progressbar.widgets.WidgetBase):
def __call__(self, progress, data):
return 'RAM: {0:10.1f} MB'.format(
Expand Down Expand Up @@ -64,7 +60,7 @@ def render(field, images, count, replace):
file_name=file_name,
variations=field.variations,
replace=replace,
storage=class_to_path(field.storage),
storage=field.storage.deconstruct()[0],
)
for file_name in images
]
Expand Down
11 changes: 11 additions & 0 deletions tests/models.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from django.core.files.storage import FileSystemStorage
from django.db import models
from django.db.models.signals import post_delete, pre_save

Expand Down Expand Up @@ -104,6 +105,16 @@ class ManualVariationsModel(CustomManagerModel):
)


class MyStorageModel(CustomManagerModel):
"""delays creation of 150x150 thumbnails until it is called manually"""
image = StdImageField(
upload_to=UploadTo(name='image', path='img'),
variations={'thumbnail': (150, 150, True)},
render_variations=False,
storage=FileSystemStorage(),
)


def render_job(**kwargs):
render_variations(**kwargs)
return False
Expand Down
2 changes: 2 additions & 0 deletions tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
'tests'
)

DEFAULT_FILE_STORAGE = 'tests.storage.MyFileSystemStorage'

MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
Expand Down
5 changes: 5 additions & 0 deletions tests/storage.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
from django.core.files.storage import FileSystemStorage


class MyFileSystemStorage(FileSystemStorage):
pass
13 changes: 12 additions & 1 deletion tests/test_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import pytest
from django.core.management import call_command

from tests.models import ManualVariationsModel, ThumbnailModel
from tests.models import ManualVariationsModel, MyStorageModel, ThumbnailModel


@pytest.mark.django_db
Expand Down Expand Up @@ -62,3 +62,14 @@ def test_replace(self, image_upload_file):
assert os.path.exists(file_path)
after = os.path.getmtime(file_path)
assert before != after

def test_none_default_storage(self, image_upload_file):
obj = MyStorageModel.customer_manager.create(
image=image_upload_file
)
file_path = obj.image.thumbnail.path
call_command(
'rendervariations',
'tests.MyStorageModel.image'
)
assert os.path.exists(file_path)