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,13 +70,19 @@ 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:
log = ApiAccessLog() try:
log.userid = params['userID'] v = int(params['userID'])
log.service = service except ValueError:
log.time_access = cached_doc.time_retrieved pass
log.document = url_path else:
log.save() print 'Adding Access Log'
log = ApiAccessLog()
log.userid = v
log.service = service
log.time_access = cached_doc.time_retrieved
log.document = url_path
log.save()
# Finish up and return the resulting document just in case. # Finish up and return the resulting document just in case.
cached_doc.save() cached_doc.save()