Commits

Ken Cochrane  committed 969f091

fixed an issue with visitor_utils.get_visitor_from_request() that was causing an error with missing get_visitor(), also cleaned up visitor_utils a little PEP8 wise, and added a few more comments

  • Participants
  • Parent commits 1ea834f

Comments (0)

Files changed (3)

 ==========
 Change Log
 ==========
+0.1.7 - Fixed an issue with visitor_utils.get_visitor_from_request() that was causing an error with missing get_visitor()
+
 0.1.6 - Fixed the pypi tar.gz, it was missing some files
 
-0.1.5 - added VISITOR_IGNORE_IP_LIST custom setting to help with issues behind a load balancer.
+0.1.5 - Added VISITOR_IGNORE_IP_LIST custom setting to help with issues behind a load balancer.
 
 0.1.4 - Merged in changes from pydanny (cleanup and better docs)
 
 
 setup(
     name='django-visitor',
-    version='0.1.6',
+    version='0.1.7',
     description='Track visitors across your site using a cookie',
     maintainer='Ken Cochrane',
     maintainer_email='KenCochrane@gmail.com',

File visitor/visitor_utils.py

 VISITOR_IGNORE_IP_LIST = getattr(settings, 'VISITOR_IGNORE_IP_LIST', ('127.0.0.1',))
 
 def create_uuid(*parts):
+    """ create a uuid """
     name = '-'.join([str(counter())] + [str(time.time())] + [str(p) for p in parts])
     return str(uuid.uuid5(uuid.NAMESPACE_URL, name))
 
 def ip_address_from_request(request):
+    """ get the ip address from the request added special logic for lots
+    of different conditions, proxies, etc. """
     meta = request.META
 
   # figure out the IP
 
     return ip_address
 
-def create_visitor(ip_address,session_key):
+def get_visitor(visitor_key):
+    """ get visitor by their visitor key"""
+    return Visitor.objects.find_visitor(visitor_key)
+
+def create_visitor(ip_address, session_key):
     """ Create the visitor given an ip_address """
     visitor = Visitor()
     visitor.generate_key(ip_address)
     visitor.save()
     return visitor
 
-def update_visitor(visitor_key,session_key=None):
+def update_visitor(visitor_key, session_key=None):
     """ update the visitor using the visitor key """
-    visitor = Visitor.objects.find_visitor(visitor_key)
+    visitor = get_visitor(visitor_key)
     if visitor:
         visitor.mark_visit()
         if session_key:
         return get_visitor(request.COOKIES[constants.COOKIE_VISITOR_KEY])
     else:
         return None
+
 def set_visitor_cookie(response, visitor):
     """ set the visitor cookie using the visitor object """
     if response and visitor and visitor.visitor_key:
             constants.COOKIE_VISITOR_KEY,
             domain=COOKIE_DOMAIN
         )
-
-