Skip to content

Commit 0a7b690

Browse files
authored
Fix #6 -- Switch to settings dictionary (#8)
1 parent 6e11971 commit 0a7b690

File tree

7 files changed

+32
-20
lines changed

7 files changed

+32
-20
lines changed

README.md

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,19 @@ MIDDLEWARE = [
3030

3131
## Configuration
3232

33-
```python
34-
# Position: bottom-right, bottom-left, top-right, top-left (default: bottom-right)
35-
DEVBAR_POSITION = "top-left"
36-
37-
# Show HTML overlay (default: DEBUG)
38-
DEVBAR_SHOW_BAR = True
33+
All settings are optional. Configure via a `DEVBAR` dict in your Django settings:
3934

40-
# Add DevBar-* response headers (default: False)
41-
DEVBAR_SHOW_HEADERS = True
35+
```python
36+
DEVBAR = {
37+
'POSITION': 'bottom-right', # bottom-right, bottom-left, top-right, top-left
38+
'SHOW_BAR': None, # None (default) = follows DEBUG, or True/False to override
39+
'SHOW_HEADERS': False, # Add X-DevBar-* headers to responses
40+
}
4241
```
4342

4443
## Response Headers
4544

46-
When `DEVBAR_SHOW_HEADERS = True`, performance metrics are added as HTTP response headers. This is useful for:
45+
When `DEVBAR = {'SHOW_HEADERS': True}`, performance metrics are added as HTTP response headers. This is useful for:
4746

4847
- **API endpoints** where the HTML overlay can't be displayed
4948
- **Automated testing** to assert performance metrics (e.g., fail CI if query count exceeds a limit)

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[project]
22
name = "django-devbar"
3-
version = "0.1.3"
3+
version = "0.2.0"
44
description = "Lightweight performance devbar for Django"
55
readme = "README.md"
66
license = "MIT"

src/django_devbar/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
from .middleware import DevBarMiddleware
22

3-
__version__ = "0.1.3"
43
__all__ = ["DevBarMiddleware"]

src/django_devbar/conf.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,26 @@
88
}
99

1010

11+
def get_config():
12+
return {
13+
"POSITION": "bottom-right",
14+
"SHOW_BAR": None, # None = use settings.DEBUG
15+
"SHOW_HEADERS": False,
16+
**getattr(settings, "DEVBAR", {}),
17+
}
18+
19+
1120
def get_position():
12-
key = getattr(settings, "DEVBAR_POSITION", "bottom-right")
21+
config = get_config()
22+
key = config["POSITION"]
1323
return POSITIONS.get(key, POSITIONS["bottom-right"])
1424

1525

1626
def get_show_bar():
17-
return getattr(settings, "DEVBAR_SHOW_BAR", settings.DEBUG)
27+
config = get_config()
28+
show_bar = config["SHOW_BAR"]
29+
return settings.DEBUG if show_bar is None else show_bar
1830

1931

2032
def get_show_headers():
21-
return getattr(settings, "DEVBAR_SHOW_HEADERS", False)
33+
return get_config()["SHOW_HEADERS"]

tests/settings.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
1-
DEVBAR_SHOW_BAR = True
2-
DEVBAR_SHOW_HEADERS = True
1+
DEVBAR = {
2+
"SHOW_BAR": True,
3+
"SHOW_HEADERS": True,
4+
}

tests/test_middleware.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def get_response(request):
5555
assert b"django-devbar" not in response.content
5656

5757
def test_position_setting(self, rf, settings):
58-
settings.DEVBAR_POSITION = "top-left"
58+
settings.DEVBAR = {"POSITION": "top-left", "SHOW_BAR": True}
5959

6060
def get_response(request):
6161
return HttpResponse(
@@ -98,7 +98,7 @@ def get_response(request):
9898
assert devbar_idx > first_body_idx
9999

100100
def test_devbar_hidden_when_disabled(self, rf, settings):
101-
settings.DEVBAR_SHOW_BAR = False
101+
settings.DEVBAR = {"SHOW_BAR": False}
102102

103103
def get_response(request):
104104
return HttpResponse(
@@ -127,7 +127,7 @@ def get_response(request):
127127
assert "DevBar-Duplicates" not in response
128128

129129
def test_headers_hidden_when_disabled(self, rf, settings):
130-
settings.DEVBAR_SHOW_HEADERS = False
130+
settings.DEVBAR = {"SHOW_HEADERS": False}
131131

132132
def get_response(request):
133133
return HttpResponse(

uv.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)