Skip to content

Commit a78e0a5

Browse files
committed
Merge remote-tracking branches 'jdufresne/span-href', 'jdufresne/stats', 'jdufresne/screenshot' and 'jdufresne/dom-id'
* jdufresne/span-href: Remove invalid href attribute from span elements * jdufresne/stats: Improve and simplify the "stats" CSS on the SQL panel * jdufresne/screenshot: Automate screenshot generation in README.rst Make djdt-{{ panel.panel_id }} a DOM ID instead of DOM class Make it simpler to run the example project * jdufresne/dom-id: Make djdt-{{ panel.panel_id }} a DOM ID instead of DOM class
4 parents ca70c2b + 83a01d9 + f04f480 + f033aa1 commit a78e0a5

File tree

11 files changed

+137
-49
lines changed

11 files changed

+137
-49
lines changed

Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ flake8:
1313
flake8
1414

1515
example:
16+
python example/manage.py migrate --noinput
17+
-DJANGO_SUPERUSER_PASSWORD=p python example/manage.py createsuperuser \
18+
--noinput --username="$(USER)" --email="$(USER)@mailinator.com"
1619
python example/manage.py runserver
1720

1821
eslint: package-lock.json
@@ -44,3 +47,8 @@ translatable_strings:
4447
update_translations:
4548
tx pull -a --minimum-perc=10
4649
cd debug_toolbar && python -m django compilemessages
50+
51+
.PHONY: example/django-debug-toolbar.png
52+
example/django-debug-toolbar.png: example/screenshot.py
53+
python $< --browser firefox --headless -o $@
54+
optipng $@

README.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ more details about the panel's content.
2525
Here's a screenshot of the toolbar in action:
2626

2727
.. image:: https://raw.github.com/jazzband/django-debug-toolbar/master/example/django-debug-toolbar.png
28-
:width: 908
29-
:height: 557
28+
:alt: Django Debug Toolbar screenshot
3029

3130
In addition to the built-in panels, a number of third-party panels are
3231
contributed by the community.

debug_toolbar/static/debug_toolbar/css/toolbar.css

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -436,27 +436,6 @@
436436
stroke: #94b24d;
437437
}
438438

439-
#djDebug .djdt-panelContent ul.djdt-stats {
440-
position: relative;
441-
list-style-type: none;
442-
}
443-
#djDebug .djdt-panelContent ul.djdt-stats li {
444-
width: 30%;
445-
float: left;
446-
}
447-
#djDebug .djdt-panelContent ul.djdt-stats li strong.djdt-label {
448-
display: block;
449-
}
450-
#djDebug .djdt-panelContent ul.djdt-stats li span.djdt-color {
451-
height: 12px;
452-
width: 3px;
453-
display: inline-block;
454-
}
455-
#djDebug .djdt-panelContent ul.djdt-stats li span.djdt-info {
456-
display: block;
457-
padding-left: 5px;
458-
}
459-
460439
#djDebug .djdt-panelContent thead th {
461440
white-space: nowrap;
462441
}

debug_toolbar/templates/debug_toolbar/includes/panel_button.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{% load i18n %}
22

3-
<li class="djDebugPanelButton djdt-{{ panel.panel_id }}">
3+
<li id="djdt-{{ panel.panel_id }}" class="djDebugPanelButton">
44
<input type="checkbox" data-cookie="djdt{{ panel.panel_id }}" {% if panel.enabled %}checked title="{% trans "Disable for next and successive requests" %}"{% else %}title="{% trans "Enable for next and successive requests" %}"{% endif %}>
55
{% if panel.has_content and panel.enabled %}
66
<a href="#" title="{{ panel.title }}" class="{{ panel.panel_id }}">

debug_toolbar/templates/debug_toolbar/panels/sql.html

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
{% load i18n l10n %}
22
<div class="djdt-clearfix">
3-
<ul class="djdt-stats">
3+
<ul>
44
{% for alias, info in databases %}
55
<li>
6-
<strong class="djdt-label"><span style="background-color:rgb({{ info.rgb_color|join:', ' }})" class="djdt-color">&#160;</span> {{ alias }}</strong>
7-
<span class="djdt-info">{{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %}
8-
{% if info.similar_count %}
9-
{% blocktrans with count=info.similar_count trimmed %}
10-
including <abbr title="Similar queries are queries with the same SQL, but potentially different parameters.">{{ count }} similar</abbr>
6+
<strong><span style="background-color:rgb({{ info.rgb_color|join:', ' }})" class="djdt-color">&#160;</span> {{ alias }}</strong>
7+
{{ info.time_spent|floatformat:"2" }} ms ({% blocktrans count info.num_queries as num %}{{ num }} query{% plural %}{{ num }} queries{% endblocktrans %}
8+
{% if info.similar_count %}
9+
{% blocktrans with count=info.similar_count trimmed %}
10+
including <abbr title="Similar queries are queries with the same SQL, but potentially different parameters.">{{ count }} similar</abbr>
11+
{% endblocktrans %}
12+
{% if info.duplicate_count %}
13+
{% blocktrans with dupes=info.duplicate_count trimmed %}
14+
and <abbr title="Duplicate queries are identical to each other: they execute exactly the same SQL and parameters.">{{ dupes }} duplicates</abbr>
1115
{% endblocktrans %}
12-
{% if info.duplicate_count %}
13-
{% blocktrans with dupes=info.duplicate_count trimmed %}
14-
and <abbr title="Duplicate queries are identical to each other: they execute exactly the same SQL and parameters.">{{ dupes }} duplicates</abbr>
15-
{% endblocktrans %}
16-
{% endif %}
17-
{% endif %})
18-
</span>
16+
{% endif %}
17+
{% endif %})
1918
</li>
2019
{% endfor %}
2120
</ul>

docs/contributing.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,14 @@ The release itself requires the following steps:
132132

133133
Commit.
134134

135+
#. Update the screenshot in ``README.rst``.
136+
137+
.. code-block:: console
138+
139+
$ make example/django-debug-toolbar.png
140+
141+
Commit.
142+
135143
#. Bump version numbers in ``docs/changes.rst``, ``docs/conf.py``,
136144
``README.rst`` and ``setup.py``. Add the release date to
137145
``docs/changes.rst``. Commit.

example/README.rst

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,36 @@ interfere with common JavaScript frameworks.
1313
How to
1414
------
1515

16-
The test project requires a working installation of Django::
16+
The example project requires a working installation of Django::
1717

1818
$ pip install Django
1919

20-
The following commands must be run from the root directory of a checkout of
21-
the debug toolbar, ie. the directory that contains ``example/``.
20+
The following command must run from the root directory of Django Debug Toolbar,
21+
i.e. the directory that contains ``example/``::
2222

23-
Before running the example for the first time, you must create a database::
23+
$ make example
2424

25-
$ python -m django migrate --settings=example.settings
25+
This will create a database, superuser, and run the Django development server.
26+
The superuser's username will be the same as the current OS user and the
27+
password is "p".
2628

27-
Then you can use the following command to run the example::
29+
If you'd like to run these steps individually, use the following commands.
30+
Again, run from the root directory of Django Debug Toolbar.
2831

29-
$ python -m django runserver --settings=example.settings
32+
Create a database::
33+
34+
$ python example/manage.py migrate
35+
36+
Create a superuser::
37+
38+
$ python example/manage.py createsuperuser
39+
40+
Run the Django development server::
41+
42+
$ python example/manage.py runserver
3043

3144
You can change the database used by specifying the ``DJANGO_DATABASE_ENGINE``
3245
environment variable::
3346

34-
$ DJANGO_DATABASE_ENGINE=postgresql python -m django migrate --settings=example.settings
35-
$ DJANGO_DATABASE_ENGINE=postgresql python -m django runserver --settings=example.settings
36-
47+
$ DJANGO_DATABASE_ENGINE=postgresql python example/manage.py migrate
48+
$ DJANGO_DATABASE_ENGINE=postgresql python example/manage.py runserver

example/django-debug-toolbar.png

-88.8 KB
Loading

example/screenshot.py

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
import argparse
2+
import importlib
3+
import os
4+
import signal
5+
import subprocess
6+
7+
from selenium.webdriver.common.keys import Keys
8+
from selenium.webdriver.support import expected_conditions as EC
9+
from selenium.webdriver.support.wait import WebDriverWait
10+
11+
12+
def parse_args():
13+
parser = argparse.ArgumentParser()
14+
parser.add_argument("--browser", required=True)
15+
parser.add_argument("--headless", action="store_true")
16+
parser.add_argument("--outfile", "-o", required=True)
17+
parser.add_argument("--width", type=int, default=900)
18+
parser.add_argument("--height", type=int, default=700)
19+
return parser.parse_args()
20+
21+
22+
def create_webdriver_options(browser, headless):
23+
mod = importlib.import_module(f"selenium.webdriver.{browser}.options")
24+
options = mod.Options()
25+
if headless:
26+
options.headless = True
27+
return options
28+
29+
30+
def create_webdriver(browser, headless):
31+
mod = importlib.import_module(f"selenium.webdriver.{browser}.webdriver")
32+
return mod.WebDriver(options=create_webdriver_options(browser, headless))
33+
34+
35+
def example_server():
36+
return subprocess.Popen(["make", "example"])
37+
38+
39+
def set_viewport_size(selenium, width, height):
40+
script = """
41+
return [
42+
window.outerWidth - window.innerWidth + arguments[0],
43+
window.outerHeight - window.innerHeight + arguments[1],
44+
];
45+
"""
46+
window_width, window_height = selenium.execute_script(script, width, height)
47+
selenium.set_window_size(window_width, window_height)
48+
49+
50+
def submit_form(selenium, data):
51+
url = selenium.current_url
52+
for name, value in data.items():
53+
el = selenium.find_element_by_name(name)
54+
el.send_keys(value)
55+
el.send_keys(Keys.RETURN)
56+
WebDriverWait(selenium, timeout=5).until(EC.url_changes(url))
57+
58+
59+
def main():
60+
args = parse_args()
61+
with example_server() as p:
62+
try:
63+
with create_webdriver(args.browser, args.headless) as selenium:
64+
set_viewport_size(selenium, args.width, args.height)
65+
66+
selenium.get("http://localhost:8000/admin/login/")
67+
submit_form(selenium, {"username": os.environ["USER"], "password": "p"})
68+
69+
selenium.get("http://localhost:8000/admin/auth/user/")
70+
# Close the admin sidebar.
71+
el = selenium.find_element_by_id("toggle-nav-sidebar")
72+
el.click()
73+
# Open the SQL panel.
74+
el = selenium.find_element_by_id("djdt-SQLPanel")
75+
el.click()
76+
77+
selenium.save_screenshot(args.outfile)
78+
finally:
79+
p.send_signal(signal.SIGTERM)
80+
81+
82+
if __name__ == "__main__":
83+
main()

tests/panels/test_custom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def test_escapes_panel_title(self):
1919
self.assertContains(
2020
response,
2121
"""
22-
<li class="djDebugPanelButton djdt-CustomPanel">
22+
<li id="djdt-CustomPanel" class="djDebugPanelButton">
2323
<input type="checkbox" checked title="Disable for next and successive requests" data-cookie="djdtCustomPanel">
2424
<a class="CustomPanel" href="#" title="Title with special chars &amp;&quot;&#39;&lt;&gt;">
2525
Title with special chars &amp;&quot;&#39;&lt;&gt;

tests/panels/test_settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ def test_panel_title(self):
1212
self.assertContains(
1313
response,
1414
"""
15-
<li class="djDebugPanelButton djdt-SettingsPanel">
15+
<li id="djdt-SettingsPanel" class="djDebugPanelButton">
1616
<input type="checkbox" checked title="Disable for next and successive requests" data-cookie="djdtSettingsPanel">
1717
<a class="SettingsPanel" href="#" title="Settings from None">Settings</a>
1818
</li>

0 commit comments

Comments
 (0)