From 090d6eb078996a7d3f9c79a8e59e0a7ddf881b11 Mon Sep 17 00:00:00 2001 From: Pierre Sassoulas Date: Tue, 19 Dec 2023 19:08:41 +0100 Subject: [PATCH] Upgrade interpreters, tool, dependencies (#183) * Upgrade python interpreters * Put ruff into place * Put pylint and pylint django into place * Update locale --- .flake8 | 8 --- .github/workflows/ci.yml | 9 +-- .github/workflows/release.yaml | 2 +- .isort.cfg | 6 -- .pre-commit-config.yaml | 54 +++++++++--------- .pylintrc | 22 -------- CONTRIBUTING.md | 2 +- example_project/manage.py | 4 +- pyproject.toml | 55 ++++++++++++++++++- survey/__init__.py | 1 + survey/exporter/survey2x.py | 6 +- survey/exporter/tex/question2tex_chart.py | 2 +- survey/exporter/tex/question2tex_sankey.py | 2 +- survey/exporter/tex/survey2tex.py | 15 ++--- survey/locale/de/LC_MESSAGES/django.po | 14 ++--- survey/locale/es/LC_MESSAGES/django.po | 14 ++--- survey/locale/fr/LC_MESSAGES/django.po | 14 ++--- survey/locale/gr/LC_MESSAGES/django.po | 14 ++--- survey/locale/id/LC_MESSAGES/django.po | 14 ++--- survey/locale/ja/LC_MESSAGES/django.po | 14 ++--- survey/locale/nl/LC_MESSAGES/django.po | 14 ++--- survey/locale/pl/LC_MESSAGES/django.po | 14 ++--- survey/locale/pt/LC_MESSAGES/django.po | 14 ++--- survey/locale/ru/LC_MESSAGES/django.po | 14 ++--- survey/locale/tr/LC_MESSAGES/django.po | 14 ++--- survey/locale/zh/LC_MESSAGES/django.po | 14 ++--- survey/models/answer.py | 8 +-- survey/models/question.py | 9 +-- survey/models/response.py | 8 +-- survey/tests/base_test.py | 2 +- survey/tests/exporter/test_survey2x.py | 6 +- .../exporter/tex/test_question2tex_sankey.py | 23 ++++---- .../management/commands/test_exportresult.py | 5 +- survey/tests/management/test_management.py | 10 ++-- survey/views/survey_detail.py | 2 +- 35 files changed, 218 insertions(+), 211 deletions(-) delete mode 100644 .flake8 delete mode 100644 .isort.cfg diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 2080770d..00000000 --- a/.flake8 +++ /dev/null @@ -1,8 +0,0 @@ -[flake8] -exclude = - .git, - __pycache__, - build, - dist -max-line-length = 120 -max-complexity = 10 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index efef2b7f..1422294d 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -11,7 +11,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: [3.8, 3.9, "3.10", "3.11"] + python-version: [3.8, 3.9, "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v2 - name: Python ${{ matrix.python-version }} @@ -20,12 +20,10 @@ jobs: python-version: ${{ matrix.python-version }} - name: Install dependencies run: | + sudo apt-get update sudo apt-get install -yqq texlive-latex-base gettext texlive-pictures texlive-latex-extra sudo apt-get install -yqq texlive-xetex libblas-dev liblapack-dev libatlas-base-dev gfortran pip3 install -e ".[dev]" - - name: Lint - run: | - pre-commit run --all-files - name: Test env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} @@ -34,3 +32,6 @@ jobs: coverage run --source=survey --omit=survey/migrations/* ./manage.py test coverage html coveralls debug --service=github + - name: pylint + run: | + pre-commit run pylint --all-files diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 5217fae7..f59c5f32 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -6,7 +6,7 @@ on: - published env: - DEFAULT_PYTHON: 3.9 + DEFAULT_PYTHON: 3.11 jobs: release-pypi: diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index ff4b4e30..00000000 --- a/.isort.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[settings] -multi_line_output=3 -line_length=120 -known_third_party = django,mock,pandas,pysankey,pytz,setuptools,yaml -known_first_party = survey -include_trailing_comma=True diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 1f496e36..df4993de 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -1,31 +1,21 @@ -#ci: -# skip: [pylint] +ci: + skip: [pylint] repos: - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.4.0 + rev: v4.5.0 hooks: - id: check-merge-conflict - id: trailing-whitespace - id: end-of-file-fixer - id: check-json - - repo: https://github.com/myint/autoflake - rev: v2.0.1 + - repo: https://github.com/astral-sh/ruff-pre-commit + rev: "v0.1.8" hooks: - - id: autoflake - args: - - --in-place - - --remove-all-unused-imports - - --expand-star-imports - - --remove-duplicate-keys - - --remove-unused-variables - - repo: https://github.com/asottile/pyupgrade - rev: v3.3.1 - hooks: - - id: pyupgrade - args: [--py36-plus] + - id: ruff + args: ["--fix"] - repo: https://github.com/psf/black - rev: 23.1.0 + rev: 23.12.0 hooks: - id: black args: [--line-length, "120"] @@ -33,18 +23,26 @@ repos: rev: v1.1.3 hooks: - id: black-disable-checker - - repo: https://github.com/PyCQA/flake8 - 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.12.0 - hooks: - - id: isort - repo: https://github.com/pre-commit/mirrors-prettier - rev: v3.0.0-alpha.6 + rev: v3.1.0 hooks: - id: prettier args: [--prose-wrap=always, --print-width=88] exclude: "survey/static/|dev/templates/|survey/templates/|survey/locale/|survey/tests/" + - repo: local + hooks: + - id: pylint + name: pylint + entry: pylint + language: system + types: [python] + args: + [ + "-rn", + "-sn", + "--rcfile=pyproject.toml", + "--django-settings-module=settings", + "--load-plugins=pylint_django", + "--fail-on=I", + ] + exclude: "survey/migrations/" diff --git a/.pylintrc b/.pylintrc index 7ac22821..e69de29b 100644 --- a/.pylintrc +++ b/.pylintrc @@ -1,22 +0,0 @@ -[MASTER] -# Python code to execute, usually for sys.path manipulation such as pygtk.require(). -init-hook=import sys; sys.path.insert(0, 'survey');sys.path.insert(0, 'venv/lib/python3.7/site-packages/'); - -[MESSAGES CONTROL] -# I0011 Warning locally suppressed using disable-msg -disable= - I0011, - no-member, - missing-docstring, # We don't want docstring everywhere - C0330, # black handle this - too-few-public-methods, # More harmful than beneficial in django project - too-many-arguments, - -ignore=migrations - -[BASIC] -# Good variable names which should always be accepted, separated by a comma. -good-names=i,j,k,ex,Run,_,f,e,maxDiff - -[FORMAT] -max-line-length=120 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index e57cf17a..3e263368 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -86,7 +86,7 @@ python manage.py runserver # Then go to http://localhost:8000/rosetta to translate python manage.py makemessages --no-obsolete --no-wrap --ignore venv --locale de \ --locale es --locale fr --locale id --locale ja --locale nl --locale pl \ - --locale pt --locale ru --locale tr --locale zh + --locale pt --locale ru --locale tr --locale zh --locale gr git add survey/locale/ ... ``` diff --git a/example_project/manage.py b/example_project/manage.py index 5ea5a516..0e37d048 100644 --- a/example_project/manage.py +++ b/example_project/manage.py @@ -14,11 +14,11 @@ import django print(django.__version__) - except ImportError: + except ImportError as e: raise ImportError( "Couldn't import Django. Are you sure it's installed and " "available on your PYTHONPATH environment variable? Did you " "forget to activate a virtual environment?" - ) + ) from e raise execute_from_command_line(sys.argv) diff --git a/pyproject.toml b/pyproject.toml index 5566938b..1a48a791 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -29,11 +29,11 @@ classifiers = [ "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", + "Programming Language :: Python :: 3.12", "Framework :: Django" ] dynamic = ["dependencies"] @@ -50,7 +50,7 @@ dev = [ "coveralls", "colorama", "pylint", - "flake8", + "pylint-django", "pre-commit" ] sankey = [ @@ -59,3 +59,54 @@ sankey = [ [tool.setuptools.dynamic] dependencies = {file = "requirements.txt"} + +[tool.ruff] + +line-length = 120 + +select = [ + "E", # pycodestyle + "F", # pyflakes + "W", # pycodestyle + "B", # bugbear + "I", # isort + "RUF", # ruff + "UP", # pyupgrade +] + +ignore = [ + "RUF012", # mutable default values in class attributes +] + +[tool.pylint.main] +load-plugins ="pylint_django" + +disable=[ + # I0011 Warning locally suppressed using disable-msg + "I0011", + "no-member", + "missing-docstring", # We don't want docstring everywhere + "too-few-public-methods", # More harmful than beneficial in django project + "too-many-arguments", + "too-many-instance-attributes", + # TODO Fix + "unspecified-encoding", + "inconsistent-return-statements", + "consider-using-with", + "fixme", + "no-else-return", + "imported-auth-user", + "unused-argument", + "arguments-differ", + "consider-using-f-string", + "too-many-branches", + "redefined-builtin", + "superfluous-parens", + "useless-parent-delegation", + "unused-private-member", + "duplicate-code", + "attribute-defined-outside-init", +] +ignore="migrations" +good-names="i,j,k,ex,Run,_,f,e,maxDiff" +max-line-length = 120 diff --git a/survey/__init__.py b/survey/__init__.py index 6175ddfa..463902ef 100644 --- a/survey/__init__.py +++ b/survey/__init__.py @@ -14,6 +14,7 @@ def set_default_settings(): try: + # pylint: disable=import-outside-toplevel from django.conf import settings from . import settings as app_settings diff --git a/survey/exporter/survey2x.py b/survey/exporter/survey2x.py index 760d83fc..63d42f8a 100755 --- a/survey/exporter/survey2x.py +++ b/survey/exporter/survey2x.py @@ -38,8 +38,8 @@ def directory(self): directory_name = f"{self.mime_type.upper()}_DIRECTORY" try: self.__directory = str(Path(getattr(settings, directory_name)).absolute()) - except AttributeError: - raise ImproperlyConfigured(f"Please define a value for {directory_name} in your settings") + except AttributeError as e: + raise ImproperlyConfigured(f"Please define a value for {directory_name} in your settings") from e return self.__directory @property @@ -101,4 +101,4 @@ def generate_file(self): f.write(str(self)) LOGGER.info("Wrote %s in %s", self.mime_type, self.filename) except OSError as exc: - raise OSError(f"Unable to create <{self.filename}> : {exc} ") + raise OSError(f"Unable to create <{self.filename}> : {exc} ") from exc diff --git a/survey/exporter/tex/question2tex_chart.py b/survey/exporter/tex/question2tex_chart.py index ca24cb94..26ba84b4 100755 --- a/survey/exporter/tex/question2tex_chart.py +++ b/survey/exporter/tex/question2tex_chart.py @@ -74,7 +74,7 @@ def get_results(self): final_answers.append(answer) return " {}".format(",\n ".join(final_answers)) - def get_pie_options(self): # noqa: C901 + def get_pie_options(self): r"""Return the options of the pie for: \pie[options]{data}""" options = "" if self.pos: diff --git a/survey/exporter/tex/question2tex_sankey.py b/survey/exporter/tex/question2tex_sankey.py index e8abbdb7..1633f205 100755 --- a/survey/exporter/tex/question2tex_sankey.py +++ b/survey/exporter/tex/question2tex_sankey.py @@ -12,7 +12,7 @@ warnings.warn( "Cannot import 'sankey', please install the package using" "the sankey extra. (pip install django-survey-and-report[sankey])" - ": '{}'".format(e), + f": '{e}'", stacklevel=2, ) SANKEY = False diff --git a/survey/exporter/tex/survey2tex.py b/survey/exporter/tex/survey2tex.py index ce95045c..c4d82883 100755 --- a/survey/exporter/tex/survey2tex.py +++ b/survey/exporter/tex/survey2tex.py @@ -48,6 +48,7 @@ def _additional_analysis(self, survey, latex_file): latex_file.text += function_(survey) def treat_question(self, question): + # pylint: disable=too-many-locals LOGGER.info("Treating, %s %s", question.pk, question.text) options = self.tconf.get(survey_name=self.survey.name, question_text=question.text) multiple_charts = options.get("multiple_charts") @@ -96,19 +97,15 @@ def treat_question(self, question): q2tex = q2tex_class(question, latex_label=i, **opts) question_synthesis += q2tex.tex() section_title = Question2Tex.html2latex(question.text) - return """ + return f""" \\clearpage{{}} -\\section{{{}}} +\\section{{{section_title}}} -\\label{{sec:{}}} +\\label{{sec:{question.pk}}} -{} +{question_synthesis} -""".format( - section_title, - question.pk, - question_synthesis, - ) +""" @property def file_modification_time(self): diff --git a/survey/locale/de/LC_MESSAGES/django.po b/survey/locale/de/LC_MESSAGES/django.po index 43b5e626..9acc6dde 100644 --- a/survey/locale/de/LC_MESSAGES/django.po +++ b/survey/locale/de/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2021-01-23 11:53+0000\n" "Last-Translator: b' <>'\n" "Language-Team: LANGUAGE \n" @@ -121,28 +121,28 @@ msgstr "rechts" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "Kann PDF nicht exportieren, denn 'xelatex' muss installiert sein!" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Wir konnten eine Grafik nicht erstellen, weil der Typ" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "kein Standard Typ und auch kein Pfad zu einer importierbaren Question2Tex child class ist. Wähle zwischen 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' oder 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "In dieser Umfrage sind keine Fragen die angezeigt werden können." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Kann nicht mehrere PDFs exportieren. Es kann nur eins ausgewählt werden." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Fehler beim erstellen des PDFs: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Exportiere als PDF" diff --git a/survey/locale/es/LC_MESSAGES/django.po b/survey/locale/es/LC_MESSAGES/django.po index 373b2b96..66cd766c 100644 --- a/survey/locale/es/LC_MESSAGES/django.po +++ b/survey/locale/es/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2018-10-06 20:42+0000\n" "Last-Translator: Javier Ordóñez <>\n" "Language-Team: \n" @@ -125,28 +125,28 @@ msgstr "derecha" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "No podemos generar el PDF, necesitamos instalar 'xelatex'" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "No pudimos generar un gráfico porque el tipo" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "no es un tipo estándar ni ruta a una subclase importable válida de Question2Tex. Escoje entre 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' o 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "No hay preguntas para mostrar en esta encuesta." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "No se pueden exportar varios PDF, elije solo uno." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Error durante la generación del PDF: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Exportación al formato PDF" diff --git a/survey/locale/fr/LC_MESSAGES/django.po b/survey/locale/fr/LC_MESSAGES/django.po index 52a40860..81f88bd9 100644 --- a/survey/locale/fr/LC_MESSAGES/django.po +++ b/survey/locale/fr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2020-02-23 14:44+0000\n" "Last-Translator: b' <>'\n" "Language-Team: LANGUAGE \n" @@ -123,28 +123,28 @@ msgstr "à droite" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "Impossible de générer le PDF, 'xelatex' doit être installé." -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Nous n'avons pas pu générer un graphique car le type" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "n'est pas un type standard, ni le chemin d'une classe fille de Question2Tex importable. Choisissez entre 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' ou 'package.chemin.MaClasseQuestion2TexPerso'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "Aucune questions à montrer dans ce sondage." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Impossible d'exporter plusieurs PDF, choisissez en un seul." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Erreur durant la génération du PDF: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Export vers PDF" diff --git a/survey/locale/gr/LC_MESSAGES/django.po b/survey/locale/gr/LC_MESSAGES/django.po index 60b24109..a3c90bb8 100644 --- a/survey/locale/gr/LC_MESSAGES/django.po +++ b/survey/locale/gr/LC_MESSAGES/django.po @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:55+0000\n" "PO-Revision-Date: 2022-04-10 22:53+0000\n" "Last-Translator: b' <>'\n" "Language-Team: \n" @@ -118,28 +118,28 @@ msgstr "δεξιά" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "Το PDF δεν μπορεί να δημιουργηθεί, χρειαζόμαστε το 'xelatex' να εγκατασταθεί!" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Δεν μπορέσαμε να αποδώσουμε το γράφημα λόγω του τύπου" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "δεν είναι κανονικός τύπος ούτε η διαδρομή προς μια εισαγόμενη έγκυρη Question2Tex κλάση παιδί. Επιλέξτε μεταξύ 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' oder 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "Δεν υπάρχουν ερωτήσεις για εμφάνιση σε αυτήν την έρευνα." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Δεν είναι δυνατή η εξαγωγή πολλών PDF, επιλέξτε μόνο ένα." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Σφάλμα κατά τη δημιουργία PDF: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Εξαγωγή ως PDF" diff --git a/survey/locale/id/LC_MESSAGES/django.po b/survey/locale/id/LC_MESSAGES/django.po index 1b18915d..9a771e88 100644 --- a/survey/locale/id/LC_MESSAGES/django.po +++ b/survey/locale/id/LC_MESSAGES/django.po @@ -9,7 +9,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2020-10-04 15:40+0000\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -120,28 +120,28 @@ msgstr "kanan" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "Tidak dapat menghasilkan PDF, 'xelatex' perlu dipasang terlebih dahulu" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Tidak dapat memuat sebuah diagram karena tipe" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "bukan tipe standar ataupun path menuju kelas turunan Question2Tex yang dapat diimpor tidak valid. Plih antara 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' atau 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "Tidak ada pertanyaan untuk ditampilkan pada survei ini." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Tidak dapat ekspor beberapa PDF sekaligus, pilih satu saja." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Terjadi kesalahan dalam membuat berkas PDF: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Ekspor sebagai PDF" diff --git a/survey/locale/ja/LC_MESSAGES/django.po b/survey/locale/ja/LC_MESSAGES/django.po index 5c6ed531..a66e0400 100644 --- a/survey/locale/ja/LC_MESSAGES/django.po +++ b/survey/locale/ja/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2018-04-09 00:52+0000\n" "Last-Translator: b' '\n" "Language-Team: LANGUAGE \n" @@ -120,28 +120,28 @@ msgstr "右" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "チャートを描画できません。何故ならタイプ" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "は標準タイプでもインポート可能で有効なQuestion2Tex子クラスへのパスでもありません。 「raw」、「sankey」、「pie」、「cloud」、 「square」、「polar」または「package.path.MyQuestion2TexCustomClass」の中から選択してください。" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "" -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "" -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "" diff --git a/survey/locale/nl/LC_MESSAGES/django.po b/survey/locale/nl/LC_MESSAGES/django.po index 8dd76081..8a65a561 100644 --- a/survey/locale/nl/LC_MESSAGES/django.po +++ b/survey/locale/nl/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2021-01-23 11:53+0000\n" "Last-Translator: b' <>'\n" "Language-Team: LANGUAGE \n" @@ -120,28 +120,28 @@ msgstr "rechts" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "Kan geen PDF genereren. Installeer 'xelatex' door middel van 'sudo apt-get install texlive-xetex'." -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "We kunnen de grafiek niet maken omdat het type" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "geen standaard type of niet in het pad naar een importeerbaar geldig Question kind klasse. Kies uit 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' of 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "Geen vragen van deze survey kunnen getoond worden." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Kan geen meerdere PDF bestanden exporteren. Kies er een." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Fout tijdens het genereren van PDFs: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Exporteer naar PDF" diff --git a/survey/locale/pl/LC_MESSAGES/django.po b/survey/locale/pl/LC_MESSAGES/django.po index 23261592..27b1579b 100644 --- a/survey/locale/pl/LC_MESSAGES/django.po +++ b/survey/locale/pl/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -120,28 +120,28 @@ msgstr "prawo" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "Nie można utworzyć PDF, wymagana instalacja 'xelatex'." -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Nie można wyrenderować wykresu ze względu na typ" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "to nie jest standardowy typ ani ścieżka aby importować prawidłowo Question2Texdo klasy podrzędnej. Wybierz pomiędzy 'surowy', 'wykres sankeya', 'kawałek', 'chmura', 'kwadrat', polarny lub 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "Brak pytań do wyświetlenia w tej ankiecie" -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Nie można eksportować wielu PDF, wybierz tylko jeden." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "Błąd podczas generowania PDF: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "Eksportuj do PDF" diff --git a/survey/locale/pt/LC_MESSAGES/django.po b/survey/locale/pt/LC_MESSAGES/django.po index 4619a05a..706fa987 100644 --- a/survey/locale/pt/LC_MESSAGES/django.po +++ b/survey/locale/pt/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -120,28 +120,28 @@ msgstr "" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "" -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "" -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "" diff --git a/survey/locale/ru/LC_MESSAGES/django.po b/survey/locale/ru/LC_MESSAGES/django.po index ffea2bf6..0b9f0f66 100644 --- a/survey/locale/ru/LC_MESSAGES/django.po +++ b/survey/locale/ru/LC_MESSAGES/django.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: \n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2019-03-10 22:53+0230\n" "Last-Translator: b' '\n" "Language-Team: \n" @@ -125,28 +125,28 @@ msgstr "правильно" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Мы не смогли отобразить диаграмму, потому что тип" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "не является стандартным типом или путем к импортируемому допустимому текстовому дочернему классу Question2Tex. Выбрать между 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' o 'package.path.MyQuestion2TexCustomClass'" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "" -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "" -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "" diff --git a/survey/locale/tr/LC_MESSAGES/django.po b/survey/locale/tr/LC_MESSAGES/django.po index 2d7f43e8..206667f8 100644 --- a/survey/locale/tr/LC_MESSAGES/django.po +++ b/survey/locale/tr/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -120,28 +120,28 @@ msgstr "sağ" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "PDF oluşturulamıyor, 'xelatex'in indilmesine ihtiyacımız var." -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "Tipi nedeniyle bir grafik oluşturamadık" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "standart bir tip veya içe aktarılabilir geçerli bir Question2Tex alt sınıfının yolu değil.'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' veya 'package.path.MyQuestion2TexCustomClass'tan birini seç" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "Bu ankette görüntülenecek bir soru yok." -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "Birden fazla PDF dışa aktarılamıyor, yalnızca birini seçin." -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "PDF oluşturma sırasında hata: %s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "PDF'e aktar" diff --git a/survey/locale/zh/LC_MESSAGES/django.po b/survey/locale/zh/LC_MESSAGES/django.po index 837b56df..70b956b0 100644 --- a/survey/locale/zh/LC_MESSAGES/django.po +++ b/survey/locale/zh/LC_MESSAGES/django.po @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2023-03-07 14:14+0000\n" +"POT-Creation-Date: 2023-12-19 14:50+0000\n" "PO-Revision-Date: 2018-04-09 00:52+0000\n" "Last-Translator: Zhu Sheng Li \n" "Language-Team: LANGUAGE \n" @@ -123,28 +123,28 @@ msgstr "右" msgid "Cannot generate PDF, we need 'xelatex' to be installed." msgstr "无法生成PDF,我们需要安装“ xelatex”。" -#: survey/exporter/tex/survey2tex.py:79 +#: survey/exporter/tex/survey2tex.py:80 msgid "We could not render a chart because the type" msgstr "我们无法生成图表,因为类型" -#: survey/exporter/tex/survey2tex.py:82 +#: survey/exporter/tex/survey2tex.py:83 msgid "is not a standard type nor the path to an importable valid Question2Tex child class. Choose between 'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' or 'package.path.MyQuestion2TexCustomClass'" msgstr "既不是标准类型,也不是可导入的有效 Question2Tex 子类的路径。请在'raw', 'sankey', 'pie', 'cloud', 'square', 'polar' 或 'package.path.MyQuestion2TexCustomClass' 中选择。" -#: survey/exporter/tex/survey2tex.py:156 +#: survey/exporter/tex/survey2tex.py:153 msgid "No questions to display in this survey." msgstr "" -#: survey/exporter/tex/survey2tex.py:186 +#: survey/exporter/tex/survey2tex.py:183 msgid "Cannot export multiple PDF, choose only one." msgstr "无法导出多个PDF,只能选择一个。" -#: survey/exporter/tex/survey2tex.py:195 +#: survey/exporter/tex/survey2tex.py:192 #, python-format msgid "Error during PDF generation: %s" msgstr "PDF生成期间发生错误:%s" -#: survey/exporter/tex/survey2tex.py:202 +#: survey/exporter/tex/survey2tex.py:199 msgid "Export to PDF" msgstr "导出为PDF" diff --git a/survey/models/answer.py b/survey/models/answer.py index 63f6a49e..015fc0d2 100644 --- a/survey/models/answer.py +++ b/survey/models/answer.py @@ -60,15 +60,15 @@ def check_answer_body(self, question, body): if question.type == Question.INTEGER and body and body != "": try: body = int(body) - except ValueError: + except ValueError as e: msg = "Answer is not an integer" - raise ValidationError(msg) + raise ValidationError(msg) from e if question.type == Question.FLOAT and body and body != "": try: body = float(body) - except ValueError: + except ValueError as e: msg = "Answer is not a number" - raise ValidationError(msg) + raise ValidationError(msg) from e def check_answer_for_select(self, choices, body): answers = [] diff --git a/survey/models/question.py b/survey/models/question.py index 7b08720b..f557197d 100644 --- a/survey/models/question.py +++ b/survey/models/question.py @@ -268,6 +268,7 @@ def sorted_answers_cardinality( The ordering is reversed for same cardinality value so we have aa before zz.""" + # pylint: disable=too-many-locals cardinality = self.answers_cardinality( min_cardinality, group_together, group_by_letter_case, group_by_slugify, filter, other_question ) @@ -344,7 +345,7 @@ def __add_user_cardinality( filter, standardized_filter, ): - found_answer = False + values = [_(settings.USER_DID_NOT_ANSWER)] for other_answer in other_question.answers.all(): if user is None: break @@ -352,12 +353,8 @@ def __add_user_cardinality( # We suppose there is only a response per user # Why would you want this info if it is # possible to answer multiple time ? - found_answer = True + values = other_answer.values break - if found_answer: - values = other_answer.values - else: - values = [_(settings.USER_DID_NOT_ANSWER)] for other_value in values: other_value = self.__get_cardinality_value( other_value, group_by_letter_case, group_by_slugify, group_together diff --git a/survey/models/response.py b/survey/models/response.py index 41f63385..6d5c1425 100644 --- a/survey/models/response.py +++ b/survey/models/response.py @@ -8,11 +8,11 @@ from django.conf import settings if settings.AUTH_USER_MODEL: - user_model = settings.AUTH_USER_MODEL + UserModel = settings.AUTH_USER_MODEL else: - user_model = User + UserModel = User except (ImportError, AttributeError): - user_model = User + UserModel = User class Response(models.Model): @@ -25,7 +25,7 @@ class Response(models.Model): created = models.DateTimeField(_("Creation date"), auto_now_add=True) updated = models.DateTimeField(_("Update date"), auto_now=True) survey = models.ForeignKey(Survey, on_delete=models.CASCADE, verbose_name=_("Survey"), related_name="responses") - user = models.ForeignKey(user_model, on_delete=models.SET_NULL, verbose_name=_("User"), null=True, blank=True) + user = models.ForeignKey(UserModel, on_delete=models.SET_NULL, verbose_name=_("User"), null=True, blank=True) interview_uuid = models.CharField(_("Interview unique identifier"), max_length=36) class Meta: diff --git a/survey/tests/base_test.py b/survey/tests/base_test.py index 74e6ff09..2d0972f6 100755 --- a/survey/tests/base_test.py +++ b/survey/tests/base_test.py @@ -24,7 +24,7 @@ def login(self): """Log the user in.""" is_logged = self.client.login(username=settings.DEBUG_ADMIN_NAME, password=settings.DEBUG_ADMIN_PASSWORD) if not is_logged: # pragma: no cover - raise Exception("Login failed for test user! Tests won't work.") + raise ValueError("Login failed for test user! Tests won't work.") def logout(self): """Log the user out.""" diff --git a/survey/tests/exporter/test_survey2x.py b/survey/tests/exporter/test_survey2x.py index e1dd5277..bb7940b3 100755 --- a/survey/tests/exporter/test_survey2x.py +++ b/survey/tests/exporter/test_survey2x.py @@ -49,7 +49,7 @@ def test_initially_need_update(self): self.actual_survey2x.need_update(), "No file exported and the survey " "contain response : we should need an update. " - "{}".format(self.get_fail_info(self.actual_survey2x)), + f"{self.get_fail_info(self.actual_survey2x)}", ) @patch.object(Survey2Survey, "file_modification_time", RIGHT_NOW) @@ -59,7 +59,7 @@ def test_need_update_after_generation(self): self.actual_survey2x.need_update(), "We exported the file and there" " is no new response, we should not need an update. " - "{}".format(self.get_fail_info(self.actual_survey2x)), + f"{self.get_fail_info(self.actual_survey2x)}", ) @patch.object(Survey2Survey, "file_modification_time", LONG_TIME_AGO) @@ -69,5 +69,5 @@ def test_need_update_after_new_response(self): self.actual_survey2x.need_update(), "We exported the file but there" " is a new response, we should need an update. " - "{}".format(self.get_fail_info(self.actual_survey2x)), + f"{self.get_fail_info(self.actual_survey2x)}", ) diff --git a/survey/tests/exporter/tex/test_question2tex_sankey.py b/survey/tests/exporter/tex/test_question2tex_sankey.py index ecd71e77..cf1dbc61 100755 --- a/survey/tests/exporter/tex/test_question2tex_sankey.py +++ b/survey/tests/exporter/tex/test_question2tex_sankey.py @@ -11,16 +11,13 @@ def test_other_question_type(self): q2s = Question2TexSankey(question, other_question=other_question) self.assertIsNotNone(q2s.tex()) - -""" - def test_big_ranking_survey(self): - # Creating a big ranking survey with user takes a long time - self.create_big_ranking_survey(with_user=True) - qtext = "How much do you like question {} ?" - from survey.models import Question - - q4 = Question.objects.get(text=qtext.format(4)) - q5 = Question.objects.get(text=qtext.format(5)) - q2tex_sankey = Question2TexSankey(q4, filter=["1"], other_question=q5, group_together={"A": ["2", "3"]}) - q2tex_sankey.tex() -""" + # def test_big_ranking_survey(self): + # # Creating a big ranking survey with user takes a long time + # self.create_big_ranking_survey(with_user=True) + # qtext = "How much do you like question {} ?" + # from survey.models import Question + # + # q4 = Question.objects.get(text=qtext.format(4)) + # q5 = Question.objects.get(text=qtext.format(5)) + # q2tex_sankey = Question2TexSankey(q4, filter=["1"], other_question=q5, group_together={"A": ["2", "3"]}) + # q2tex_sankey.tex() diff --git a/survey/tests/management/commands/test_exportresult.py b/survey/tests/management/commands/test_exportresult.py index 570b32a7..c0a5360a 100755 --- a/survey/tests/management/commands/test_exportresult.py +++ b/survey/tests/management/commands/test_exportresult.py @@ -30,7 +30,10 @@ def test_no_options(self): call_command("exportresult", "--pdf", survey_id="1") call_command("exportresult", "--pdf", "--force", survey_id="1") except XelatexNotInstalled: - warn("xelatex is not installed, some features regarding report generation in PDF were not tested!") + warn( + "xelatex is not installed, some features regarding report generation in PDF were not tested!", + stacklevel=0, + ) def test_handle(self): """The custom command export result create the right csv file.""" diff --git a/survey/tests/management/test_management.py b/survey/tests/management/test_management.py index cd75592d..a6fee9b2 100755 --- a/survey/tests/management/test_management.py +++ b/survey/tests/management/test_management.py @@ -83,15 +83,13 @@ def create_big_ranking_survey(self, with_user=False): def setUp(self): super().setUp() self.create_survey() - self.expected_content = """\ + self.expected_content = f"""\ user,Aèbc?,Bècd?,Cède?,Dèef? ps250112,1é,2é,3é, pierre,,,, -{},1|1a|1b,2|2a|2b,3|3a|3b, -{},1e|1é|1ë,2e|2é|2ë,3e|3é|3ë, -Anonymous,,,,""".format( - self.username, self.other_username - ) +{self.username},1|1a|1b,2|2a|2b,3|3a|3b, +{self.other_username},1e|1é|1ë,2e|2é|2ë,3e|3é|3ë, +Anonymous,,,,""" self.expected_header = ["user", "Aèbc?", "Bècd?", "Cède?", "Dèef?"] self.conf_dir = Path(HERE, "..", "exporter", "tex") self.test_conf_path = Path(self.conf_dir, "test_conf.yaml") diff --git a/survey/views/survey_detail.py b/survey/views/survey_detail.py index 61fa8157..68b6335e 100644 --- a/survey/views/survey_detail.py +++ b/survey/views/survey_detail.py @@ -30,7 +30,7 @@ def get(self, request, *args, **kwargs): asset_context = { # If any of the widgets of the current form has a "date" class, flatpickr will be loaded into the template - "flatpickr": any([field.widget.attrs.get("class") == "date" for _, field in form.fields.items()]) + "flatpickr": any(field.widget.attrs.get("class") == "date" for _, field in form.fields.items()) } context = { "response_form": form,