Parent: [c9d94b] (diff)

Child: [853210] (diff)

Download this file

custom_tags.py    37 lines (31 with data), 1.3 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
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)
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 ""