1
+ import iso8601
2
+
1
3
from django .utils .translation import ugettext_lazy as _
2
4
3
5
4
6
def get_answers_tree (project , snapshot = None ):
5
7
6
8
values = {}
7
9
valuesets = {}
8
- yesno = {
9
- '1' : _ ('yes' ),
10
- '0' : _ ('no' )
11
- }
12
10
13
11
# loop over all values of this snapshot
14
12
for value in project .values .filter (snapshot = snapshot ):
@@ -55,13 +53,7 @@ def get_answers_tree(project, snapshot=None):
55
53
for value in values [catalog_question .attribute_entity .id ]:
56
54
57
55
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 ))
65
57
66
58
if answers :
67
59
sets .append ({
@@ -73,16 +65,16 @@ def get_answers_tree(project, snapshot=None):
73
65
questions .append ({
74
66
'sets' : sets ,
75
67
'text' : catalog_question .text ,
76
- 'attribute' : catalog_question .attribute_entity .label ,
68
+ 'attribute' : catalog_question .attribute_entity .attribute ,
77
69
'is_collection' : catalog_question .attribute_entity .is_collection or catalog_question .widget_type == 'checkbox'
78
70
})
79
71
80
72
if questions :
81
73
entities .append ({
82
74
'questions' : questions ,
83
- 'attribute' : catalog_entity .attribute_entity . label ,
75
+ 'attribute' : catalog_entity .attribute_entity ,
84
76
'is_set' : True ,
85
- 'is_collection' : True
77
+ 'is_collection' : True ,
86
78
})
87
79
88
80
else :
@@ -94,27 +86,20 @@ def get_answers_tree(project, snapshot=None):
94
86
95
87
answers = []
96
88
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 ))
105
90
106
91
if answers :
107
92
questions .append ({
108
93
'text' : catalog_question .text ,
109
- 'attribute' : catalog_question .attribute_entity .label ,
94
+ 'attribute' : catalog_question .attribute_entity .attribute ,
110
95
'answers' : answers ,
111
96
'is_collection' : catalog_question .attribute_entity .is_collection or catalog_question .widget_type == 'checkbox'
112
97
})
113
98
114
99
if questions :
115
100
entities .append ({
116
101
'questions' : questions ,
117
- 'attribute' : catalog_entity .attribute_entity . label ,
102
+ 'attribute' : catalog_entity .attribute_entity ,
118
103
'is_set' : True ,
119
104
'is_collection' : False
120
105
})
@@ -126,19 +111,12 @@ def get_answers_tree(project, snapshot=None):
126
111
127
112
answers = []
128
113
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 ))
137
115
138
116
if answers :
139
117
entities .append ({
140
118
'text' : catalog_entity .question .text ,
141
- 'attribute' : catalog_entity .attribute_entity .label ,
119
+ 'attribute' : catalog_entity .attribute_entity .attribute ,
142
120
'answers' : answers ,
143
121
'is_set' : False ,
144
122
'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):
157
135
})
158
136
159
137
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