Commits

ken cochrane committed 3bf9215 Merge

Merged in pydanny/django-visitor-pydanny (pull request #4)

Comments (0)

Files changed (4)

 # If extensions (or modules to document with autodoc) are in another directory,
 # add these directories to sys.path here. If the directory is relative to the
 # documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.insert(0, os.path.abspath('.'))
+sys.path.insert(0, os.path.abspath('..'))
+
+import settings
+from django.core.management import setup_environ
+setup_environ(settings)
 
 # -- General configuration -----------------------------------------------------
 
 .. django-visitor documentation master file, created by
    sphinx-quickstart on Tue Jul 26 07:25:04 2011.
-   You can adapt this file completely to your liking, but it should at least
-   contain the root `toctree` directive.
 
 Welcome to django-visitor's documentation!
 ==========================================
 
 Django 1.1 or newer
 
+Code Repo
+---------
+
+ * https://bitbucket.org/kencochrane/django-visitor
 
 Installation
 ------------
     python manage.py syncdb
 
 Custom Settings
-------------
+---------------
+
 Add the following two properties to your settings file::
 
     COOKIE_DOMAIN
         Default = 31536000 # or 1 year.
         # This is how long the cookie will live in your visitors browser before it expires on it's own
         COOKIE_MAX_AGE = 31536000 # 1 year
+        
+References
+----------
+        
+.. toctree::
+    :maxdepth: 2
+
+    ref_visitor_utils
 
 
 Indices and tables

docs/ref_visitor_utils.rst

+=======================
+Visitor Utils Reference
+=======================
+
+
+.. automodule:: visitor.visitor_utils
+  :members:
+  :undoc-members:

visitor/visitor_utils.py

+import itertools
+import time
 import uuid
-import time
-import itertools
+
+from django.conf import settings
 
 from visitor.models import Visitor
 from visitor import visitor_constants as constants
-from django.conf import settings
 
 # this is a counter to make sure our uuid's are unique.
 counter = itertools.count(0).next
 COOKIE_DOMAIN = getattr(settings, 'COOKIE_DOMAIN', None) # local domain only 
 COOKIE_MAX_AGE = getattr(settings, 'COOKIE_MAX_AGE', 31536000) # 1 year
 
-#-------------------------------------------------------------------------------
 def create_uuid(*parts):
     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):
     meta = request.META
 
         ip_address = meta.get('REMOTE_ADDR', None)
 
     return ip_address
-    
-#-------------------------------------------------------------------------------
+
 def get_visitor(visitor_key):
     """ get the visitor using the 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.save()
     return visitor
 
-#-------------------------------------------------------------------------------
 def update_visitor(visitor_key,session_key=None):
     """ update the visitor using the visitor key """
     visitor = Visitor.objects.find_visitor(visitor_key)
         visitor.save()
     return visitor
 
-
-#-------------------------------------------------------------------------------
 def get_visitor_cookie_key(request):
     """ look for the cookie and if we find one return the visitor key """
     if constants.COOKIE_VISITOR_KEY in request.COOKIES:
         return request.COOKIES[constants.COOKIE_VISITOR_KEY]
     else:
         return None
-        
-#-------------------------------------------------------------------------------
+
 def get_visitor_from_request(request):
     """ look for the cookie and if we find one return the visitor key """
     if constants.COOKIE_VISITOR_KEY in request.COOKIES:
         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:
             domain=COOKIE_DOMAIN
         )
 
-#-------------------------------------------------------------------------------
 def set_visitor_cookie_from_key(response, visitor_key):
     """ set the cookie using the visitor_key"""
     if response and visitor_key:
             domain=COOKIE_DOMAIN
         )
 
-#-------------------------------------------------------------------------------
 def delete_visitor_cookie(response):
     """ delete the visitor cookie """
     if response:
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.