0001-misc-make-sure-data-sources-with-unicode-are-correct.patch
tests/test_datasource.py | ||
---|---|---|
1 |
# -*- coding: utf-8 -*- |
|
2 | ||
1 | 3 |
import json |
2 | 4 |
import sys |
3 | 5 |
import shutil |
... | ... | |
212 | 214 |
widget = form.get_widget('f1') |
213 | 215 |
assert widget is not None |
214 | 216 |
assert widget.options == [('1', 'un', '1'), ('2', 'deux', '2')] |
217 | ||
218 |
def test_data_source_unicode(): |
|
219 |
NamedDataSource.wipe() |
|
220 |
data_source = NamedDataSource(name='foobar') |
|
221 |
data_source.data_source = {'type': 'formula', 'value': "['uné', 'deux']"} |
|
222 |
data_source.store() |
|
223 | ||
224 |
data_source2 = NamedDataSource.select()[0] |
|
225 |
assert data_source2.data_source == data_source.data_source |
wcs/data_sources.py | ||
---|---|---|
215 | 215 |
def export_data_source_to_xml(self, element, attribute_name, charset): |
216 | 216 |
data_source = getattr(self, attribute_name) |
217 | 217 |
ET.SubElement(element, 'type').text = data_source.get('type') |
218 |
ET.SubElement(element, 'value').text = data_source.get('value') or ''
|
|
218 |
ET.SubElement(element, 'value').text = unicode(data_source.get('value') or '', charset)
|
|
219 | 219 | |
220 | 220 |
def import_data_source_from_xml(self, element, charset): |
221 | 221 |
return { |
222 | 222 |
'type': str(element.find('type').text), |
223 |
'value': str(element.find('value').text),
|
|
223 |
'value': (element.find('value').text or '').encode(charset)
|
|
224 | 224 |
} |
225 | 225 | |
226 | 226 |
def get_by_slug(cls, slug): |
227 |
- |