From 9e8f3452b1183e917b1aca5fa49d3651840a0470 Mon Sep 17 00:00:00 2001 From: Rogelio Mita Date: Fri, 14 Jun 2013 23:41:25 +0000 Subject: BugFix: bad converions from unicode to string in poll results to csv. --- (limited to 'webapp') diff --git a/webapp/polls/models.py b/webapp/polls/models.py index a0bf45e..f4d9153 100644 --- a/webapp/polls/models.py +++ b/webapp/polls/models.py @@ -1246,7 +1246,7 @@ class PollResult(AbstractObject): results = [] for index_record, respuesta in self._data["result"].iteritems(): - aux = dict([(str(x), "") for x in header_order]) + aux = dict([(x, "") for x in header_order]) for key, value in respuesta['polled'].iteritems(): if key in header_order: @@ -1256,12 +1256,13 @@ class PollResult(AbstractObject): for index_preg, data_preg in data_group['fields'].iteritems(): widget_type = data_preg['widget_type'] name = data_preg['name'] + name = unicode(name, "utf-8") if isinstance( + name, str) else name answer = data_preg['answer'] if len(answer) and widget_type in ONLY_ANSWER: if widget_type == "TextInput": - aux[name] = str( - answer.values()[0].get("text", "-")) + aux[name] = answer.values()[0].get("text", "-") else: aux[name] = str( answer.values()[0].get("weight", "-")) diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py index b86b6f7..d34858e 100644 --- a/webapp/polls/tests/result_tests.py +++ b/webapp/polls/tests/result_tests.py @@ -188,7 +188,7 @@ class PollResultTests(MongoTestCase): "1": { "widget_type": "RadioButton", "dependence": {}, - "name": "Q: RadioButton", + "name": "Q: RadioButton con ácento", "options": { "1370786178803": { "text": "option 2", @@ -202,7 +202,7 @@ class PollResultTests(MongoTestCase): }, "0": { "widget_type": "TextInput", - "name": "Q: TextInput", + "name": "Q: TextInput con ácento", "options": {} }, "3": { @@ -265,7 +265,7 @@ class PollResultTests(MongoTestCase): "text": "some text" } }, - "name": "Q: TextInput", + "name": "Q: TextInput con ácento", "widget_type": "TextInput" }, "1": { @@ -275,7 +275,7 @@ class PollResultTests(MongoTestCase): "weight": 1 } }, - "name": "Q: RadioButton", + "name": "Q: RadioButton con ácento", "widget_type": "RadioButton" }, "2": { @@ -346,10 +346,12 @@ class PollResultTests(MongoTestCase): poll_result = PollResult(data=result_data) - expected_header = "RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" + \ - "TIPO_GRUPO;Q: TextInput;Q: RadioButton;Q: DropDownList;" + \ - "Q: ImageRadioButton;1370786178809;1370786178810;" + \ - "1370786178812;1370786178813;" + expected_header = unicode( + "RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" + + "TIPO_GRUPO;Q: TextInput con ácento;Q: RadioButton con ácento;" + + "Q: DropDownList;" + + "Q: ImageRadioButton;1370786178809;1370786178810;" + + "1370786178812;1370786178813;", 'utf-8') self.assertEqual(expected_header, poll_result.get_csv_header()) csv = poll_result.to_csv() -- cgit v0.9.1