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:
Matthew Tretter 2012-02-03 09:16:50 -05:00
parent 513b23b169
commit 35b807cfa9
2 changed files with 6 additions and 4 deletions

View file

@ -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)

View file

@ -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