Commits

Kostas Papadimitriou committed 6aa6ef8 Draft

Improve ignore urls setting

Use dict to allow method/url-regex mapping.

Comments (0)

Files changed (1)

dogslow/__init__.py

 import thread
 import linecache
 import os
+import re
 import datetime as dt
 
 from django.conf import settings
     def peek(request, thread_id, started):
         try:
             frame = sys._current_frames()[thread_id]
-            
+
             req_string = '%s %s://%s%s' % (
                 request.META.get('REQUEST_METHOD'),
                 request.META.get('wsgi.url_scheme', 'http'),
 
     def _is_exempt(self, request):
         """Returns True if this request's URL resolves to a url pattern whose
-        name is listed in settings.DOGSLOW_IGNORE_URLS.
+        name is listed in settings.DOGSLOW_IGNORE_URLS dict object.
+
+        DOGSLOW_IGNORE_URLS = {
+            '*': ['/api/uploads/.*'],
+            'POST': ['/api/create/.*'],
+            'GET': ['/static/.*']
+        }
         """
+        ignore_urls = getattr(settings, 'DOGSLOW_IGNORE_URLS', {})
+
+        for method, urls in ignore_urls.iteritems():
+            if request.method != method and method != '*':
+                continue
+
+            for url_reg in urls:
+                if re.match(url_reg, request.META.get('PATH_INFO', None)):
+                    return True
+
         return False
-        #match = resolve(request.META.get('PATH_INFO'))
-        #return match and (getattr(match, 'url_name', '') in
-        #               getattr(settings, 'DOGSLOW_IGNORE_URLS', ()))
 
     def process_request(self, request):
         if not self._is_exempt(request):