From 4e3298e9d3cf87f74da8ed99a91efe56652d7a03 Mon Sep 17 00:00:00 2001 From: Rogelio Mita Date: Wed, 12 Jun 2013 16:32:32 +0000 Subject: Bug fix: Text for TextInput fields when export to csv --- (limited to 'webapp') 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) -- cgit v0.9.1