diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-04-24 21:00:38 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-04-24 21:00:38 (GMT) |
commit | e74a4c36b257bcde9ea63f1f5599b51b5a620647 (patch) | |
tree | d5878515135760d93c751526aa8b8a36f61ce006 /webapp/polls/views.py | |
parent | 412c023380840f19325578289ee9fc8eb5f9151b (diff) |
Merge partial files for poll results upload
Diffstat (limited to 'webapp/polls/views.py')
-rw-r--r-- | webapp/polls/views.py | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/webapp/polls/views.py b/webapp/polls/views.py index 6e58ecb..70d83d4 100644 --- a/webapp/polls/views.py +++ b/webapp/polls/views.py @@ -319,10 +319,24 @@ class UnploadPollResultFormView(TemplateView): json_dst.seek(0) to_json.append(json.load(json_dst, 'utf-8')) - # TODO: Merge all data in to_json - merged_data = to_json[0] + # Validation: Partial files of same poll! + fields_to_compare = ['poll_id', 'pollster_id', 'poll_type'] + valid_data = {} + for to_compare in fields_to_compare: + comparation = to_json[0].get(to_compare, None) + valid_data[to_compare] = comparation + + for data in to_json[1:]: + for to_compare in fields_to_compare: + _value = data.get(to_compare, None) + if _value != valid_data[to_compare]: + msg = u'Los resultados parciales no pertenecen \ + a una misma encuesta.' + messages.add_message( + self.request, messages.ERROR, msg) + return self.render_to_response(context) - poll_result = PollResult(merged_data) + poll_result = PollResult(to_json) poll = poll_result.get_poll() pollster = Pollster.get_by_user_id(request.user.id) @@ -355,7 +369,7 @@ class UnploadPollResultFormView(TemplateView): with open(file_name, 'wb+') as dst: dst.write( json.dumps( - merged_data, + to_json, sort_keys=True, indent=4, separators=(',', ': ') |