Commits

Josh VanderLinden committed 398317c

Adding some more logging and fixing the README

Comments (0)

Files changed (3)

 
 If you wish to use a Google Map to display where your visitors are probably at,
 you must have a `Google Maps API key
-<http://code.google.com/intl/ro/apis/maps/signup.html>`_, which is free.  In
-the past, you were required to have a couple of GeoIP API libraries.  Since
-version 0.2.11, these dependencies have been replaced with Django's built-in
-GIS utilities.  You might want to grab the `GeoLite City binary
+<http://code.google.com/intl/ro/apis/maps/signup.html>`_, which is free.  You
+are required to have the `GeoIP C API library
+<http://geolite.maxmind.com/download/geoip/api/c/GeoIP.tar.gz>`_ installed.
+You might want to grab the `GeoLite City binary
 <http://www.maxmind.com/app/geolitecity>`_ unless you are a paying MaxMind
 customer.  This is the data file that ``django-tracking`` uses to translate an
 IP into a location on the planet.  Configuring this feature is discussed later.

tracking/__init__.py

 import listeners
 
-VERSION = (0, 3, 5)
+VERSION = (0, 3, 6)
 
 def get_version():
     "Returns the version as a human-format string."

tracking/views.py

+from datetime import datetime
+import logging
+import traceback
+
+from django.conf import settings
+from django.http import Http404, HttpResponse
+from django.shortcuts import render_to_response
+from django.template import RequestContext, Context, loader
 from django.utils.simplejson.encoder import JSONEncoder
+from django.utils.translation import ungettext
 from django.views.decorators.cache import never_cache
-from django.http import Http404, HttpResponse
-from django.template import RequestContext, Context, loader
-from django.shortcuts import render_to_response
-from django.conf import settings
-from django.utils.translation import ungettext
 from tracking.models import Visitor
 from tracking.utils import u_clean as uc
-from datetime import datetime
 
 DEFAULT_TRACKING_TEMPLATE = getattr(settings, 'DEFAULT_TRACKING_TEMPLATE',
                                     'tracking/visitor_map.html')
+log = logging.getLogger('tracking.views')
 
 def update_active_users(request):
     """
         now = datetime.now()
 
         # we don't put the session key or IP address here for security reasons
-        data = {'users': [{
-                'id': v.id,
-                #'user': uc(v.user),
-                'user_agent': uc(v.user_agent),
-                'referrer': uc(v.referrer),
-                'url': uc(v.url),
-                'page_views': v.page_views,
-                'geoip': v.geoip_data_json,
-                'last_update': (now - v.last_update).seconds,
-                'friendly_time': ', '.join(friendly_time((now - v.last_update).seconds)),
-            } for v in active]}
-        #print data
+        try:
+            data = {'users': [{
+                    'id': v.id,
+                    #'user': uc(v.user),
+                    'user_agent': uc(v.user_agent),
+                    'referrer': uc(v.referrer),
+                    'url': uc(v.url),
+                    'page_views': v.page_views,
+                    'geoip': v.geoip_data_json,
+                    'last_update': (now - v.last_update).seconds,
+                    'friendly_time': ', '.join(friendly_time((now - v.last_update).seconds)),
+                } for v in active]}
+        except:
+            log.error('There was a problem putting all of the visitor data together:\n%s\n\n%s' % (traceback.format_exc(), locals()))
+            return HttpResponse(content='{}', mimetype='text/javascript')
 
         response = HttpResponse(content=JSONEncoder().encode(data),
                                 mimetype='text/javascript')
     Displays a map of recently active users.  Requires a Google Maps API key
     and GeoIP in order to be most effective.
     """
+
     GOOGLE_MAPS_KEY = getattr(settings, 'GOOGLE_MAPS_KEY', None)
 
     return render_to_response(template_name,