Parent: [77df3f] (diff)

Child: [831432] (diff)

Download this file

custom_tags.py    75 lines (62 with data), 3.1 kB

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# This Source Code Form of OSSEval is subject to the terms of the GNU AFFERO
# GENERAL PUBLIC LICENSE, v. 3.0. If a copy of the AGPL was not
# distributed with this file, You can obtain one at http://www.gnu.org/licenses/agpl.txt
#
# OSSeval is powered by the SOS Open Source AGPL edition.
# The AGPL requires that you do not remove the SOS Open Source attribution and copyright
# notices from the user interface (see section 5.d below).
# Commercial licenses are available and do not require any SOS Open Source attributions
# or visible copyright notices but they are not permitted under this license.
# OSSEval Copyright 2014 Bitergium SLL
# SOS Open Source Copyright 2012 Roberto Galoppini
# Author: Davide Galletti
from django import template
from analysis.models import Instance, Question, Answer, Page, MethodologyVersion
register = template.Library()
@register.simple_tag
def page_radar_chart(page_id, weight_scenario_id, *args, **kwargs):
page = Page.objects.get(pk=page_id)
return page.radar_chart(weight_scenario_id)
@register.simple_tag
def page_bar_chart(page_id, weight_scenario_id, *args, **kwargs):
page = Page.objects.get(pk=page_id)
return page.bar_chart(weight_scenario_id)
@register.simple_tag
def methodology_version_radar_chart(methodology_version_id, weight_scenario_id, *args, **kwargs):
methodology_version = MethodologyVersion.objects.get(pk=methodology_version_id)
return methodology_version.radar_chart(weight_scenario_id)
@register.simple_tag
def methodology_version_bar_chart(methodology_version_id, weight_scenario_id, *args, **kwargs):
methodology_version = MethodologyVersion.objects.get(pk=methodology_version_id)
return methodology_version.bar_chart(weight_scenario_id)
@register.simple_tag
def instance_score_question(instance_id, question_id, *args, **kwargs):
instance = Instance.objects.get(pk=instance_id)
question = Question.objects.get(pk=question_id)
try:
answer = Answer.objects.get(question=question, instance=instance)
choice = question.choice_set.get(order=answer.value_integer)
if choice.todo != "":
return "<div title=\"" + choice.todo + "\">(" + str(answer.score) + ") " + choice.text + "</div>"
else:
return "(" + str(answer.score) + ") " + choice.text
except:
return "<font color=red>not answered</font>"
@register.simple_tag
def instance_score_page(instance_id, page_id, *args, **kwargs):
instance = Instance.objects.get(pk=instance_id)
page = Page.objects.get(pk=page_id)
score = 0
for question in page.question_set.all():
try:
answer = Answer.objects.get(question=question, instance=instance)
score += answer.score
except:
pass
return "(" + str(score) + ") <strong>" + instance.name + "</strong>"
@register.simple_tag
def question_weight(question_id, weight_scenario, *args, **kwargs):
if weight_scenario.question_weight(question_id) != 1:
return " ( * " + str(weight_scenario.question_weight(question_id)) + " )"
else:
return ""