SmileyChris/easy-thumbnails — pull request #180 by roberts81 (2012-11-21 21:48:03+00:00)
Title: Use modified_time method provided by Storage interface instead of assuming os.path compatible storages when getting mod times

As you're aware, modtimes are critical for the thumbnail_exists method (and much of the framework) to operate correctly. Currently, get_source_modtime & get_thumbnail_modtime, in files.py (line 461 & 470), are hardcoded to use os.path.getmtime to get the modtimes for thumbnails and sources. However, this assumes an os.path compatible Storage backend and neglects the fact that Django Storage classes and subclasses already implement a "modified_time" method for this purpose.

I've written a database base64-based storage backend & a memcached storage backend (with fall-back to database) in order to do various things on Heroku, which has an ephemeral file-system that is useless for writing files to. I have my reasons for doing this instead of uploading to S3.

As it stands, easy-thumbnails doesn't work out of the box with these custom storages because of the os.path assumption. However, there was no reason why easy-thumbnails couldn't work with any storage backend that implements the modified_time interface which Django's Storage prescribes. FileSystemStorage (and by extension ThumbnailFileSystemStorage) already implement modified_time by doing basically the same thing easy-thumbnails manually does (see django.core.files.storage.FileSystemStorage):

```def modified_time(self, name):
return datetime.fromtimestamp(os.path.getmtime(self.path(name)))```

In sum, it seems more correct to use the storage's modified_time method rather than manually getting the modified time, and this enables different types of backends.

My commit swaps out the hardcoded call to os.path and calls the storage's modified_time method instead. Also, the call to ```utils.fromtimestamp``` at lines 437 and 449 become redundant, since the modified_time method in FileSystemStorage performs this conversion already for file-based storages.

All tests pass, and I don't really see room for new tests beyond the current ones, since this is using the modified_time method of Django Storage or FileSystemStorage (or of a custom storage) which are tested in their respective packages. But i'd be happy to write a test if you can describe to me what it would do. Anecdotally, I've been using this code in production for a few months and it works great.