diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-12 16:32:32 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-12 17:53:01 (GMT) |
commit | 4e3298e9d3cf87f74da8ed99a91efe56652d7a03 (patch) | |
tree | ffb3d2aee4d799a1cb0fa1c612001efd60edda51 | |
parent | 20f31a8438696a968d6217e117dfb7957b3c298c (diff) |
Bug fix: Text for TextInput fields when export to csv
-rw-r--r-- | webapp/polls/models.py | 9 | ||||
-rw-r--r-- | webapp/polls/tests/result_tests.py | 4 |
2 files changed, 8 insertions, 5 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py index 4c9a9f1..75d75a0 100644 --- a/webapp/polls/models.py +++ b/webapp/polls/models.py @@ -1230,7 +1230,7 @@ class PollResult(AbstractObject): results = [] for index_record, respuesta in self._data["result"].iteritems(): - aux = dict([(x, "None") for x in header_order]) + aux = dict([(str(x), "") for x in header_order]) for key, value in respuesta['polled'].iteritems(): if key in header_order: @@ -1243,7 +1243,10 @@ class PollResult(AbstractObject): answer = data_preg['answer'] if len(answer) and widget_type in ONLY_ANSWER: - aux[name] = str(answer.values()[0].get("weight", "-")) + if widget_type == "TextInput": + aux[name] = str(answer.values()[0].get("text", "-")) + else: + aux[name] = str(answer.values()[0].get("weight", "-")) elif len(answer) and widget_type in MANY_ANSWERS: for opt_id, opt_value in answer.iteritems(): aux[opt_id] = str(opt_value.get("weight", "-")) @@ -1251,7 +1254,7 @@ class PollResult(AbstractObject): record = [] for key in header_order: record.append(aux[key]) - record = ";".join(record).replace("None", "") + record = ";".join(record) results.append(record) return poll_csv_header + "\n" + ";\n".join(results) diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py index c8b2ee3..b86b6f7 100644 --- a/webapp/polls/tests/result_tests.py +++ b/webapp/polls/tests/result_tests.py @@ -265,7 +265,7 @@ class PollResultTests(MongoTestCase): "text": "some text" } }, - "name": "Q: TextIntup", + "name": "Q: TextInput", "widget_type": "TextInput" }, "1": { @@ -353,6 +353,6 @@ class PollResultTests(MongoTestCase): self.assertEqual(expected_header, poll_result.get_csv_header()) csv = poll_result.to_csv() - record = "1101236;MONTEVIDEO;236;2;A;1;;1;1;1;1;2;1;;" + record = "1101236;MONTEVIDEO;236;2;A;1;some text;1;1;1;1;2;1;;" self.assertTrue(expected_header in csv) self.assertTrue(record in csv) |