Parent: [853210] (diff)

Child: [8529bc] (diff)

Download this file

custom_tags.py    55 lines (46 with data), 2.2 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
# 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
register = template.Library()
@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 ""