from django.conf import settings
from django.core.servers.basehttp import WSGIRequestHandler
from django.db import connection

from devserver.utils.time import ms_from_timedelta

from datetime import datetime

class SlimWSGIRequestHandler(WSGIRequestHandler):
    """
    Hides all requests that originate from ```MEDIA_URL`` as well as any
    request originating with a prefix included in ``DEVSERVER_IGNORED_PREFIXES``.
    """
    def handle(self, *args, **kwargs):
        self._start_request = datetime.now()
        return WSGIRequestHandler.handle(self, *args, **kwargs)
        
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()
        
        if settings.MEDIA_URL.startswith('http:'):
            if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(settings.MEDIA_URL):
                return
        
        # if self.path.startswith(settings.MEDIA_URL):
        #     return
        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return
        
        format += " (time: %.2fs; sql: %dms (%dq))"
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
            len(connection.queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)
from django.conf import settings
from django.core.servers.basehttp import WSGIRequestHandler
from django.db import connection

from devserver.utils.time import ms_from_timedelta

from datetime import datetime

class SlimWSGIRequestHandler(WSGIRequestHandler):
    """
    Hides all requests that originate from either ``STATIC_URL`` or ``MEDIA_URL`` 
    as well as any request originating with a prefix included in 
    ``DEVSERVER_IGNORED_PREFIXES``.
    """
    def handle(self, *args, **kwargs):
        self._start_request = datetime.now()
        return WSGIRequestHandler.handle(self, *args, **kwargs)
        
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()
        
        for url in (settings.STATIC_URL, settings.MEDIA_URL):
            if self.path.startswith(url):
                return
            elif url.startswith('http:'):
                if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(url):
                    return

        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return
        
        format += " (time: %.2fs; sql: %dms (%dq))"
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
            len(connection.queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)
Make sure that all requests for static files are correctly hidden from output
Make sure that all requests for static files are correctly hidden from output

  from django.conf import settings
  from django.core.servers.basehttp import WSGIRequestHandler
  from django.db import connection
  
  from devserver.utils.time import ms_from_timedelta
  
  from datetime import datetime
  
  class SlimWSGIRequestHandler(WSGIRequestHandler):
      """
-     Hides all requests that originate from ```MEDIA_URL`` as well as any
+     Hides all requests that originate from either ``STATIC_URL`` or ``MEDIA_URL`` 
-     request originating with a prefix included in ``DEVSERVER_IGNORED_PREFIXES``.
+     as well as any request originating with a prefix included in 
+     ``DEVSERVER_IGNORED_PREFIXES``.
      """
      def handle(self, *args, **kwargs):
          self._start_request = datetime.now()
          return WSGIRequestHandler.handle(self, *args, **kwargs)
          
      def log_message(self, format, *args):
          duration = datetime.now() - self._start_request
  
          env = self.get_environ()
          
-         if settings.MEDIA_URL.startswith('http:'):
-             if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(settings.MEDIA_URL):
+         for url in (settings.STATIC_URL, settings.MEDIA_URL):
+             if self.path.startswith(url):
                  return
-         
-         # if self.path.startswith(settings.MEDIA_URL):
+             elif url.startswith('http:'):
+                 if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(url):
-         #     return
+                     return
+ 
          for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
              if self.path.startswith(path):
                  return
          
          format += " (time: %.2fs; sql: %dms (%dq))"
          args = list(args) + [
              ms_from_timedelta(duration) / 1000,
              sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
              len(connection.queries),
          ]
          return WSGIRequestHandler.log_message(self, format, *args)
Make sure that all requests for static files are correctly hidden from output
## Code Before:
from django.conf import settings
from django.core.servers.basehttp import WSGIRequestHandler
from django.db import connection

from devserver.utils.time import ms_from_timedelta

from datetime import datetime

class SlimWSGIRequestHandler(WSGIRequestHandler):
    """
    Hides all requests that originate from ```MEDIA_URL`` as well as any
    request originating with a prefix included in ``DEVSERVER_IGNORED_PREFIXES``.
    """
    def handle(self, *args, **kwargs):
        self._start_request = datetime.now()
        return WSGIRequestHandler.handle(self, *args, **kwargs)
        
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()
        
        if settings.MEDIA_URL.startswith('http:'):
            if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(settings.MEDIA_URL):
                return
        
        # if self.path.startswith(settings.MEDIA_URL):
        #     return
        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return
        
        format += " (time: %.2fs; sql: %dms (%dq))"
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
            len(connection.queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)
## Instruction:
Make sure that all requests for static files are correctly hidden from output
## Code After:
from django.conf import settings
from django.core.servers.basehttp import WSGIRequestHandler
from django.db import connection

from devserver.utils.time import ms_from_timedelta

from datetime import datetime

class SlimWSGIRequestHandler(WSGIRequestHandler):
    """
    Hides all requests that originate from either ``STATIC_URL`` or ``MEDIA_URL`` 
    as well as any request originating with a prefix included in 
    ``DEVSERVER_IGNORED_PREFIXES``.
    """
    def handle(self, *args, **kwargs):
        self._start_request = datetime.now()
        return WSGIRequestHandler.handle(self, *args, **kwargs)
        
    def log_message(self, format, *args):
        duration = datetime.now() - self._start_request

        env = self.get_environ()
        
        for url in (settings.STATIC_URL, settings.MEDIA_URL):
            if self.path.startswith(url):
                return
            elif url.startswith('http:'):
                if ('http://%s%s' % (env['HTTP_HOST'], self.path)).startswith(url):
                    return

        for path in getattr(settings, 'DEVSERVER_IGNORED_PREFIXES', []):
            if self.path.startswith(path):
                return
        
        format += " (time: %.2fs; sql: %dms (%dq))"
        args = list(args) + [
            ms_from_timedelta(duration) / 1000,
            sum(float(c.get('time', 0)) for c in connection.queries) * 1000,
            len(connection.queries),
        ]
        return WSGIRequestHandler.log_message(self, format, *args)