Skip to content

Commit

Permalink
Fix python 2.6 dt.total_seconds.
Browse files Browse the repository at this point in the history
  • Loading branch information
hellysmile committed Nov 2, 2015
1 parent 52562c1 commit 7c34d2d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from django.core.management.base import NoArgsCommand

from ... import backend
from ...utils import total_seconds

try: # Django >= 1.4
from django.utils import timezone
Expand All @@ -25,7 +26,7 @@ def handle_noargs(self, *args, **kwargs):
self.stdout.write('processing %d of %d\n' % (counter, count))

expire_in = session.expire_date - timezone.now()
expire_in = expire_in.total_seconds()
expire_in = round(total_seconds(expire_in))

if expire_in < 0:
continue
Expand Down
3 changes: 0 additions & 3 deletions redis_sessions_fork/session.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ class SessionStore(SessionBase):
'''
Redis Session Backend For Django
'''
def __init__(self, session_key=None):
super(SessionStore, self).__init__(session_key)

def _get_or_create_session_key(self):
if self._session_key is None:
self._session_key = self._get_new_session_key()
Expand Down
11 changes: 11 additions & 0 deletions redis_sessions_fork/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,14 @@ def import_by_path(dotted_path):
raise ImportError('can not import %s' % dotted_path)

return attr


def total_seconds(dt):
if hasattr(dt, 'total_seconds'):
return dt.total_seconds()
else:
return (
(dt.microseconds + (dt.seconds + dt.days * 24 * 3600) * 10 ** 6)
/
10 ** 6
)

0 comments on commit 7c34d2d

Please sign in to comment.