mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 09:13:14 +00:00
Cast 'order' field to int so that it works with >10 items
This commit is contained in:
parent
47f2cb57dd
commit
38b2977e9f
2 changed files with 34 additions and 1 deletions
|
|
@ -780,7 +780,7 @@ class BaseStreamBlock(Block):
|
|||
|
||||
values_with_indexes.append(
|
||||
(
|
||||
data['%s-%d-order' % (prefix, i)],
|
||||
int(data['%s-%d-order' % (prefix, i)]),
|
||||
block_type_name,
|
||||
child_block.value_from_datadict(data, files, '%s-%d-value' % (prefix, i)),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -543,3 +543,36 @@ class TestStreamBlock(unittest.TestCase):
|
|||
|
||||
self.assertIn('<input id="__PREFIX__-value-title" name="__PREFIX__-value-title" placeholder="Title" type="text" value="Github" />', html)
|
||||
self.assertIn('<input id="__PREFIX__-value-link" name="__PREFIX__-value-link" placeholder="Link" type="url" value="http://www.github.com" />', html)
|
||||
|
||||
def test_ordering_in_form_submission(self):
|
||||
class ArticleBlock(blocks.StreamBlock):
|
||||
heading = blocks.CharBlock()
|
||||
paragraph = blocks.CharBlock()
|
||||
|
||||
block = ArticleBlock()
|
||||
|
||||
# check that items are ordered by the 'order' field, not the order they appear in the form
|
||||
post_data = {'article-count': '3'}
|
||||
for i in range(0, 3):
|
||||
post_data.update({
|
||||
'article-%d-deleted' % i: '',
|
||||
'article-%d-order' % i: str(2 - i),
|
||||
'article-%d-type' % i: 'heading',
|
||||
'article-%d-value' % i: "heading %d" % i
|
||||
})
|
||||
|
||||
block_value = block.value_from_datadict(post_data, {}, 'article')
|
||||
self.assertEqual(block_value[2].value, "heading 0")
|
||||
|
||||
# check that items are ordered by 'order' numerically, not alphabetically
|
||||
post_data = {'article-count': '12'}
|
||||
for i in range(0, 12):
|
||||
post_data.update({
|
||||
'article-%d-deleted' % i: '',
|
||||
'article-%d-order' % i: str(i),
|
||||
'article-%d-type' % i: 'heading',
|
||||
'article-%d-value' % i: "heading %d" % i
|
||||
})
|
||||
|
||||
block_value = block.value_from_datadict(post_data, {}, 'article')
|
||||
self.assertEqual(block_value[2].value, "heading 2")
|
||||
|
|
|
|||
Loading…
Reference in a new issue