kopia lustrzana https://github.com/wagtail/wagtail
Fixes UnicodeEncodeError in `wagtailforms`
If you will create form field entry with unicode characters, you will get `UnicodeEncodeError`. This commit fixes this bug.pull/2416/merge
rodzic
d90c2a6c71
commit
4392680067
|
@ -47,6 +47,7 @@ Changelog
|
|||
* Fix: StreamField block controls are no longer hidden by the StreamField menu when prepending a new block (Vincent Audebert)
|
||||
* Fix: Removed invalid use of `__` alias that prevented strings getting picked up for translation (Juha Yrjölä)
|
||||
* Fix: Routable pages without a main view no longer raise a `TypeError` (Bojan Mihelac)
|
||||
* Fix: Fixed UnicodeEncodeError in wagtailforms when downloading a CSV for a form containing non-ASCII field labels on Python 2 (Mikalai Radchuk)
|
||||
|
||||
|
||||
1.4.4 (xx.xx.2016)
|
||||
|
|
|
@ -85,6 +85,7 @@ Bug fixes
|
|||
* StreamField block controls are no longer hidden by the StreamField menu when prepending a new block (Vincent Audebert)
|
||||
* Removed invalid use of ``__`` alias that prevented strings getting picked up for translation (Juha Yrjölä)
|
||||
* :ref:`Routable pages <routable_page_mixin>` without a main view no longer raise a ``TypeError`` (Bojan Mihelac)
|
||||
* Fixed UnicodeEncodeError in wagtailforms when downloading a CSV for a form containing non-ASCII field labels on Python 2 (Mikalai Radchuk)
|
||||
|
||||
|
||||
Upgrade considerations
|
||||
|
|
|
@ -552,7 +552,7 @@ class TestFormsSubmissions(TestCase, WagtailTestUtils):
|
|||
self.assertEqual(data_lines[0], 'Submission date,Your email,Your message,Your choices\r')
|
||||
self.assertEqual(data_lines[1], '2014-01-01 12:00:00+00:00,new@example.com,this is a fairly new message,None\r')
|
||||
|
||||
def test_list_submissions_csv_export_with_unicode(self):
|
||||
def test_list_submissions_csv_export_with_unicode_in_submission(self):
|
||||
unicode_form_submission = FormSubmission.objects.create(
|
||||
page=self.form_page,
|
||||
form_data=json.dumps({
|
||||
|
@ -573,6 +573,39 @@ class TestFormsSubmissions(TestCase, WagtailTestUtils):
|
|||
data_line = response.content.decode('utf-8').split("\n")[1]
|
||||
self.assertIn('こんにちは、世界', data_line)
|
||||
|
||||
def test_list_submissions_csv_export_with_unicode_in_field(self):
|
||||
FormField.objects.create(
|
||||
page=self.form_page,
|
||||
sort_order=2,
|
||||
label="Выберите самую любимую IDE для разработке на Python",
|
||||
help_text="Вы можете выбрать только один вариант",
|
||||
field_type='radio',
|
||||
required=True,
|
||||
choices='PyCharm,vim,nano',
|
||||
)
|
||||
unicode_form_submission = FormSubmission.objects.create(
|
||||
page=self.form_page,
|
||||
form_data=json.dumps({
|
||||
'your-email': "unicode@example.com",
|
||||
'your-message': "We don\'t need unicode here",
|
||||
'vyberite-samuiu-liubimuiu-ide-dlia-razrabotke-na-python': "vim",
|
||||
}),
|
||||
)
|
||||
unicode_form_submission.submit_time = '2014-01-02T12:00:00.000Z'
|
||||
unicode_form_submission.save()
|
||||
|
||||
response = self.client.get(
|
||||
reverse('wagtailforms:list_submissions', args=(self.form_page.id, )),
|
||||
{'date_from': '01/02/2014', 'action': 'CSV'}
|
||||
)
|
||||
|
||||
# Check response
|
||||
self.assertEqual(response.status_code, 200)
|
||||
|
||||
data_lines = response.content.decode('utf-8').split("\n")
|
||||
self.assertIn('Выберите самую любимую IDE для разработке на Python', data_lines[0])
|
||||
self.assertIn('vim', data_lines[1])
|
||||
|
||||
|
||||
class TestDeleteFormSubmission(TestCase):
|
||||
fixtures = ['test.json']
|
||||
|
|
|
@ -80,7 +80,7 @@ def list_submissions(request, page_id):
|
|||
|
||||
writer = csv.writer(response)
|
||||
|
||||
header_row = ['Submission date'] + [label for name, label in data_fields]
|
||||
header_row = ['Submission date'] + [smart_str(label) for name, label in data_fields]
|
||||
|
||||
writer.writerow(header_row)
|
||||
for s in submissions:
|
||||
|
|
Ładowanie…
Reference in New Issue