Fixed validation of variables and also logging of access requests

This commit is contained in:
2010-06-04 11:58:20 +01:00
parent 1f441a29b1
commit cfb5b2fffc

View File

@@ -16,10 +16,11 @@ class CachedDocumentManager(models.Manager):
""" """
def get_document_id(self, url_path, params): def get_document_id(self, url_path, params):
if params: p = params.copy()
if 'service' in params: if p:
del params['service'] if 'service' in p:
paramstr = urllib.urlencode(params) del p['service']
paramstr = urllib.urlencode(p)
else: else:
paramstr = '' paramstr = ''
@@ -35,6 +36,7 @@ class CachedDocumentManager(models.Manager):
method = 'GET' method = 'GET'
paramstr = '' paramstr = ''
print params
if params: if params:
if 'service' in params: if 'service' in params:
service = params['service'] service = params['service']
@@ -68,9 +70,15 @@ class CachedDocumentManager(models.Manager):
cached_doc.cached_until = dom.getElementsByTagName('cachedUntil')[0].childNodes[0].nodeValue cached_doc.cached_until = dom.getElementsByTagName('cachedUntil')[0].childNodes[0].nodeValue
# If this is user related, write a log instance # If this is user related, write a log instance
if params and 'userID' in params and type(params['userID']) == long: if params and 'userID' in params:
try:
v = int(params['userID'])
except ValueError:
pass
else:
print 'Adding Access Log'
log = ApiAccessLog() log = ApiAccessLog()
log.userid = params['userID'] log.userid = v
log.service = service log.service = service
log.time_access = cached_doc.time_retrieved log.time_access = cached_doc.time_retrieved
log.document = url_path log.document = url_path