• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

iplweb / bpp / #819

18 Oct 2025 12:03PM UTC coverage: 59.791% (+25.6%) from 34.185%
#819

push

local-test

MichaƂ Pasternak
autostash

3781 of 9280 branches covered (40.74%)

Branch coverage included in aggregate %.

24978 of 38819 relevant lines covered (64.34%)

0.64 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

26.32
src/bpp/middleware.py
1
import json
1✔
2

3
from django.http import HttpResponse
1✔
4
from django.utils.deprecation import MiddlewareMixin
1✔
5
from rollbar.contrib.django.middleware import RollbarNotifierMiddleware
1✔
6

7

8
class NonHtmlDebugToolbarMiddleware(MiddlewareMixin):
1✔
9
    """
10
    The Django Debug Toolbar usually only works for views that return HTML.
11
    This middleware wraps any non-HTML response in HTML if the request
12
    has a 'debug' query parameter (e.g. http://localhost/foo?debug)
13
    Special handling for json (pretty printing) and
14
    binary data (only show data length)
15
    """
16

17
    @staticmethod
1✔
18
    def process_response(request, response):
1✔
19
        debug = request.GET.get("debug", "UNSET")
×
20

21
        if debug != "UNSET":
×
22
            if response["Content-Type"] == "application/octet-stream":
×
23
                new_content = (
×
24
                    "<html><body>Binary Data, "
25
                    f"Length: {len(response.content)}</body></html>"
26
                )
27
                response = HttpResponse(new_content)
×
28
            elif response["Content-Type"] != "text/html":
×
29
                content = response.content
×
30
                try:
×
31
                    json_ = json.loads(content)
×
32
                    content = json.dumps(json_, sort_keys=True, indent=2)
×
33
                except ValueError:
×
34
                    pass
×
35
                response = HttpResponse(
×
36
                    f"<html><body><pre>{content}" "</pre></body></html>"
37
                )
38

39
        return response
×
40

41

42
class CustomRollbarNotifierMiddleware(RollbarNotifierMiddleware):
1✔
43
    def get_extra_data(self, request, exc):
1✔
44
        from django.conf import settings
×
45

46
        return {
×
47
            "DJANGO_BPP_HOSTNAME": settings.DJANGO_BPP_HOSTNAME,
48
        }
49

50
    def get_payload_data(self, request, exc):
1✔
51
        payload_data = dict()
×
52

53
        if not request.user.is_anonymous:
×
54
            # Adding info about the user affected by this event (optional)
55
            # The 'id' field is required, anything else is optional
56
            payload_data = {
×
57
                "person": {
58
                    "id": request.user.id,
59
                    "username": request.user.username,
60
                    "email": request.user.email,
61
                },
62
            }
63

64
        return payload_data
×
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc