Skip to content

Commit 79b6db9

Browse files
committed
Prevent double submission on template change
- Disable all submit buttons (input and button elements) immediately after triggering save when template is changed in the admin interface - Add regression test that verifies the fix is present in item_editor.js - Test uses BASEDIR from settings for robust path construction This prevents users from accidentally submitting the form twice while the page is reloading after a template change.
1 parent 19420d7 commit 79b6db9

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

feincms/static/feincms/item_editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -537,7 +537,7 @@
537537
invoked. See Issue #372 */
538538
form_element.find("[type=submit][name=_save]").click()
539539
/* Disable all submit buttons to prevent double submission while page reloads */
540-
form_element.find("input[type=submit]").attr("disabled", "disabled")
540+
form_element.find("input[type=submit], button").attr("disabled", "disabled")
541541
} else {
542542
// Restore original value
543543
form_element.val($(this).data("original_value"))

tests/testapp/tests/test_template_change_fix.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"""
66

77
import os
8+
from django.conf import settings
89
from django.test import TestCase
910

1011

@@ -13,21 +14,19 @@ class TemplateChangeFixTest(TestCase):
1314

1415
def test_fix_is_present_in_javascript(self):
1516
"""Verify that the fix line exists in item_editor.js"""
16-
# Get the path to the JavaScript file
17-
base_dir = os.path.dirname(
18-
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
19-
)
17+
# Use BASEDIR from settings to construct the path
2018
js_file_path = os.path.join(
21-
base_dir, "feincms", "static", "feincms", "item_editor.js"
19+
settings.BASEDIR, '..', '..', 'feincms', 'static', 'feincms', 'item_editor.js'
2220
)
21+
js_file_path = os.path.normpath(js_file_path)
2322

2423
# Read the file
2524
with open(js_file_path, "r") as f:
2625
content = f.read()
2726

2827
# Check that the fix is present
2928
self.assertIn(
30-
'form_element.find("input[type=submit]").attr("disabled", "disabled")',
29+
'form_element.find("input[type=submit], button").attr("disabled", "disabled")',
3130
content,
3231
"The double submission fix should be present in item_editor.js",
3332
)
@@ -48,23 +47,18 @@ def test_fix_is_present_in_javascript(self):
4847

4948
def test_fix_order_is_correct(self):
5049
"""Verify that the disable happens AFTER the click, not before."""
51-
base_dir = os.path.dirname(
52-
os.path.dirname(os.path.dirname(os.path.dirname(__file__)))
53-
)
50+
base_dir = os.path.dirname(os.path.dirname(os.path.dirname(os.path.dirname(__file__))))
5451
js_file_path = os.path.join(
55-
base_dir, "feincms", "static", "feincms", "item_editor.js"
52+
base_dir, 'feincms', 'static', 'feincms', 'item_editor.js'
5653
)
54+
js_file_path = os.path.normpath(js_file_path)
5755

5856
with open(js_file_path, "r") as f:
5957
content = f.read()
6058

6159
# Find positions of both statements
62-
click_pos = content.find(
63-
'form_element.find("[type=submit][name=_save]").click()'
64-
)
65-
disable_pos = content.find(
66-
'form_element.find("input[type=submit]").attr("disabled", "disabled")'
67-
)
60+
click_pos = content.find('form_element.find("[type=submit][name=_save]").click()')
61+
disable_pos = content.find('form_element.find("input[type=submit]").attr("disabled", "disabled")')
6862

6963
self.assertGreater(click_pos, 0, "The click() statement should be present")
7064
self.assertGreater(disable_pos, 0, "The disable statement should be present")

0 commit comments

Comments
 (0)