diff --git a/CHANGELOG.md b/CHANGELOG.md index fb25f182..f8aabe61 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +Parsifal 2.0.5 (2021-09-10) +=========================== + +Bugfixes +-------- + +- Improve quality assessment performance (#81) + + Parsifal 2.0.4 (2021-09-10) =========================== diff --git a/parsifal/__init__.py b/parsifal/__init__.py index f4daf158..53bbd973 100644 --- a/parsifal/__init__.py +++ b/parsifal/__init__.py @@ -1,5 +1,5 @@ from parsifal.utils.version import get_version -VERSION = (2, 0, 4, "final", 0) +VERSION = (2, 0, 5, "final", 0) __version__ = get_version(VERSION) diff --git a/parsifal/apps/reviews/conducting/views.py b/parsifal/apps/reviews/conducting/views.py index 01033b71..2747a54f 100644 --- a/parsifal/apps/reviews/conducting/views.py +++ b/parsifal/apps/reviews/conducting/views.py @@ -11,7 +11,7 @@ from django.shortcuts import get_object_or_404, redirect, render from django.template.context_processors import csrf from django.urls import reverse as r -from django.utils.html import escape, format_html +from django.utils.html import escape from django.utils.translation import gettext as _ from django.views.decorators.http import require_POST @@ -237,6 +237,14 @@ def build_quality_assessment_table(request, review, order): quality_questions = review.get_quality_assessment_questions() quality_answers = review.get_quality_assessment_answers() + csrf_token = csrf(request)["csrf_token"] + + quality_index = {} + for study in selected_studies: + quality_index[study.pk] = {} + for qa in study.qualityassessment_set.all(): + quality_index[study.pk][qa.question_id] = qa.answer_id + if quality_questions and quality_answers: str_table = "" for study in selected_studies: @@ -248,31 +256,27 @@ def build_quality_assessment_table(request, review, order): """.format( - escape(study.title), study.score, study.id, str(csrf(request)["csrf_token"]), escape(study.year) + escape(study.title), study.score, study.id, csrf_token, escape(study.year) ) for question in quality_questions: - str_table += format_html( - '', + str_table += ''.format( question_id=question.pk, - question_description=question.description, + question_description=escape(question.description), ) - question_answer_id = None - for qa in study.qualityassessment_set.all(): - if qa.question_id == question.pk: - question_answer_id = qa.answer_id - break + question_answer_id = quality_index[study.pk].get(question.pk) for answer in quality_answers: selected_answer = "" if answer.id == question_answer_id: selected_answer = " selected-answer" - str_table += format_html( - '', - selected=selected_answer, - answer_id=answer.pk, - answer_description=answer.description, + str_table += ( + ''.format( + selected=selected_answer, + answer_id=answer.pk, + answer_description=escape(answer.description), + ) ) str_table += "" diff --git a/parsifal/settings/local.py b/parsifal/settings/local.py index 8d1c0020..a2f1eaa9 100644 --- a/parsifal/settings/local.py +++ b/parsifal/settings/local.py @@ -6,9 +6,10 @@ # CORE SETTINGS # ============================================================================== -INSTALLED_APPS += ["debug_toolbar"] +INSTALLED_APPS += ["debug_toolbar", "silk"] MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware") +MIDDLEWARE.insert(0, "silk.middleware.SilkyMiddleware") # ============================================================================== @@ -16,3 +17,11 @@ # ============================================================================== EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend" + + +# ============================================================================== +# THIRD-PARTY APPS +# ============================================================================== + +SILKY_PYTHON_PROFILER = True +SILKY_PYTHON_PROFILER_BINARY = True diff --git a/parsifal/urls.py b/parsifal/urls.py index b9454817..59d0a0dc 100644 --- a/parsifal/urls.py +++ b/parsifal/urls.py @@ -112,6 +112,10 @@ urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns + if apps.is_installed("silk"): + + urlpatterns = [path("__silk__/", include("silk.urls"))] + urlpatterns + from django.conf.urls.static import static urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/requirements/local.txt b/requirements/local.txt index d5ac4ff4..dbd53523 100644 --- a/requirements/local.txt +++ b/requirements/local.txt @@ -1,4 +1,5 @@ -r tests.txt django-debug-toolbar==3.2.2 +git+git://github.com/jazzband/django-silk.git#egg=django-silk ipython==7.27.0
{question_description}
{question_description}{answer_description}{answer_description}