Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

amend modified time method to support new django file api #115

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
18 changes: 14 additions & 4 deletions swift/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@
import mimetypes
import os
import re
from datetime import datetime
from datetime import datetime, timezone
from functools import wraps
from io import BytesIO, UnsupportedOperation
from time import time

import magic
from django.conf import settings
from django.core.exceptions import ImproperlyConfigured
from django.core.files import File
from django.core.files.storage import Storage
Expand Down Expand Up @@ -363,10 +364,19 @@ def get_available_name(self, name, max_length=None):
def size(self, name):
return int(self.get_headers(name)['content-length'])

def _datetime_from_timestamp(self, ts):
"""
If timezone support is enabled, make an aware datetime object in UTC;
otherwise make a naive one in the local timezone.
"""
tz = timezone.utc if settings.USE_TZ else None
return datetime.fromtimestamp(ts, tz=tz)

@prepend_name_prefix
def modified_time(self, name):
return datetime.fromtimestamp(
float(self.get_headers(name)['x-timestamp']))
def get_modified_time(self, name):
return self._datetime_from_timestamp(
float(self.get_headers(name)['x-timestamp'])
)

@prepend_name_prefix
def url(self, name):
Expand Down