Skip to content

Commit

Permalink
Merge pull request #4545 from rtfd/davidfischer/enable-timezone-support
Browse files Browse the repository at this point in the history
Enable timezone support and set timezone to UTC
  • Loading branch information
ericholscher authored Nov 6, 2018
2 parents b63ef59 + 953a4ee commit d2137df
Show file tree
Hide file tree
Showing 12 changed files with 96 additions and 84 deletions.
5 changes: 3 additions & 2 deletions readthedocs/core/admin.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Django admin interface for core models."""

from __future__ import absolute_import
from datetime import datetime, timedelta
from datetime import timedelta

from django.contrib import admin
from django.contrib.auth.models import User
from django.contrib.auth.admin import UserAdmin
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone

from readthedocs.core.models import UserProfile
from readthedocs.projects.models import Project
Expand Down Expand Up @@ -50,7 +51,7 @@ def queryset(self, request, queryset):
if self.value() == self.PROJECT_BUILT:
return queryset.filter(projects__versions__built=True)
if self.value() == self.PROJECT_RECENT:
recent_date = datetime.today() - timedelta(days=365)
recent_date = timezone.now() - timedelta(days=365)
return queryset.filter(projects__builds__date__gt=recent_date)


Expand Down
12 changes: 6 additions & 6 deletions readthedocs/core/fixtures/eric.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@
"is_active": true,
"is_superuser": false,
"is_staff": true,
"last_login": "2010-08-14 01:51:05",
"last_login": "2010-08-14T01:51:05+00:00",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$30000$Vs87OlKZEzCb$nUw1o5pGQw7ff/QhnleSpUOupBaT1DogZrVaoZyQRyc=",
"email": "e@e.co",
"date_joined": "2010-08-14 01:50:58"
"date_joined": "2010-08-14T01:50:58+00:00"
}
},
{
Expand All @@ -27,12 +27,12 @@
"is_active": true,
"is_superuser": false,
"is_staff": true,
"last_login": "2010-08-14 01:51:05",
"last_login": "2010-08-14T01:51:05+00:00",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$30000$Vs87OlKZEzCb$nUw1o5pGQw7ff/QhnleSpUOupBaT1DogZrVaoZyQRyc=",
"email": "e@etest.co",
"date_joined": "2010-08-14 01:50:58"
"date_joined": "2010-08-14T01:50:58+00:00"
}
},
{
Expand All @@ -45,12 +45,12 @@
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2010-08-14 01:51:05",
"last_login": "2010-08-14T01:51:05+00:00",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$30000$Vs87OlKZEzCb$nUw1o5pGQw7ff/QhnleSpUOupBaT1DogZrVaoZyQRyc=",
"email": "e@e.co",
"date_joined": "2010-08-14 01:50:58"
"date_joined": "2010-08-14T01:50:58+00:00"
}
}
]
5 changes: 3 additions & 2 deletions readthedocs/core/management/commands/clean_builds.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
"""Clean up stable build paths per project version"""

from __future__ import absolute_import
from datetime import datetime, timedelta
from datetime import timedelta
import logging
from optparse import make_option

from django.core.management.base import BaseCommand
from django.db.models import Max
from django.utils import timezone

from readthedocs.builds.models import Build, Version

Expand Down Expand Up @@ -35,7 +36,7 @@ def add_arguments(self, parser):

def handle(self, *args, **options):
"""Find stale builds and remove build paths"""
max_date = datetime.now() - timedelta(days=options['days'])
max_date = timezone.now() - timedelta(days=options['days'])
queryset = (Build.objects
.values('project', 'version')
.annotate(max_date=Max('date'))
Expand Down
7 changes: 5 additions & 2 deletions readthedocs/oauth/services/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from allauth.socialaccount.providers import registry
from builtins import object
from django.conf import settings
from django.utils import timezone
from oauthlib.oauth2.rfc6749.errors import InvalidClientIdError
from requests.exceptions import RequestException
from requests_oauthlib import OAuth2Session
Expand Down Expand Up @@ -83,7 +84,7 @@ def create_session(self):
'token_type': 'bearer',
}
if token.expires_at is not None:
token_expires = (token.expires_at - datetime.now()).total_seconds()
token_expires = (token.expires_at - timezone.now()).total_seconds()
token_config.update({
'refresh_token': token.token_secret,
'expires_in': token_expires,
Expand Down Expand Up @@ -119,7 +120,9 @@ def token_updater(self, token):
"""
def _updater(data):
token.token = data['access_token']
token.expires_at = datetime.fromtimestamp(data['expires_at'])
token.expires_at = timezone.make_aware(
datetime.fromtimestamp(data['expires_at'])
)
token.save()
log.info('Updated token %s:', token)

Expand Down
8 changes: 4 additions & 4 deletions readthedocs/projects/fixtures/test_auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -675,12 +675,12 @@
"is_active": true,
"is_superuser": false,
"is_staff": false,
"last_login": "2014-02-09T19:47:26.625",
"last_login": "2014-02-09T19:47:26.625+00:00",
"groups": [],
"user_permissions": [],
"password": "",
"email": "",
"date_joined": "2014-02-09T19:47:26.625"
"date_joined": "2014-02-09T19:47:26.625+00:00"
}
},
{
Expand All @@ -693,12 +693,12 @@
"is_active": true,
"is_superuser": true,
"is_staff": true,
"last_login": "2014-02-09T19:48:39.934",
"last_login": "2014-02-09T19:48:39.934+00:00",
"groups": [],
"user_permissions": [],
"password": "pbkdf2_sha256$10000$FgAANNnclCS5$ElbS6laaFoh+nyHbEb96ICxS3xK1LioUS+CMQK+KdYM=",
"email": "test@readthedocs.org",
"date_joined": "2014-02-09T19:48:39.934"
"date_joined": "2014-02-09T19:48:39.934+00:00"
}
}
]
Loading

0 comments on commit d2137df

Please sign in to comment.