Skip to content

Commit d673b02

Browse files
committed
fix dates in project_answers_tree
1 parent 7c17c5b commit d673b02

File tree

2 files changed

+46
-36
lines changed

2 files changed

+46
-36
lines changed

apps/projects/templates/projects/project_answers_tree.html

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,12 @@ <h3>{{ subsection.title}}</h3>
1919
{% for set in question.sets %}
2020

2121
{% if question.is_collection %}
22-
<p><em>{{ set.id }}:</em> {{ set.answers | join:', ' }}</p>
22+
<p><em>{{ set.id }}:</em></>
23+
<ul>
24+
{% for answer in set.answers %}
25+
<li>{{ answer }}</li>
26+
{% endfor %}
27+
</ul>
2328
{% else %}
2429
<p><em>{{ set.id }}:</em> {{ set.answers.0 }}</p>
2530
{% endif %}
@@ -35,7 +40,11 @@ <h3>{{ subsection.title}}</h3>
3540
<p><strong>{{ question.text }}</strong></p>
3641

3742
{% if question.is_collection %}
38-
<p>{{ question.answers | join:', ' }}</p>
43+
<ul>
44+
{% for answer in question.answers %}
45+
<li>{{ answer }}</li>
46+
{% endfor %}
47+
</ul>
3948
{% else %}
4049
<p>{{ question.answers.0 }}</p>
4150
{% endif %}
@@ -49,7 +58,11 @@ <h3>{{ subsection.title}}</h3>
4958
<p><strong>{{ entity.text }}</strong></p>
5059

5160
{% if entity.is_collection %}
52-
<p>{{ entity.answers | join:', ' }}</p>
61+
<ul>
62+
{% for answer in entity.answers %}
63+
<li>{{ answer }}</li>
64+
{% endfor %}
65+
</ul>
5366
{% else %}
5467
<p>{{ entity.answers.0 }}</p>
5568
{% endif %}

apps/projects/utils.py

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
1+
import iso8601
2+
13
from django.utils.translation import ugettext_lazy as _
24

35

46
def get_answers_tree(project, snapshot=None):
57

68
values = {}
79
valuesets = {}
8-
yesno = {
9-
'1': _('yes'),
10-
'0': _('no')
11-
}
1210

1311
# loop over all values of this snapshot
1412
for value in project.values.filter(snapshot=snapshot):
@@ -55,13 +53,7 @@ def get_answers_tree(project, snapshot=None):
5553
for value in values[catalog_question.attribute_entity.id]:
5654

5755
if value.set_index == set_index:
58-
if value.option:
59-
answers.append(value.option.text)
60-
elif value.text:
61-
if catalog_question.widget_type == 'yesno':
62-
answers.append(yesno[value.text])
63-
else:
64-
answers.append(value.text)
56+
answers.append(get_answer(value, catalog_question.attribute_entity.attribute))
6557

6658
if answers:
6759
sets.append({
@@ -73,16 +65,16 @@ def get_answers_tree(project, snapshot=None):
7365
questions.append({
7466
'sets': sets,
7567
'text': catalog_question.text,
76-
'attribute': catalog_question.attribute_entity.label,
68+
'attribute': catalog_question.attribute_entity.attribute,
7769
'is_collection': catalog_question.attribute_entity.is_collection or catalog_question.widget_type == 'checkbox'
7870
})
7971

8072
if questions:
8173
entities.append({
8274
'questions': questions,
83-
'attribute': catalog_entity.attribute_entity.label,
75+
'attribute': catalog_entity.attribute_entity,
8476
'is_set': True,
85-
'is_collection': True
77+
'is_collection': True,
8678
})
8779

8880
else:
@@ -94,27 +86,20 @@ def get_answers_tree(project, snapshot=None):
9486

9587
answers = []
9688
for value in values[catalog_question.attribute_entity.id]:
97-
98-
if value.option:
99-
answers.append(value.option.text)
100-
elif value.text:
101-
if catalog_question.widget_type == 'yesno':
102-
answers.append(yesno[value.text])
103-
else:
104-
answers.append(value.text)
89+
answers.append(get_answer(value, catalog_question.attribute_entity.attribute))
10590

10691
if answers:
10792
questions.append({
10893
'text': catalog_question.text,
109-
'attribute': catalog_question.attribute_entity.label,
94+
'attribute': catalog_question.attribute_entity.attribute,
11095
'answers': answers,
11196
'is_collection': catalog_question.attribute_entity.is_collection or catalog_question.widget_type == 'checkbox'
11297
})
11398

11499
if questions:
115100
entities.append({
116101
'questions': questions,
117-
'attribute': catalog_entity.attribute_entity.label,
102+
'attribute': catalog_entity.attribute_entity,
118103
'is_set': True,
119104
'is_collection': False
120105
})
@@ -126,19 +111,12 @@ def get_answers_tree(project, snapshot=None):
126111

127112
answers = []
128113
for value in values[catalog_entity.attribute_entity.id]:
129-
130-
if value.option:
131-
answers.append(value.option.text)
132-
elif value.text:
133-
if catalog_entity.question.widget_type == 'yesno':
134-
answers.append(yesno[value.text])
135-
else:
136-
answers.append(value.text)
114+
answers.append(get_answer(value, catalog_entity.attribute_entity.attribute))
137115

138116
if answers:
139117
entities.append({
140118
'text': catalog_entity.question.text,
141-
'attribute': catalog_entity.attribute_entity.label,
119+
'attribute': catalog_entity.attribute_entity.attribute,
142120
'answers': answers,
143121
'is_set': False,
144122
'is_collection': catalog_entity.attribute_entity.is_collection or catalog_entity.question.widget_type == 'checkbox'
@@ -157,3 +135,22 @@ def get_answers_tree(project, snapshot=None):
157135
})
158136

159137
return {'sections': sections}
138+
139+
140+
def get_answer(value, attribute):
141+
142+
if value.option:
143+
return value.option.text
144+
145+
elif value.text:
146+
if attribute.value_type == 'datetime':
147+
return iso8601.parse_date(value.text).date()
148+
149+
elif attribute.value_type == 'boolian':
150+
if bool(value.text):
151+
return _('yes')
152+
else:
153+
return _('no')
154+
155+
else:
156+
return value.text

0 commit comments

Comments
 (0)