Josh VanderLinden avatar Josh VanderLinden committed 5a4a283

Handling some problems in the setup script...

Comments (0)

Files changed (2)

 syntax: glob
 dist
 build
+*.dat
 *.egg*
 *.pyc
 *.swp

tracking/listeners.py

 import logging
 
-from django.core.cache import cache
-from django.db.models.signals import post_save, post_delete
-from tracking.models import UntrackedUserAgent, BannedIP
-
 log = logging.getLogger('tracking.listeners')
 
-def refresh_untracked_user_agents(sender, instance, created=False, **kwargs):
-    """Updates the cache of user agents that we don't track"""
+try:
+    from django.core.cache import cache
+    from django.db.models.signals import post_save, post_delete
 
-    log.debug('Updating untracked user agents cache')
-    cache.set('_tracking_untracked_uas',
-        UntrackedUserAgent.objects.all(),
-        3600)
+    from tracking.models import UntrackedUserAgent, BannedIP
+except ImportError:
+    pass
+else:
 
-def refresh_banned_ips(sender, instance, created=False, **kwargs):
-    """Updates the cache of banned IP addresses"""
+    def refresh_untracked_user_agents(sender, instance, created=False, **kwargs):
+        """Updates the cache of user agents that we don't track"""
 
-    log.debug('Updating banned IP cache')
-    cache.set('_tracking_banned_ips',
-        [b.ip_address for b in BannedIP.objects.all()],
-        3600)
+        log.debug('Updating untracked user agents cache')
+        cache.set('_tracking_untracked_uas',
+            UntrackedUserAgent.objects.all(),
+            3600)
 
-post_save.connect(refresh_untracked_user_agents, sender=UntrackedUserAgent)
-post_delete.connect(refresh_untracked_user_agents, sender=UntrackedUserAgent)
+    def refresh_banned_ips(sender, instance, created=False, **kwargs):
+        """Updates the cache of banned IP addresses"""
 
-post_save.connect(refresh_banned_ips, sender=BannedIP)
-post_delete.connect(refresh_banned_ips, sender=BannedIP)
+        log.debug('Updating banned IP cache')
+        cache.set('_tracking_banned_ips',
+            [b.ip_address for b in BannedIP.objects.all()],
+            3600)
+
+    post_save.connect(refresh_untracked_user_agents, sender=UntrackedUserAgent)
+    post_delete.connect(refresh_untracked_user_agents, sender=UntrackedUserAgent)
+
+    post_save.connect(refresh_banned_ips, sender=BannedIP)
+    post_delete.connect(refresh_banned_ips, sender=BannedIP)
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.