mirror of
https://github.com/nikdoof/test-auth.git
synced 2025-12-18 12:19:29 +00:00
Fix date/time fuctions for timezone information
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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 *
|
||||
@@ -54,12 +53,10 @@ class OAuthOpTimerHandler(BaseHandler):
|
||||
|
||||
for node in dom.getElementsByTagName('rowset')[0].childNodes:
|
||||
if node.nodeType == 1:
|
||||
ownerID = node.getAttribute('ownerID')
|
||||
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'))
|
||||
@@ -84,7 +81,7 @@ class OAuthOpTimerHandler(BaseHandler):
|
||||
'isImportant': int(node.getAttribute('importance')),
|
||||
'eventText': node.getAttribute('eventText'),
|
||||
'endsIn':endsIn,
|
||||
'forumLink': forumlink}
|
||||
'forumLink': forumlink}
|
||||
events.append(event)
|
||||
|
||||
if len(events) == 0:
|
||||
@@ -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):
|
||||
|
||||
@@ -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
|
||||
@@ -194,12 +194,10 @@ class OpTimerHandler(BaseHandler):
|
||||
events = []
|
||||
for node in dom.getElementsByTagName('rowset')[0].childNodes:
|
||||
if node.nodeType == 1:
|
||||
ownerID = node.getAttribute('ownerID')
|
||||
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'))
|
||||
@@ -224,7 +222,7 @@ class OpTimerHandler(BaseHandler):
|
||||
'isImportant': int(node.getAttribute('importance')),
|
||||
'eventText': ' '.join(BeautifulSoup(node.getAttribute('eventText')).findAll(text=True)),
|
||||
'endsIn':endsIn,
|
||||
'forumLink': forumlink}
|
||||
'forumLink': forumlink}
|
||||
events.append(event)
|
||||
if len(events) == 0:
|
||||
return {'ops':[{
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user