diff options
author | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-14 23:14:43 (GMT) |
---|---|---|
committer | Rogelio Mita <rogeliomita@activitycentral.com> | 2013-06-14 23:14:43 (GMT) |
commit | e555b7e2d85c42d4de564729088bd6fca7d4a12a (patch) | |
tree | ad6f82d73df3e335c41e0ab333b75a8c60ef97f3 | |
parent | 278f499e4fa26a1b5d301aec9f0f958e4cfe96f8 (diff) |
BugFix: ignore latin-1 charactes and others symbols not matched for js array key
-rw-r--r-- | webapp/polls/models.py | 16 | ||||
-rw-r--r-- | webapp/polls/templatetags/poll_tags.py | 8 | ||||
-rw-r--r-- | webapp/sociologist/views.py | 10 |
3 files changed, 21 insertions, 13 deletions
diff --git a/webapp/polls/models.py b/webapp/polls/models.py index 66c8e25..a0bf45e 100644 --- a/webapp/polls/models.py +++ b/webapp/polls/models.py @@ -21,6 +21,7 @@ from django.core.files.uploadedfile import InMemoryUploadedFile from utils.mongo_connection import get_db from utils.mongo_document import Document +from utils.strings import multiple_replace from pollster.models import Pollster @@ -79,6 +80,21 @@ class Poll(Document, AbstracErrorObject): self.creation_date = data.get('creation_date', None) self.modification_date = data.get('modification_date', None) + @staticmethod + def clean_question(question_name): + new_string = question_name.encode('ascii', 'ignore') + to_replace = [ + (" ", ''), + ("#", ''), + (".", ''), + (":", ''), + ("?", ''), + (",", ''), + ('"', ''), + ("'", '') + ] + return multiple_replace(new_string, to_replace) + def clone(self): clone_data = self.to_python() if clone_data.get('_id', None): diff --git a/webapp/polls/templatetags/poll_tags.py b/webapp/polls/templatetags/poll_tags.py index d8398ae..c28d237 100644 --- a/webapp/polls/templatetags/poll_tags.py +++ b/webapp/polls/templatetags/poll_tags.py @@ -1,9 +1,7 @@ from django import template from django.template.loader import render_to_string -from utils.strings import multiple_replace - -from polls.models import WIDGET_TYPES, WITH_OPTIONS, WITH_IMAGES, Field +from polls.models import WIDGET_TYPES, WITH_OPTIONS, WITH_IMAGES, Field, Poll register = template.Library() @@ -31,6 +29,4 @@ def render_structure(context, structure): @register.filter(name="clean_question") def clean_question(question_name): - to_replace = [(" ", "_"), ("#", ''), (".", "_"), (":", "")] - question_name = question_name.lower() - return multiple_replace(question_name, to_replace) + return Poll.clean_question(question_name) diff --git a/webapp/sociologist/views.py b/webapp/sociologist/views.py index 0a35b7c..64253c5 100644 --- a/webapp/sociologist/views.py +++ b/webapp/sociologist/views.py @@ -10,7 +10,6 @@ from django.template.loader import render_to_string from utils.mongo_connection import get_db from utils.forms import BadFormValidation -from utils.strings import multiple_replace from pollster.models import Pollster from polls.models import Poll, Option @@ -89,11 +88,7 @@ class PollResultListView(ListView): poll_result = self.poll.get_result() - to_replace = [(" ", "_"), ("#", ''), (".", "_"), (":", "")] - clean_field_name = lambda field_name: multiple_replace( - field_name, to_replace) - - questions = map(clean_field_name, self.poll.get_questions()) + questions = map(Poll.clean_question, self.poll.get_questions()) self.poll_type = poll_result.to_python()['poll_type'] @@ -138,7 +133,8 @@ class PollResultListView(ListView): if len(_answers): completed_questions.append(field_data['name']) - field_name = clean_field_name(field_data['name']) + field_name = Poll.clean_question( + field_data['name']) item['answers'].update({ field_name: { "weight": str(_weight), |