From 99f6fa26d716c19662a0cb38191fc8399ed1549d Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Tue, 7 Mar 2023 13:13:33 +0100 Subject: [PATCH 1/4] Don't slugify multiple choice choices and make compatible with Python 3.11 --- .gitignore | 2 + .pre-commit-config.yaml | 16 ++--- pyproject.toml | 58 +++++++++++++++++++ requirements.txt | 7 +++ setup.cfg | 58 ------------------- setup.py | 4 +- survey/exporter/tex/configuration.py | 1 - survey/exporter/tex/question2tex_sankey.py | 3 +- survey/exporter/tex/survey2tex.py | 1 - survey/forms.py | 15 ++--- survey/management/survey_command.py | 1 - survey/migrations/0001_initial.py | 1 - survey/migrations/0002_survey_template.py | 1 - survey/migrations/0003_auto_20170320_0337.py | 1 - .../0004_polymorphic_answers_to_kiss.py | 1 - .../0005_rename_question_related_name.py | 1 - .../0006_add_related_name_for_categories.py | 1 - survey/migrations/0007_auto_20180217_1515.py | 1 - .../0008_translated_name_for_models.py | 1 - survey/migrations/0009_auto_20181211_1908.py | 1 - .../0010_survey_editable_answers.py | 1 - .../0011_survey_publish_duration.py | 1 - .../0012_add_display_by_category.py | 1 - survey/migrations/0013_auto_20200609_0748.py | 1 - survey/migrations/0014_survey_redirect_url.py | 1 - survey/models/answer.py | 1 - survey/models/category.py | 1 - survey/models/question.py | 3 +- survey/models/survey.py | 1 - survey/tests/base_test.py | 1 - .../tests/locale/test_locale_normalization.py | 1 - survey/views/confirm_view.py | 1 - survey/views/survey_completed.py | 1 - 33 files changed, 85 insertions(+), 105 deletions(-) create mode 100644 pyproject.toml create mode 100644 requirements.txt delete mode 100644 setup.cfg diff --git a/.gitignore b/.gitignore index c93c33e7..82e764bc 100644 --- a/.gitignore +++ b/.gitignore @@ -8,6 +8,8 @@ survey.db django_survey_and_report.egg-info/ survey_test/static/ venv/ +.direnv/ +.envrc .idea/ .project .pydevproject diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index d1419ea2..1f496e36 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,14 +3,14 @@ repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.3.0 + rev: v4.4.0 hooks: - id: check-merge-conflict - id: trailing-whitespace - id: end-of-file-fixer - id: check-json - repo: https://github.com/myint/autoflake - rev: v1.4 + rev: v2.0.1 hooks: - id: autoflake args: @@ -20,30 +20,30 @@ repos: - --remove-duplicate-keys - --remove-unused-variables - repo: https://github.com/asottile/pyupgrade - rev: v2.37.3 + rev: v3.3.1 hooks: - id: pyupgrade args: [--py36-plus] - repo: https://github.com/psf/black - rev: 22.6.0 + rev: 23.1.0 hooks: - id: black args: [--line-length, "120"] - repo: https://github.com/Pierre-Sassoulas/black-disable-checker/ - rev: v1.1.1 + rev: v1.1.3 hooks: - id: black-disable-checker - repo: https://github.com/PyCQA/flake8 - rev: 5.0.4 + rev: 6.0.0 hooks: - id: flake8 additional_dependencies: [flake8-bugbear, flake8-typing-imports==1.12.0] - repo: https://github.com/PyCQA/isort - rev: 5.10.1 + rev: 5.12.0 hooks: - id: isort - repo: https://github.com/pre-commit/mirrors-prettier - rev: v2.7.1 + rev: v3.0.0-alpha.6 hooks: - id: prettier args: [--prose-wrap=always, --print-width=88] diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 00000000..78e30a3a --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,58 @@ +[build-system] +requires = ["setuptools>=67.5.1", "wheel"] +build-backend = "setuptools.build_meta" + +[project] +name = "django-survey-and-report" +description = "A django survey app that can export results as CSV or PDF using your native language." +version = "1.4.7" +readme = "README.md" +authors = [ + {email="pierre.sassoulas@gmail.com", name="Pierre SASSOULAS"} +] +license = {text = "AGPL-3.0"} +classifiers = [ + "Development Status :: 5 - Production/Stable", + "Natural Language :: English", + "Natural Language :: Russian", + "Natural Language :: Spanish", + "Natural Language :: French", + "Natural Language :: Japanese", + "Natural Language :: Dutch", + "Natural Language :: Chinese (Traditional)", + "Natural Language :: German", + "Natural Language :: Indonesian", + "Natural Language :: Portuguese", + "Natural Language :: Polish", + "Topic :: Utilities", + "Environment :: Web Environment", + "Intended Audience :: Developers", + "License :: OSI Approved :: GNU Affero General Public License v3", + "Operating System :: OS Independent", + "Programming Language :: Python :: 3.7", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Framework :: Django" +] +dynamic = ["dependencies"] + +[project.urls] +repository = "https://github.com/Pierre-Sassoulas/django-survey" + +[project.optional-dependencies] +dev = [ + "pySankeyBeta~=1.3.0", + "django-rosetta", + "coverage", + "python-coveralls", + "coveralls", + "colorama", + "pylint", + "flake8", + "pre-commit" +] +sankey = [ + "pySankeyBeta~=1.3.0", +] diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 00000000..847a927e --- /dev/null +++ b/requirements.txt @@ -0,0 +1,7 @@ +django>=2.2,<5 +django-bootstrap-form>=3.4 +django-tastypie>=0.14.2 +django-registration>=3.0 +pytz>=2018.9 +ordereddict>=1.1 +pyyaml>=4.2b1 diff --git a/setup.cfg b/setup.cfg deleted file mode 100644 index 0a1322c3..00000000 --- a/setup.cfg +++ /dev/null @@ -1,58 +0,0 @@ -[metadata] -name = django-survey-and-report -version = 1.4.7 -description = A django survey app that can export results as CSV or PDF using your native language. -long_description = file: README.md -long_description_content_type = text/markdown -author = Pierre SASSOULAS -author_email = pierre.sassoulas@gmail.com -license = AGPL-3.0 -url = https://github.com/Pierre-Sassoulas/django-survey -classifiers = - Development Status :: 5 - Production/Stable - Natural Language :: English - Natural Language :: Russian - Natural Language :: Spanish - Natural Language :: French - Natural Language :: Japanese - Natural Language :: Dutch - Natural Language :: Chinese (Traditional) - Natural Language :: German - Natural Language :: Indonesian - Natural Language :: Portuguese - Natural Language :: Polish - Topic :: Utilities - Environment :: Web Environment - Intended Audience :: Developers - License :: OSI Approved :: GNU Affero General Public License v3 - Operating System :: OS Independent - Programming Language :: Python :: 3.7 - Programming Language :: Python :: 3.8 - Programming Language :: Python :: 3.9 - Programming Language :: Python :: 3.10 - Framework :: Django - -[options] -packages = find: -include_package_data = True -install_requires = - django>=2.2,<5 - django-bootstrap-form>=3.4 - django-tastypie>=0.14.2 - django-registration>=3.0 - pytz>=2018.9 - ordereddict>=1.1 - pyyaml>=4.2b1 - -[options.extras_require] -dev = - pySankeyBeta~=1.3.0 - django-rosetta - coverage - python-coveralls - coveralls - colorama - pylint - flake8 - pre-commit -sankey = pySankeyBeta~=1.3.0 diff --git a/setup.py b/setup.py index 60684932..5b8de774 100644 --- a/setup.py +++ b/setup.py @@ -1,3 +1,3 @@ -from setuptools import setup +from setuptools import find_packages, setup -setup() +setup(include_package_data=True, packages=find_packages()) diff --git a/survey/exporter/tex/configuration.py b/survey/exporter/tex/configuration.py index 35620cec..93db6460 100755 --- a/survey/exporter/tex/configuration.py +++ b/survey/exporter/tex/configuration.py @@ -12,7 +12,6 @@ class Configuration: - DEFAULT_PATH = Path(HERE, "default_conf.yaml") def __init__(self, configuration_file=None): diff --git a/survey/exporter/tex/question2tex_sankey.py b/survey/exporter/tex/question2tex_sankey.py index 99923565..e8abbdb7 100755 --- a/survey/exporter/tex/question2tex_sankey.py +++ b/survey/exporter/tex/question2tex_sankey.py @@ -12,7 +12,8 @@ warnings.warn( "Cannot import 'sankey', please install the package using" "the sankey extra. (pip install django-survey-and-report[sankey])" - ": '{}'".format(e) + ": '{}'".format(e), + stacklevel=2, ) SANKEY = False diff --git a/survey/exporter/tex/survey2tex.py b/survey/exporter/tex/survey2tex.py index 63152c79..ce95045c 100755 --- a/survey/exporter/tex/survey2tex.py +++ b/survey/exporter/tex/survey2tex.py @@ -31,7 +31,6 @@ def __init__(self): class Survey2Tex(Survey2X): - ANALYSIS_FUNCTION = [] PGF_PIE_STY = Path(STATIC, "survey", "sty", "pgf-pie.sty") PGF_PLOT_STY = Path(STATIC, "survey", "sty", "pgfplots.sty") diff --git a/survey/forms.py b/survey/forms.py index 668b0495..c6418400 100644 --- a/survey/forms.py +++ b/survey/forms.py @@ -5,7 +5,6 @@ from django.conf import settings from django.forms import models from django.urls import reverse -from django.utils.text import slugify from survey.models import Answer, Category, Question, Response, Survey from survey.signals import survey_completed @@ -15,7 +14,6 @@ class ResponseForm(models.ModelForm): - FIELDS = { Question.TEXT: forms.CharField, Question.SHORT_TEXT: forms.CharField, @@ -165,18 +163,15 @@ def get_question_initial(self, question, data): if answer: # Initialize the field with values from the database if any if question.type == Question.SELECT_MULTIPLE: - initial = [] if answer.body == "[]": - pass - elif "[" in answer.body and "]" in answer.body: initial = [] - unformated_choices = answer.body[1:-1].strip() - for unformated_choice in unformated_choices.split(settings.CHOICES_SEPARATOR): - choice = unformated_choice.split("'")[1] - initial.append(slugify(choice)) + elif answer.body[0] == "[" and answer.body[-1] == "]": + initial = [ + choice.strip(" '") for choice in answer.body.strip("[]").split(settings.CHOICES_SEPARATOR) + ] else: # Only one element - initial.append(slugify(answer.body)) + initial = [answer.body] else: initial = answer.body if data: diff --git a/survey/management/survey_command.py b/survey/management/survey_command.py index e13df813..b681e9cf 100755 --- a/survey/management/survey_command.py +++ b/survey/management/survey_command.py @@ -8,7 +8,6 @@ class SurveyCommand(BaseCommand): - requires_system_checks = [] def add_arguments(self, parser): diff --git a/survey/migrations/0001_initial.py b/survey/migrations/0001_initial.py index fb4fc756..0254731d 100644 --- a/survey/migrations/0001_initial.py +++ b/survey/migrations/0001_initial.py @@ -3,7 +3,6 @@ class Migration(migrations.Migration): - dependencies = [migrations.swappable_dependency(settings.AUTH_USER_MODEL)] operations = [ diff --git a/survey/migrations/0002_survey_template.py b/survey/migrations/0002_survey_template.py index 4aa18689..3b78b7b8 100644 --- a/survey/migrations/0002_survey_template.py +++ b/survey/migrations/0002_survey_template.py @@ -2,7 +2,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0001_initial")] operations = [ diff --git a/survey/migrations/0003_auto_20170320_0337.py b/survey/migrations/0003_auto_20170320_0337.py index c7b15fa2..75d21dca 100644 --- a/survey/migrations/0003_auto_20170320_0337.py +++ b/survey/migrations/0003_auto_20170320_0337.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0002_survey_template")] operations = [ diff --git a/survey/migrations/0004_polymorphic_answers_to_kiss.py b/survey/migrations/0004_polymorphic_answers_to_kiss.py index ccba29d3..2e3674f4 100644 --- a/survey/migrations/0004_polymorphic_answers_to_kiss.py +++ b/survey/migrations/0004_polymorphic_answers_to_kiss.py @@ -16,7 +16,6 @@ def migrate_answers(apps, schema_editor): class Migration(migrations.Migration): - dependencies = [("survey", "0003_auto_20170320_0337")] operations = [ diff --git a/survey/migrations/0005_rename_question_related_name.py b/survey/migrations/0005_rename_question_related_name.py index ff078473..0b560459 100644 --- a/survey/migrations/0005_rename_question_related_name.py +++ b/survey/migrations/0005_rename_question_related_name.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0004_polymorphic_answers_to_kiss")] operations = [ diff --git a/survey/migrations/0006_add_related_name_for_categories.py b/survey/migrations/0006_add_related_name_for_categories.py index 62a272b3..d0d0b1e8 100644 --- a/survey/migrations/0006_add_related_name_for_categories.py +++ b/survey/migrations/0006_add_related_name_for_categories.py @@ -6,7 +6,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0005_rename_question_related_name")] operations = [ diff --git a/survey/migrations/0007_auto_20180217_1515.py b/survey/migrations/0007_auto_20180217_1515.py index f81e1467..5e97892c 100644 --- a/survey/migrations/0007_auto_20180217_1515.py +++ b/survey/migrations/0007_auto_20180217_1515.py @@ -5,7 +5,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0006_add_related_name_for_categories")] operations = [ diff --git a/survey/migrations/0008_translated_name_for_models.py b/survey/migrations/0008_translated_name_for_models.py index 76449020..e6293530 100644 --- a/survey/migrations/0008_translated_name_for_models.py +++ b/survey/migrations/0008_translated_name_for_models.py @@ -7,7 +7,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0007_auto_20180217_1515")] operations = [ diff --git a/survey/migrations/0009_auto_20181211_1908.py b/survey/migrations/0009_auto_20181211_1908.py index 0f83a8cb..d01423c5 100644 --- a/survey/migrations/0009_auto_20181211_1908.py +++ b/survey/migrations/0009_auto_20181211_1908.py @@ -6,7 +6,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0008_translated_name_for_models")] operations = [ diff --git a/survey/migrations/0010_survey_editable_answers.py b/survey/migrations/0010_survey_editable_answers.py index be5e75e5..038a0973 100644 --- a/survey/migrations/0010_survey_editable_answers.py +++ b/survey/migrations/0010_survey_editable_answers.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0009_auto_20181211_1908")] operations = [ diff --git a/survey/migrations/0011_survey_publish_duration.py b/survey/migrations/0011_survey_publish_duration.py index 8ca3d3b6..78f75128 100644 --- a/survey/migrations/0011_survey_publish_duration.py +++ b/survey/migrations/0011_survey_publish_duration.py @@ -7,7 +7,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0010_survey_editable_answers")] operations = [ diff --git a/survey/migrations/0012_add_display_by_category.py b/survey/migrations/0012_add_display_by_category.py index fb351d6e..b7847b15 100644 --- a/survey/migrations/0012_add_display_by_category.py +++ b/survey/migrations/0012_add_display_by_category.py @@ -11,7 +11,6 @@ def convert_bool_to_small_int(apps, _schema_editor): class Migration(migrations.Migration): - dependencies = [("survey", "0011_survey_publish_duration")] operations = [ diff --git a/survey/migrations/0013_auto_20200609_0748.py b/survey/migrations/0013_auto_20200609_0748.py index cf3e5340..c1e43c64 100644 --- a/survey/migrations/0013_auto_20200609_0748.py +++ b/survey/migrations/0013_auto_20200609_0748.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [("survey", "0012_add_display_by_category")] operations = [ diff --git a/survey/migrations/0014_survey_redirect_url.py b/survey/migrations/0014_survey_redirect_url.py index e1ac20e4..cf6b9a71 100644 --- a/survey/migrations/0014_survey_redirect_url.py +++ b/survey/migrations/0014_survey_redirect_url.py @@ -4,7 +4,6 @@ class Migration(migrations.Migration): - dependencies = [ ("survey", "0013_auto_20200609_0748"), ] diff --git a/survey/models/answer.py b/survey/models/answer.py index 74d435fc..63f6a49e 100644 --- a/survey/models/answer.py +++ b/survey/models/answer.py @@ -17,7 +17,6 @@ class Answer(models.Model): - question = models.ForeignKey(Question, on_delete=models.CASCADE, verbose_name=_("Question"), related_name="answers") response = models.ForeignKey(Response, on_delete=models.CASCADE, verbose_name=_("Response"), related_name="answers") created = models.DateTimeField(_("Creation date"), auto_now_add=True) diff --git a/survey/models/category.py b/survey/models/category.py index 6cf6c5c8..0614901f 100644 --- a/survey/models/category.py +++ b/survey/models/category.py @@ -6,7 +6,6 @@ class Category(models.Model): - name = models.CharField(_("Name"), max_length=400) survey = models.ForeignKey(Survey, on_delete=models.CASCADE, verbose_name=_("Survey"), related_name="categories") order = models.IntegerField(_("Display order"), blank=True, null=True) diff --git a/survey/models/question.py b/survey/models/question.py index db38e424..76b7f025 100644 --- a/survey/models/question.py +++ b/survey/models/question.py @@ -46,7 +46,6 @@ class SortAnswer: class Question(models.Model): - TEXT = "text" SHORT_TEXT = "short-text" RADIO = "radio" @@ -373,7 +372,7 @@ def get_choices(self): """ choices_list = [] for choice in self.get_clean_choices(): - choices_list.append((slugify(choice, allow_unicode=True), choice)) + choices_list.append((choice, choice)) choices_tuple = tuple(choices_list) return choices_tuple diff --git a/survey/models/survey.py b/survey/models/survey.py index c95b3386..94981b93 100644 --- a/survey/models/survey.py +++ b/survey/models/survey.py @@ -12,7 +12,6 @@ def in_duration_day(): class Survey(models.Model): - ALL_IN_ONE_PAGE = 0 BY_QUESTION = 1 BY_CATEGORY = 2 diff --git a/survey/tests/base_test.py b/survey/tests/base_test.py index 286814fe..74e6ff09 100755 --- a/survey/tests/base_test.py +++ b/survey/tests/base_test.py @@ -9,7 +9,6 @@ class BaseTest(TestCase): - fixtures = [Path(HERE, "testdump.json")] def setUp(self): diff --git a/survey/tests/locale/test_locale_normalization.py b/survey/tests/locale/test_locale_normalization.py index 8db3ab64..d72d6105 100644 --- a/survey/tests/locale/test_locale_normalization.py +++ b/survey/tests/locale/test_locale_normalization.py @@ -10,7 +10,6 @@ class TestLocaleNormalization(unittest.TestCase): - LOCALE_PATH = Path("survey", "locale").absolute() def test_normalization(self): diff --git a/survey/views/confirm_view.py b/survey/views/confirm_view.py index 3e748e60..e45ac1f8 100644 --- a/survey/views/confirm_view.py +++ b/survey/views/confirm_view.py @@ -4,7 +4,6 @@ class ConfirmView(TemplateView): - template_name = "survey/confirm.html" def get_context_data(self, **kwargs): diff --git a/survey/views/survey_completed.py b/survey/views/survey_completed.py index 58ad522f..5b229f08 100644 --- a/survey/views/survey_completed.py +++ b/survey/views/survey_completed.py @@ -5,7 +5,6 @@ class SurveyCompleted(TemplateView): - template_name = "survey/completed.html" def get_context_data(self, **kwargs): From 3746ea8b685c69663c68945011a88ce4894edd3f Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Tue, 7 Mar 2023 13:35:47 +0100 Subject: [PATCH 2/4] upgrade python/djangon versions in tox.ini --- tox.ini | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/tox.ini b/tox.ini index 1cd4d4dc..0ca7a32f 100644 --- a/tox.ini +++ b/tox.ini @@ -1,26 +1,28 @@ [tox] envlist = - py36-django{22,30}, - py37-django{22,30}, - py38-django{22,30}, + py38-django{32,40,41}, + py39-django{32,40,41}, + py310-django{32,40,41}, + py311-django{32,40,41}, [testenv] commands = python -Wd manage.py test deps = - django22: Django>=2.2a1,<=2.2.99 - django30: Django>=3.0a1,<=3.0.99 + django32: Django>=3.2.0,<3.3.0 + django40: Django>=4.0.0,<4.1.0 + django41: Django>=4.1.0,<4.2.0 django-bootstrap-form>=3.4 django-tastypie>=0.14.2 django-registration>=3. pytz>=2018.9 ordereddict>=1.1 pyyaml>=4.2b1 - pySankeyBeta~=1.2.2 + pySankeyBeta~=1.3.0 django-rosetta [testenv:flake8] basepython = python3 -deps = flake8==2.4.1 +deps = flake8==6.0.0 commands= flake8 {toxinidir}/survey From 223c9d5efe81955c3c78c703201b2b6eb2e76529 Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Tue, 7 Mar 2023 13:41:21 +0100 Subject: [PATCH 3/4] Readd slugify --- survey/forms.py | 14 +++++++++----- survey/models/question.py | 2 +- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/survey/forms.py b/survey/forms.py index c6418400..833961f7 100644 --- a/survey/forms.py +++ b/survey/forms.py @@ -5,6 +5,7 @@ from django.conf import settings from django.forms import models from django.urls import reverse +from django.utils.text import slugify from survey.models import Answer, Category, Question, Response, Survey from survey.signals import survey_completed @@ -163,15 +164,18 @@ def get_question_initial(self, question, data): if answer: # Initialize the field with values from the database if any if question.type == Question.SELECT_MULTIPLE: + initial = [] if answer.body == "[]": + pass + elif "[" in answer.body and "]" in answer.body: initial = [] - elif answer.body[0] == "[" and answer.body[-1] == "]": - initial = [ - choice.strip(" '") for choice in answer.body.strip("[]").split(settings.CHOICES_SEPARATOR) - ] + unformated_choices = answer.body[1:-1].strip() + for unformated_choice in unformated_choices.split(settings.CHOICES_SEPARATOR): + choice = unformated_choice.split("'")[1] + initial.append(slugify(choice)) else: # Only one element - initial = [answer.body] + initial.append(slugify(answer.body)) else: initial = answer.body if data: diff --git a/survey/models/question.py b/survey/models/question.py index 76b7f025..7b08720b 100644 --- a/survey/models/question.py +++ b/survey/models/question.py @@ -372,7 +372,7 @@ def get_choices(self): """ choices_list = [] for choice in self.get_clean_choices(): - choices_list.append((choice, choice)) + choices_list.append((slugify(choice, allow_unicode=True), choice)) choices_tuple = tuple(choices_list) return choices_tuple From d54133de7c15f488dee97ac01420e580b511f2e3 Mon Sep 17 00:00:00 2001 From: Johannes Wilm Date: Tue, 7 Mar 2023 13:43:32 +0100 Subject: [PATCH 4/4] Remove slugify This reverts commit 223c9d5efe81955c3c78c703201b2b6eb2e76529. --- survey/forms.py | 14 +++++--------- survey/models/question.py | 2 +- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/survey/forms.py b/survey/forms.py index 833961f7..c6418400 100644 --- a/survey/forms.py +++ b/survey/forms.py @@ -5,7 +5,6 @@ from django.conf import settings from django.forms import models from django.urls import reverse -from django.utils.text import slugify from survey.models import Answer, Category, Question, Response, Survey from survey.signals import survey_completed @@ -164,18 +163,15 @@ def get_question_initial(self, question, data): if answer: # Initialize the field with values from the database if any if question.type == Question.SELECT_MULTIPLE: - initial = [] if answer.body == "[]": - pass - elif "[" in answer.body and "]" in answer.body: initial = [] - unformated_choices = answer.body[1:-1].strip() - for unformated_choice in unformated_choices.split(settings.CHOICES_SEPARATOR): - choice = unformated_choice.split("'")[1] - initial.append(slugify(choice)) + elif answer.body[0] == "[" and answer.body[-1] == "]": + initial = [ + choice.strip(" '") for choice in answer.body.strip("[]").split(settings.CHOICES_SEPARATOR) + ] else: # Only one element - initial.append(slugify(answer.body)) + initial = [answer.body] else: initial = answer.body if data: diff --git a/survey/models/question.py b/survey/models/question.py index 7b08720b..76b7f025 100644 --- a/survey/models/question.py +++ b/survey/models/question.py @@ -372,7 +372,7 @@ def get_choices(self): """ choices_list = [] for choice in self.get_clean_choices(): - choices_list.append((slugify(choice, allow_unicode=True), choice)) + choices_list.append((choice, choice)) choices_tuple = tuple(choices_list) return choices_tuple