Fix date/time fuctions for timezone information

This commit is contained in:
2012-05-20 14:23:08 +01:00
parent 0a4b30244f
commit 1bbd15abce
5 changed files with 20 additions and 22 deletions

View File

@@ -1,7 +1,10 @@
from urllib import urlencode
from datetime import datetime
from django.http import HttpResponseForbidden
from django.contrib.auth.models import AnonymousUser
from django.utils.timezone import now
from api.models import AuthAPIKey, AuthAPILog
@@ -21,7 +24,7 @@ class APIKeyAuthentication(object):
url = "%s?%s" % (request.path, urlencode(params))
else:
url = request.path
AuthAPILog(key=keyobj, access_datetime=datetime.utcnow(), url=url).save()
AuthAPILog(key=keyobj, access_datetime=now(), url=url).save()
request.user = AnonymousUser()
request.api_key = keyobj
return True

View File

@@ -5,17 +5,16 @@ from operator import itemgetter
from django.contrib.auth import login, logout, authenticate
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.utils.timezone import now, utc
from piston.handler import BaseHandler
from piston.utils import rc, throttle
from api.models import AuthAPIKey, AuthAPILog
from eve_proxy.models import CachedDocument
from eve_proxy.exceptions import *
from eve_api.app_defines import *
@@ -56,10 +55,8 @@ class OAuthOpTimerHandler(BaseHandler):
if node.nodeType == 1:
ownerID = node.getAttribute('ownerID')
if ownerID != '1':
date = node.getAttribute('eventDate')
dt = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
now = datetime.utcnow()
startsIn = int(dt.strftime('%s')) - int(now.strftime('%s'))
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
duration = int(node.getAttribute('duration'))
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
@@ -101,7 +98,7 @@ class OAuthOpTimerHandler(BaseHandler):
'forumLink': ''}]}
else:
events.sort(key=itemgetter('startsIn'))
return {'ops': events, 'doc_time': cached_doc.time_retrieved, 'cache_until': cached_doc.cached_until, 'current_time': datetime.utcnow() }
return {'ops': events, 'doc_time': cached_doc.time_retrieved, 'cache_until': cached_doc.cached_until, 'current_time': now() }
class OAuthCharacterHandler(BaseHandler):

View File

@@ -4,11 +4,11 @@ from xml.dom import minidom
from operator import itemgetter
from django.contrib.auth.models import User
from django.http import HttpResponse
from django.core.urlresolvers import reverse
from django.shortcuts import get_object_or_404
from django.conf import settings
from django.utils.timezone import now
from BeautifulSoup import BeautifulSoup
from piston.handler import BaseHandler
@@ -196,10 +196,8 @@ class OpTimerHandler(BaseHandler):
if node.nodeType == 1:
ownerID = node.getAttribute('ownerID')
if ownerID != '1':
date = node.getAttribute('eventDate')
dt = datetime.strptime(date, '%Y-%m-%d %H:%M:%S')
now = datetime.utcnow()
startsIn = int(dt.strftime('%s')) - int(now.strftime('%s'))
dt = datetime.strptime(node.getAttribute('eventDate'), '%Y-%m-%d %H:%M:%S').replace(tzinfo=utc)
startsIn = int(dt.strftime('%s')) - int(now().strftime('%s'))
duration = int(node.getAttribute('duration'))
fid = re.search('topic=[\d]+', node.getAttribute('eventText'))
@@ -240,7 +238,7 @@ class OpTimerHandler(BaseHandler):
'forumLink': ''}]}
else:
events.sort(key=itemgetter('startsIn'))
return {'ops': events, 'doc_time': cached_doc.time_retrieved, 'cache_until': cached_doc.cached_until, 'current_time': datetime.utcnow() }
return {'ops': events, 'doc_time': cached_doc.time_retrieved, 'cache_until': cached_doc.cached_until, 'current_time': now() }
class BlacklistHandler(BaseHandler):

View File

@@ -13,6 +13,7 @@ from django.forms.extras.widgets import SelectDateWidget
from django.views.generic import TemplateView, DetailView, FormView, CreateView, ListView
from django.views.generic.detail import BaseDetailView
from django.conf import settings
from django.utils.timezone import now
from gargoyle import gargoyle
@@ -354,7 +355,7 @@ class HrBlacklistUser(FormView):
self.source = BlacklistSource.objects.get(id=1)
self.expiry = form.cleaned_data.get('expiry_date', None)
if not self.expiry:
self.expiry = datetime.utcnow() + timedelta(days=50*365) # 50 year default
self.expiry = now() + timedelta(days=50*365) # 50 year default
self.level = form.cleaned_data.get('level', 0)
self.reason = form.cleaned_data.get('reason', 'No reason provided')

View File

@@ -1,5 +1,6 @@
from django.db import IntegrityError
from django.contrib.auth import logout
from django.utils.timezone import utc, now
class InactiveLogoutMiddleware(object):
"""
@@ -59,7 +60,5 @@ class IPTrackingMiddleware(object):
if request.user and not request.user.is_anonymous():
ip, created = SSOUserIPAddress.objects.get_or_create(user=request.user, ip_address=request.META['REMOTE_ADDR'])
if created:
ip.first_seen = datetime.utcnow()
ip.last_seen = datetime.utcnow()
ip.last_seen = now()
ip.save()