mirror of
https://github.com/Hopiu/django-imagekit.git
synced 2026-03-27 10:10:23 +00:00
generate method (optionally) saves file
This way, there's a creation counterpart to `delete()`. The user shouldn't have to deal with storage backends to create and delete the files, and now they don't.
This commit is contained in:
parent
513b23b169
commit
35b807cfa9
2 changed files with 6 additions and 4 deletions
|
|
@ -16,9 +16,7 @@ class DefaultCacheStateBackend(object):
|
|||
|
||||
"""
|
||||
if self.is_invalid(file):
|
||||
content = file.generate()
|
||||
if content:
|
||||
file.storage.save(file.name, content)
|
||||
file.generate(save=True)
|
||||
|
||||
def invalidate(self, file):
|
||||
file.delete(save=False)
|
||||
|
|
|
|||
|
|
@ -240,7 +240,7 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
|
|||
def validate(self):
|
||||
return self.field.cache_state_backend.validate(self)
|
||||
|
||||
def generate(self):
|
||||
def generate(self, save=True):
|
||||
"""
|
||||
Generates a new image file by processing the source file and returns
|
||||
the content of the result, ready for saving.
|
||||
|
|
@ -257,6 +257,10 @@ class ImageSpecFile(_ImageSpecFileMixin, ImageFieldFile):
|
|||
fp = StringIO(fp.read())
|
||||
|
||||
img, content = self._process_content(self.name, fp)
|
||||
|
||||
if save:
|
||||
self.storage.save(self.name, content)
|
||||
|
||||
return content
|
||||
|
||||
@property
|
||||
|
|
|
|||
Loading…
Reference in a new issue