Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Run editor_url logic when retrieving stats
  • Loading branch information
federicobond committed Dec 4, 2025
commit 50a1c71788ca719070990767af8fbf3ba179c8c7
12 changes: 9 additions & 3 deletions debug_toolbar/panels/templates/panel.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,13 @@ def generate_stats(self, request, response):
if hasattr(template, "origin") and template.origin and template.origin.name:
template.origin_name = template.origin.name
template.origin_hash = signing.dumps(template.origin.name)
template.editor_url = get_editor_url(template.origin.name)
else:
template.origin_name = _("No origin")
template.origin_name = None
template.origin_hash = ""
info["template"] = {
"name": template.name,
"origin_name": template.origin_name,
"origin_hash": template.origin_hash,
"editor_url": getattr(template, "editor_url", None),
}
# Clean up context for better readability
if self.toolbar.config["SHOW_TEMPLATE_CONTEXT"]:
Expand Down Expand Up @@ -241,3 +239,11 @@ def generate_stats(self, request, response):
"context_processors": context_processors,
}
)

def get_stats(self):
stats = super().get_stats()
for template in stats.get("templates", []):
origin_name = template["template"]["origin_name"]
if origin_name:
template["template"]["editor_url"] = get_editor_url(origin_name)
return stats
4 changes: 3 additions & 1 deletion debug_toolbar/templates/debug_toolbar/panels/templates.html
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ <h4>{% blocktranslate count template_count=templates|length %}Template{% plural
<samp>
{% if template.template.editor_url %}
<a href="{{ template.template.editor_url }}" title="{% translate "Open in editor" %}">{{ template.template.origin_name|addslashes }}</a>
{% else %}
{% elif template.template.origin_name %}
{{ template.template.origin_name|addslashes }}
{% else %}
{% translate "No origin" %}
{% endif %}
</samp>
</dd>
Expand Down