Skip to content

Commit bda95cf

Browse files
committed
Run editor_url logic when retrieving stats
1 parent 418e706 commit bda95cf

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

debug_toolbar/panels/templates/panel.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,13 @@ def generate_stats(self, request, response):
196196
if hasattr(template, "origin") and template.origin and template.origin.name:
197197
template.origin_name = template.origin.name
198198
template.origin_hash = signing.dumps(template.origin.name)
199-
template.editor_url = get_editor_url(template.origin.name)
200199
else:
201-
template.origin_name = _("No origin")
200+
template.origin_name = None
202201
template.origin_hash = ""
203202
info["template"] = {
204203
"name": template.name,
205204
"origin_name": template.origin_name,
206205
"origin_hash": template.origin_hash,
207-
"editor_url": getattr(template, "editor_url", None),
208206
}
209207
# Clean up context for better readability
210208
if self.toolbar.config["SHOW_TEMPLATE_CONTEXT"]:
@@ -241,3 +239,11 @@ def generate_stats(self, request, response):
241239
"context_processors": context_processors,
242240
}
243241
)
242+
243+
def get_stats(self):
244+
stats = super().get_stats()
245+
for template in stats.get("templates", []):
246+
origin_name = template["template"]["origin_name"]
247+
if origin_name:
248+
template["template"]["editor_url"] = get_editor_url(origin_name)
249+
return stats

debug_toolbar/templates/debug_toolbar/panels/templates.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,10 @@ <h4>{% blocktranslate count template_count=templates|length %}Template{% plural
1919
<samp>
2020
{% if template.template.editor_url %}
2121
<a href="{{ template.template.editor_url }}" title="{% translate "Open in editor" %}">{{ template.template.origin_name|addslashes }}</a>
22-
{% else %}
22+
{% elif template.template.origin_name %}
2323
{{ template.template.origin_name|addslashes }}
24+
{% else %}
25+
{% translate "No origin" %}
2426
{% endif %}
2527
</samp>
2628
</dd>

0 commit comments

Comments
 (0)