Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRogelio Mita <rogeliomita@activitycentral.com>2013-06-14 23:41:25 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-06-14 23:41:25 (GMT)
commit9e8f3452b1183e917b1aca5fa49d3651840a0470 (patch)
tree4f3d65234bb0a6cb699d5ddbd3506e8c177238b1
parente555b7e2d85c42d4de564729088bd6fca7d4a12a (diff)
BugFix: bad converions from unicode to string in poll results to csv.
-rw-r--r--webapp/polls/models.py7
-rw-r--r--webapp/polls/tests/result_tests.py18
2 files changed, 14 insertions, 11 deletions
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()