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-08-13 17:54:24 (GMT)
committer Rogelio Mita <rogeliomita@activitycentral.com>2013-08-13 17:54:24 (GMT)
commitfcc7fb22e6d9e112d4ce443faffd3fa2cb6a73ba (patch)
tree8c2ab6e68c09cd88fa739ad17b975dd5035cbda3
parent9706ebab4b562767f0243da92df2891949b7033b (diff)
issue 4429 - BugFix: options col name is ordered by order key from structure of poll
-rw-r--r--webapp/polls/models.py9
-rw-r--r--webapp/polls/tests/result_tests.py24
2 files changed, 22 insertions, 11 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py
index 07c8a9a..919121e 100644
--- a/webapp/polls/models.py
+++ b/webapp/polls/models.py
@@ -417,12 +417,19 @@ class Poll(Document, AbstracErrorObject):
for group_id in sorted_groups:
fields = groups[str(group_id)]['fields']
sorted_fields = sorted(map(lambda x: int(x), fields.keys()))
+
for field_id in sorted_fields:
field = fields[str(field_id)]
+
if field['widget_type'] in ONLY_ANSWER:
header.append(field['name'])
+
elif field['widget_type'] in MANY_ANSWERS:
- for option_id, option in field['options'].iteritems():
+ cmp_ = lambda x, y: cmp(
+ int(x[1]['order']), int(y[1]['order']))
+ sorted_options = sorted(field['options'].items(), cmp_)
+
+ for option_id, option in sorted_options:
col_name = option.get("text", option_id)
header.append(col_name)
diff --git a/webapp/polls/tests/result_tests.py b/webapp/polls/tests/result_tests.py
index 9a646ba..ad7784f 100644
--- a/webapp/polls/tests/result_tests.py
+++ b/webapp/polls/tests/result_tests.py
@@ -153,15 +153,17 @@ class PollResultTests(MongoTestCase):
"dependence": {},
"name": "Q: ImageCheckBox",
"options": {
- "1370786178812": {
- "img_name": "1370786178812.jpg",
- "type": "img_input",
- "weight": 1
- },
"1370786178813": {
"img_name": "1370786178813.jpg",
"type": "img_input",
- "weight": 2
+ "weight": 2,
+ "order": "1"
+ },
+ "1370786178812": {
+ "img_name": "1370786178812.jpg",
+ "type": "img_input",
+ "weight": 1,
+ "order": "2"
}
}
},
@@ -172,11 +174,13 @@ class PollResultTests(MongoTestCase):
"options": {
"1370786178809": {
"text": "option 1",
- "weight": 1
+ "weight": 1,
+ "order": "1"
},
"1370786178810": {
"text": "option 2",
- "weight": 2
+ "weight": 2,
+ "order": "2"
}
}
}
@@ -347,13 +351,13 @@ class PollResultTests(MongoTestCase):
poll_result = PollResult(data=result_data)
expected_header = unicode(
"RUEE;DEPARTAMENTO;NUM_ESC;GRADO;GRUPO;" +
- "TIPO_GRUPO;option 1;option 2;1370786178812;1370786178813;" +
+ "TIPO_GRUPO;option 1;option 2;1370786178813;1370786178812;" +
"Q: TextInput con ácento;Q: RadioButton con ácento;" +
"Q: DropDownList;Q: ImageRadioButton;", 'utf-8')
self.assertEqual(expected_header, poll_result.get_csv_header())
csv = poll_result.to_csv()
- record = "1101236;MONTEVIDEO;236;2;A;1;1;2;1;;some text;1;1;1;"
+ record = "1101236;MONTEVIDEO;236;2;A;1;1;2;;1;some text;1;1;1;"
self.assertTrue(expected_header in csv)
self.assertTrue(record in csv)