def test_show_toolbar_INTERNAL_IPS_STRING(self):
     with self.settings(INTERNAL_IPS='127.0.0.1'):
         self.assertTrue(show_toolbar(self.request))
     with self.settings(INTERNAL_IPS='localhost'):
         self.assertFalse(show_toolbar(self.request))
     with self.settings(INTERNAL_IPS='127.0.0.0/8'):
         self.assertFalse(show_toolbar(self.request))
Ejemplo n.º 2
0
def show_toolbar_callback(request):
    """
        Whether to show django-debug-toolbar.
        This adds an optout for urls with ?no_toolbar
    """
    from debug_toolbar.middleware import show_toolbar
    return False if 'no_toolbar' in request.GET else show_toolbar(request)
Ejemplo n.º 3
0
Archivo: common.py Proyecto: e-n-0/site
def show_toolbar_cb(req):
    from debug_toolbar.middleware import show_toolbar
    if not show_toolbar(req):
        return False
    # Disable for statictemplate
    if req.META['SERVER_NAME'] == 'testserver':
        return False
    return True
Ejemplo n.º 4
0
def djdt_show(request):
    """
    Determining whether the Django Debug Toolbar should show or not.
    """
    if not settings.DEBUG:
        return False

    if Path('/.dockerenv').exists():
        # We run in a docker container
        # skip the `request.META['REMOTE_ADDR'] in settings.INTERNAL_IPS` check.
        return True

    return show_toolbar(request)
Ejemplo n.º 5
0
def dt_show_toolbar(request: HttpRequest) -> bool:
    """Add a helper to determin if Django debug toolbar should be displayed.

    Extends the default behaviour by enabling DJDT for superusers independent
    of source IP.
    """
    from debug_toolbar.middleware import show_toolbar  # noqa

    if not settings.DEBUG:
        return False

    if show_toolbar(request):
        return True
    elif hasattr(request, "user") and request.user.is_superuser:
        return True

    return False
Ejemplo n.º 6
0
    def process_request(self, request):
        """
        Try to match the request with an URL from debug_panel application.

        If it matches, that means we are serving a view from debug_panel,
        and we can skip the debug_toolbar middleware.

        Otherwise we fallback to the default debug_toolbar middleware.
        """
        try:
            res = resolve(request.path, urlconf=debug_panel.urls)
        except Resolver404:

            #return super(DebugPanelMiddleware, self).process_request(request)


            if show_toolbar(request):
                return super(DebugPanelMiddleware, self).process_request(request)
            else:
                return None

        return res.func(request, *res.args, **res.kwargs)
Ejemplo n.º 7
0
 def test_show_toolbar_INTERNAL_IPS(self):
     with self.settings(INTERNAL_IPS=[]):
         self.assertFalse(show_toolbar(self.request))
Ejemplo n.º 8
0
 def test_show_toolbar_DEBUG(self):
     with self.settings(DEBUG=False):
         self.assertFalse(show_toolbar(self.request))
Ejemplo n.º 9
0
 def test_show_toolbar(self):
     self.assertTrue(show_toolbar(self.request))
Ejemplo n.º 10
0
 def test_show_toolbar_INTERNAL_IPS(self):
     with self.settings(INTERNAL_IPS=[]):
         self.assertFalse(show_toolbar(self.request))
Ejemplo n.º 11
0
 def test_show_toolbar_DEBUG(self):
     with self.settings(DEBUG=False):
         self.assertFalse(show_toolbar(self.request))
Ejemplo n.º 12
0
 def test_show_toolbar(self):
     self.assertTrue(show_toolbar(self.request))
Ejemplo n.º 13
0
def show_debug_toolbar(request):
    from debug_toolbar.middleware import show_toolbar
    return show_toolbar(
        request) or "debug" in request.GET or request.user.is_superuser
Ejemplo n.º 14
0
def show_toolbar(request):
    from debug_toolbar.middleware import show_toolbar
    return show_toolbar(request) or request.user.is_superuser
 def test_show_toolbar_INTERNAL_IPS_HOSTNAME(self):
     with self.settings(INTERNAL_IPS=('localhost',)):
         self.assertTrue(show_toolbar(self.request))
     with self.settings(INTERNAL_IPS=('example.org',)):
         self.assertFalse
 def test_show_toolbar_INTERNAL_IPS_CIDR(self):
     with self.settings(INTERNAL_IPS=('127.0.0.0/8',)):
         self.assertTrue(show_toolbar(self.request))
     with self.settings(INTERNAL_IPS=('192.0.2.0/24', '198.51.100.0/24', '203.0.113.0/24',)):
         self.assertFalse
 def test_show_toolbar_INTERNAL_IPS_CIDR_BAD(self):
     with self.settings(INTERNAL_IPS=('INVALID/8', '127.0.0.0/8',)):
         self.assertTrue(show_toolbar(self.request))
     with self.settings(INTERNAL_IPS=('INVALID/8',)):
         self.assertFalse