Implement new Django time metadata interface where possible #1240
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Closes #1233.
This PR normalizes the distribution of implementations of Django's newer
get_*_time
and its older*_time
interfaces across the various storage backends. It does not add any new specific functionality, e.g., modified time on some backend that previously did not have this functionality.On a technical level, this PR introduces a new
TimeStorageMixin
containing time metadata logic. This simplifies storage backends and their tests because they no longer have to deal with the specifics of the Django interface (i.e., converting timezones based on theUSE_TZ
setting). To do so, each subclass implements a custom_*_time
interface that can return a naive or aware datetime, andTimeStorageMixin
handles the rest.Subclasses of
TimeStorageMixin
automatically support both the newer and the older interface if timezone information is present, else only the older*_time
interface, by raisingNotImplementedError
where appropriate.To ensure the new interface is definitely supported, subclasses may set
_default_timezone
. Azure, Dropbox, Google Cloud and S3 Boto3 all assume UTC datetime values by default, even if the underlying library should somehow fail to return aware datetime values. FTP and SFTP do not have a default timezone, but end users are free to subclass the storage and provide it if known. Apache Libcloud does not feature any time metadata methods.Availability (✅ = implemented, ❌ = not implemented,⚠️ = only old interface implemented but new interface easily implemented by providing a default timezone):
get_accessed_time
get_created_time
get_modified_time
Breaking changes:
make_naive
to its return value.