|
a/OSSEval/analysis/templatetags/custom_tags.py |
|
b/OSSEval/analysis/templatetags/custom_tags.py |
1 |
# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
|
1 |
# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
|
2 |
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
|
2 |
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
|
3 |
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
|
3 |
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
|
4 |
#
|
4 |
#
|
5 |
# OSSeval is powered by the SOS Open Source AGPL edition.
|
5 |
# OSSeval is powered by the SOS Open Source AGPL edition.
|
6 |
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
|
6 |
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
|
|
... |
|
... |
10 |
# SOS Open Source Copyright 2012 Roberto Galoppini
|
10 |
# SOS Open Source Copyright 2012 Roberto Galoppini
|
11 |
# Author: Davide Galletti
|
11 |
# Author: Davide Galletti
|
12 |
|
12 |
|
13 |
|
13 |
|
14 |
from django import template
|
14 |
from django import template
|
15 |
from analysis.models import Instance, Question, Answer, Page, MethodologyVersion
|
15 |
from analysis.models import Instance, Question, Answer, Choice, Page, MethodologyVersion
|
16 |
|
16 |
|
17 |
register = template.Library()
|
17 |
register = template.Library()
|
18 |
|
18 |
|
19 |
@register.simple_tag
|
19 |
@register.simple_tag
|
20 |
def page_radar_chart(page_id, weight_scenario_id, *args, **kwargs):
|
20 |
def page_radar_chart(page_id, weight_scenario_id, *args, **kwargs):
|
|
... |
|
... |
39 |
@register.simple_tag
|
39 |
@register.simple_tag
|
40 |
def instance_score_question(instance_id, question_id, *args, **kwargs):
|
40 |
def instance_score_question(instance_id, question_id, *args, **kwargs):
|
41 |
instance = Instance.objects.get(pk=instance_id)
|
41 |
instance = Instance.objects.get(pk=instance_id)
|
42 |
question = Question.objects.get(pk=question_id)
|
42 |
question = Question.objects.get(pk=question_id)
|
43 |
try:
|
43 |
try:
|
|
|
44 |
choices = Choice.objects.filter(question=question)
|
44 |
answer = Answer.objects.get(question=question, instance=instance)
|
45 |
answer = Answer.objects.get(choice__in=choices, instance=instance)
|
45 |
choice = question.choice_set.get(order=answer.value_integer)
|
|
|
46 |
if choice.todo != "":
|
46 |
if answer.choice.todo != "":
|
47 |
return "<div title=\"" + choice.todo + "\">(" + str(answer.score) + ") " + choice.text + "</div>"
|
47 |
return "<div title=\"" + answer.choice.todo + "\">(" + str(answer.score) + ") " + answer.choice.text + "</div>"
|
48 |
else:
|
48 |
else:
|
49 |
return "(" + str(answer.score) + ") " + choice.text
|
49 |
return "(" + str(answer.score) + ") " + answer.choice.text
|
50 |
except:
|
50 |
except:
|
51 |
return "<font color=red>not answered</font>"
|
51 |
return "<font color=red>not answered</font>"
|
52 |
|
52 |
|
53 |
|
53 |
|
54 |
@register.simple_tag
|
54 |
@register.simple_tag
|
|
... |
|
... |
56 |
instance = Instance.objects.get(pk=instance_id)
|
56 |
instance = Instance.objects.get(pk=instance_id)
|
57 |
page = Page.objects.get(pk=page_id)
|
57 |
page = Page.objects.get(pk=page_id)
|
58 |
score = 0
|
58 |
score = 0
|
59 |
for question in page.question_set.all():
|
59 |
for question in page.question_set.all():
|
60 |
try:
|
60 |
try:
|
|
|
61 |
choices = Choice.objects.filter(question=question)
|
61 |
answer = Answer.objects.get(question=question, instance=instance)
|
62 |
answer = Answer.objects.get(choice__in=choices, instance=instance)
|
62 |
score += answer.score
|
63 |
score += answer.score
|
63 |
except:
|
64 |
except:
|
64 |
pass
|
65 |
pass
|
65 |
return "(" + str(score) + ") <strong>" + instance.name + "</strong>"
|
66 |
return "(" + str(score) + ") <strong>" + instance.name + "</strong>"
|
66 |
|
67 |
|