Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit 433f671

Browse files
committed
Fixed #23 -- Changed hardcoded admin index URL.
Refactored the code to dynamically get the admin index URL by leveraging the json_script templates tag.
1 parent 0e5156b commit 433f671

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

django_admin_keyboard_shortcuts/static/admin/js/shortcuts.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,17 @@ function isFocusedTextField() {
1111
{
1212
let previousKey = undefined;
1313
const shortcutFunctions = new Map([
14-
["g i", () => { document.location.href = "/admin/"; }],
14+
["g i", () => {
15+
// Get the admin index URL from the json_script element
16+
const adminIndexElement = document.getElementById('admin-index-url');
17+
if (adminIndexElement) {
18+
const adminIndexUrl = JSON.parse(adminIndexElement.textContent);
19+
document.location.href = adminIndexUrl;
20+
} else {
21+
// Fallback to default if element not found
22+
document.location.href = "/admin/";
23+
}
24+
}],
1525
["g l", () => showDialog("model-list-dialog")]
1626
]);
1727

django_admin_keyboard_shortcuts/templates/admin/base.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
{% block extrahead %}
55
{{ block.super }}
66
{% block extrahead_shortcuts %}
7+
{% url 'admin:index' as admin_index_url %}
8+
{{ admin_index_url|json_script:"admin-index-url" }}
79
<link rel="stylesheet" href="{% static "admin/css/shortcuts.css" %}">
810
<script src="{% static "admin/js/shortcuts.js" %}" async></script>
911
{% endblock %}

0 commit comments

Comments
 (0)