Skip to content

Commit 7d43597

Browse files
authored
Merge pull request #83 from vitorfs/dev
Release v2.0.5
2 parents 3967603 + e6e8249 commit 7d43597

File tree

6 files changed

+44
-17
lines changed

6 files changed

+44
-17
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
Parsifal 2.0.5 (2021-09-10)
2+
===========================
3+
4+
Bugfixes
5+
--------
6+
7+
- Improve quality assessment performance (#81)
8+
9+
110
Parsifal 2.0.4 (2021-09-10)
211
===========================
312

parsifal/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from parsifal.utils.version import get_version
22

3-
VERSION = (2, 0, 4, "final", 0)
3+
VERSION = (2, 0, 5, "final", 0)
44

55
__version__ = get_version(VERSION)

parsifal/apps/reviews/conducting/views.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from django.shortcuts import get_object_or_404, redirect, render
1212
from django.template.context_processors import csrf
1313
from django.urls import reverse as r
14-
from django.utils.html import escape, format_html
14+
from django.utils.html import escape
1515
from django.utils.translation import gettext as _
1616
from django.views.decorators.http import require_POST
1717

@@ -237,6 +237,14 @@ def build_quality_assessment_table(request, review, order):
237237
quality_questions = review.get_quality_assessment_questions()
238238
quality_answers = review.get_quality_assessment_answers()
239239

240+
csrf_token = csrf(request)["csrf_token"]
241+
242+
quality_index = {}
243+
for study in selected_studies:
244+
quality_index[study.pk] = {}
245+
for qa in study.qualityassessment_set.all():
246+
quality_index[study.pk][qa.question_id] = qa.answer_id
247+
240248
if quality_questions and quality_answers:
241249
str_table = ""
242250
for study in selected_studies:
@@ -248,31 +256,27 @@ def build_quality_assessment_table(request, review, order):
248256
249257
<table class="table" id="tbl-quality" article-id="{2}" csrf-token="{3}">
250258
<tbody>""".format(
251-
escape(study.title), study.score, study.id, str(csrf(request)["csrf_token"]), escape(study.year)
259+
escape(study.title), study.score, study.id, csrf_token, escape(study.year)
252260
)
253261

254262
for question in quality_questions:
255-
str_table += format_html(
256-
'<tr question-id="{question_id}"><td>{question_description}</td>',
263+
str_table += '<tr question-id="{question_id}"><td>{question_description}</td>'.format(
257264
question_id=question.pk,
258-
question_description=question.description,
265+
question_description=escape(question.description),
259266
)
260267

261-
question_answer_id = None
262-
for qa in study.qualityassessment_set.all():
263-
if qa.question_id == question.pk:
264-
question_answer_id = qa.answer_id
265-
break
268+
question_answer_id = quality_index[study.pk].get(question.pk)
266269

267270
for answer in quality_answers:
268271
selected_answer = ""
269272
if answer.id == question_answer_id:
270273
selected_answer = " selected-answer"
271-
str_table += format_html(
272-
'<td class="answer {selected}" answer-id="{answer_id}">{answer_description}</td>',
273-
selected=selected_answer,
274-
answer_id=answer.pk,
275-
answer_description=answer.description,
274+
str_table += (
275+
'<td class="answer {selected}" answer-id="{answer_id}">{answer_description}</td>'.format(
276+
selected=selected_answer,
277+
answer_id=answer.pk,
278+
answer_description=escape(answer.description),
279+
)
276280
)
277281
str_table += "</tr>"
278282

parsifal/settings/local.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,22 @@
66
# CORE SETTINGS
77
# ==============================================================================
88

9-
INSTALLED_APPS += ["debug_toolbar"]
9+
INSTALLED_APPS += ["debug_toolbar", "silk"]
1010

1111
MIDDLEWARE.insert(0, "debug_toolbar.middleware.DebugToolbarMiddleware")
12+
MIDDLEWARE.insert(0, "silk.middleware.SilkyMiddleware")
1213

1314

1415
# ==============================================================================
1516
# EMAIL SETTINGS
1617
# ==============================================================================
1718

1819
EMAIL_BACKEND = "django.core.mail.backends.console.EmailBackend"
20+
21+
22+
# ==============================================================================
23+
# THIRD-PARTY APPS
24+
# ==============================================================================
25+
26+
SILKY_PYTHON_PROFILER = True
27+
SILKY_PYTHON_PROFILER_BINARY = True

parsifal/urls.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,10 @@
112112

113113
urlpatterns = [path("__debug__/", include(debug_toolbar.urls))] + urlpatterns
114114

115+
if apps.is_installed("silk"):
116+
117+
urlpatterns = [path("__silk__/", include("silk.urls"))] + urlpatterns
118+
115119
from django.conf.urls.static import static
116120

117121
urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

requirements/local.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
-r tests.txt
22

33
django-debug-toolbar==3.2.2
4+
git+git://github.com/jazzband/django-silk.git#egg=django-silk
45
ipython==7.27.0

0 commit comments

Comments
 (0)