kopia lustrzana https://github.com/wagtail/wagtail
Prevent USE_THOUSAND_SEPARATOR from breaking the rendering of maxForms in InlinePanel's JS code
Fixes #2699. Thanks to Mattias Loverot for the report and original fix.pull/3019/head
rodzic
5869bc37bb
commit
674af5586b
|
@ -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)
|
||||
|
|
|
@ -169,6 +169,7 @@ Contributors
|
|||
* emg36
|
||||
* Stein Strindhaug
|
||||
* Žan Anderle
|
||||
* Mattias Loverot
|
||||
|
||||
Translators
|
||||
===========
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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"))
|
||||
|
|
Ładowanie…
Reference in New Issue