diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cc743cfa44..3cbffed635 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -26,6 +26,7 @@ Changelog * Fix: "Your recent edits" list on dashboard no longer leaves out pages that another user has subsequently edited (Michael Cordover, Kees Hink, João Luiz Lorencetti) * Fix: `InlinePanel` now accepts a `classname` parameter as per the documentation (emg36, Matt Westcott) * Fix: Disabled use of escape key to revert content of rich text fields, which could cause accidental data loss (Matt Westcott) + * Fix: Setting `USE_THOUSAND_SEPARATOR = True` no longer breaks the rendering of numbers in JS code for InlinePanel (Mattias Loverot, Matt Westcott) 1.6.3 (XX.XX.2016) diff --git a/CONTRIBUTORS.rst b/CONTRIBUTORS.rst index a774719478..fa776aa306 100644 --- a/CONTRIBUTORS.rst +++ b/CONTRIBUTORS.rst @@ -169,6 +169,7 @@ Contributors * emg36 * Stein Strindhaug * Žan Anderle +* Mattias Loverot Translators =========== diff --git a/docs/releases/1.7.rst b/docs/releases/1.7.rst index b1e322c90a..2093813b0a 100644 --- a/docs/releases/1.7.rst +++ b/docs/releases/1.7.rst @@ -61,6 +61,7 @@ Bug fixes * "Your recent edits" list on dashboard no longer leaves out pages that another user has subsequently edited (Michael Cordover, Kees Hink, João Luiz Lorencetti) * ``InlinePanel`` now accepts a ``classname`` parameter as per the documentation (emg36, Matt Westcott) * Disabled use of escape key to revert content of rich text fields, which could cause accidental data loss (Matt Westcott) + * Setting ``USE_THOUSAND_SEPARATOR = True`` no longer breaks the rendering of numbers in JS code for InlinePanel (Mattias Loverot, Matt Westcott) Upgrade considerations diff --git a/wagtail/wagtailadmin/templates/wagtailadmin/edit_handlers/inline_panel.js b/wagtail/wagtailadmin/templates/wagtailadmin/edit_handlers/inline_panel.js index 0663564c7e..6b7a33c2fd 100644 --- a/wagtail/wagtailadmin/templates/wagtailadmin/edit_handlers/inline_panel.js +++ b/wagtail/wagtailadmin/templates/wagtailadmin/edit_handlers/inline_panel.js @@ -1,9 +1,10 @@ +{% load wagtailadmin_tags %} (function() { var panel = InlinePanel({ formsetPrefix: "id_{{ self.formset.prefix }}", emptyChildFormPrefix: "{{ self.empty_child.form.prefix }}", canOrder: {% if can_order %}true{% else %}false{% endif %}, - maxForms: {{ self.formset.max_num }} + maxForms: {{ self.formset.max_num|no_thousand_separator }} }); {% for child in self.children %} diff --git a/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py b/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py index c8d01ff719..c0875462c1 100644 --- a/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py +++ b/wagtail/wagtailadmin/templatetags/wagtailadmin_tags.py @@ -78,6 +78,14 @@ def ellipsistrim(value, max_length): return value +@register.filter +def no_thousand_separator(num): + """ + Prevent USE_THOUSAND_SEPARATOR from automatically inserting a thousand separator on this value + """ + return str(num) + + @register.filter def fieldtype(bound_field): try: diff --git a/wagtail/wagtailadmin/tests/test_edit_handlers.py b/wagtail/wagtailadmin/tests/test_edit_handlers.py index 8fac3cd3d5..c643ccc7fe 100644 --- a/wagtail/wagtailadmin/tests/test_edit_handlers.py +++ b/wagtail/wagtailadmin/tests/test_edit_handlers.py @@ -6,7 +6,7 @@ import mock from django import forms from django.core import checks from django.core.exceptions import ImproperlyConfigured -from django.test import TestCase +from django.test import TestCase, override_settings from wagtail.tests.testapp.forms import ValidatedPageForm from wagtail.tests.testapp.models import ( @@ -750,6 +750,27 @@ class TestInlinePanel(TestCase, WagtailTestUtils): # render_js_init must provide the JS initializer self.assertIn('var panel = InlinePanel({', panel.render_js_init()) + @override_settings(USE_L10N=True, USE_THOUSAND_SEPARATOR=True) + def test_no_thousand_separators_in_js(self): + """ + Test that the USE_THOUSAND_SEPARATOR setting does not screw up the rendering of numbers + (specifically maxForms=1000) in the JS initializer: + https://github.com/torchbox/wagtail/pull/2699 + """ + SpeakerObjectList = ObjectList([ + InlinePanel('speakers', label="Speakers", panels=[ + FieldPanel('first_name', widget=forms.Textarea), + ImageChooserPanel('image'), + ]), + ]).bind_to_model(EventPage) + SpeakerInlinePanel = SpeakerObjectList.children[0] + EventPageForm = SpeakerObjectList.get_form_class(EventPage) + event_page = EventPage.objects.get(slug='christmas') + form = EventPageForm(instance=event_page) + panel = SpeakerInlinePanel(instance=event_page, form=form) + + self.assertIn('maxForms: 1000', panel.render_js_init()) + def test_invalid_inlinepanel_declaration(self): with self.ignore_deprecation_warnings(): self.assertRaises(TypeError, lambda: InlinePanel(label="Speakers"))