[MERGE] merge with parent brnach
[odoo/odoo.git] / addons / survey / report / survey_browse_response.py
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
6 #    $Id$
7 #
8 #    This program is free software: you can redistribute it and/or modify
9 #    it under the terms of the GNU Affero General Public License as published by
10 #    the Free Software Foundation, either version 3 of the License, or
11 #    (at your option) any later version.
12 #
13 #    This program is distributed in the hope that it will be useful,
14 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
15 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 #    GNU Affero General Public License for more details.
17 #
18 #    You should have received a copy of the GNU Affero General Public License
19 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 #
21 ##############################################################################
22
23 import pooler
24 from report.interface import report_rml
25 from tools import to_xml
26 import tools
27 import time
28 from report import report_sxw
29
30 class survey_browse_response(report_rml):
31     def create(self, cr, uid, ids, datas, context):
32         _divide_columns_for_matrix = 0.7
33         _display_ans_in_rows = 5
34         _pageSize = ('29.7cm','21.1cm')
35
36         if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical':
37             if datas['form'].get('paper_size','') == 'letter':
38                 _pageSize = ('21.6cm','27.9cm')
39             elif datas['form'].get('paper_size','') == 'legal':
40                 _pageSize = ('21.6cm','35.6cm')
41             elif datas['form'].get('paper_size','') == 'a4':
42                 _pageSize = ('21.1cm','29.7cm')
43
44         elif datas.has_key('form') and datas['form'].get('orientation',False) == 'horizontal':
45             if datas['form'].get('paper_size','') == 'letter':
46                 _pageSize = ('27.9cm','21.6cm')
47             elif datas['form'].get('paper_size','') == 'legal':
48                 _pageSize = ('35.6cm','21.6cm')
49             elif datas['form'].get('paper_size') == 'a4':
50                 _pageSize = ('29.7cm','21.1cm')
51
52         _frame_width = tools.ustr(_pageSize[0])
53         _frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm'
54         _tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm'
55         rml ="""<document filename="Survey Answer Report.pdf">
56                 <template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Answer' author="OpenERP S.A.(sales@openerp.com)" allowSplitting="20" >
57                     <pageTemplate id="first">
58                         <frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/>
59                         <pageGraphics>
60                             <lineMode width="1.0"/>
61                             <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+"""</lines>
62                             <lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" 1.0cm 1.00cm</lines>
63                             <lines>"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>
64                             <lines>1.0cm 1.00cm """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>"""
65         if datas.has_key('form') and datas['form']['page_number']:
66             rml +="""
67                     <fill color="gray"/>
68                     <setFont name="Helvetica" size="10"/>
69                     <drawRightString x='"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+"""' y="0.6cm">Page : <pageNumber/> </drawRightString>"""
70         rml +="""</pageGraphics>
71                     </pageTemplate>
72                 </template>
73                   <stylesheet>
74                     <blockTableStyle id="tbl_white">
75                       <blockAlignment value="LEFT"/>
76                       <blockValign value="TOP"/>
77                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
78                       <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
79                       <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
80                     </blockTableStyle>
81                     <blockTableStyle id="tbl_gainsboro">
82                       <blockAlignment value="LEFT"/>
83                       <blockValign value="TOP"/>
84                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
85                       <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
86                       <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
87                       <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
88                     </blockTableStyle>
89                     <blockTableStyle id="ans_tbl_white">
90                       <blockAlignment value="LEFT"/>
91                       <blockValign value="TOP"/>
92                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
93                     </blockTableStyle>
94                     <blockTableStyle id="ans_tbl_gainsboro">
95                       <blockAlignment value="LEFT"/>
96                       <blockValign value="TOP"/>
97                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
98                       <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
99                     </blockTableStyle>
100                     <blockTableStyle id="simple_table">
101                       <blockAlignment value="LEFT"/>
102                       <blockValign value="TOP"/>
103                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6"/>
104                     </blockTableStyle>
105                     <blockTableStyle id="note_table">
106                       <blockAlignment value="LEFT"/>
107                       <blockValign value="TOP"/>
108                     </blockTableStyle>
109                     <blockTableStyle id="Table2">
110                       <blockAlignment value="LEFT"/>
111                       <blockValign value="TOP"/>
112                     </blockTableStyle>
113                     <blockTableStyle id="Table3">
114                       <blockAlignment value="LEFT"/>
115                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="1,0" stop="2,-1"/>
116                       <blockValign value="TOP"/>
117                     </blockTableStyle>
118                     <blockTableStyle id="Table4">
119                       <blockAlignment value="LEFT"/>
120                       <blockValign value="TOP"/>
121                       <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
122                     </blockTableStyle>
123                     <blockTableStyle id="Table5">
124                       <blockAlignment value="LEFT"/>
125                       <blockValign value="TOP"/>
126                       <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/>
127                     </blockTableStyle>
128                     <blockTableStyle id="Table41">
129                       <blockAlignment value="LEFT"/>
130                       <blockValign value="TOP"/>
131                       <lineStyle kind="LINEBELOW" colorName="#000000" start="0,0" stop="-1,-1"/>
132                       <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
133                       <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
134                     </blockTableStyle>
135                     <blockTableStyle id="Table51">
136                       <blockAlignment value="LEFT"/>
137                       <blockValign value="TOP"/>
138                       <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
139                       <lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
140                       <lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
141                     </blockTableStyle>
142                     <blockTableStyle id="Table_heading">
143                       <blockAlignment value="LEFT"/>
144                       <blockValign value="TOP"/>
145                     </blockTableStyle>
146                     <blockTableStyle id="title_tbl">
147                       <blockAlignment value="LEFT"/>
148                       <blockValign value="TOP"/>
149                       <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
150                       <blockBackground colorName="black" start="0,0" stop="-1,-1"/>
151                       <blockTextColor colorName="white" start="0,0" stop="0,0"/>
152                     </blockTableStyle>
153                     <blockTableStyle id="page_tbl">
154                       <blockAlignment value="LEFT"/>
155                       <blockValign value="TOP"/>
156                       <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
157                       <blockBackground colorName="gray" start="0,0" stop="-1,-1"/>
158                       <blockTextColor colorName="white" start="0,0" stop="0,0"/>
159                     </blockTableStyle>
160                     <initialize>
161                       <paraStyle name="all" alignment="justify"/>
162                     </initialize>
163                     <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
164                     <paraStyle name="answer_right" alignment="RIGHT" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
165                     <paraStyle name="Standard1" fontName="helvetica-bold" alignment="RIGHT" fontSize="09.0"/>
166                     <paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/>
167                     <paraStyle name="header1" fontName="Helvetica" fontSize="11.0"/>
168                     <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/>
169                     <paraStyle name="page" fontName="helvetica" fontSize="11.0" leftIndent="0.0"/>
170                     <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/>
171                     <paraStyle name="answer_bold" fontName="Helvetica-Bold" fontSize="09.0" leftIndent="2.0"/>
172                     <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
173                     <paraStyle name="answer1" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
174                     <paraStyle name="Title" fontName="helvetica" fontSize="20.0" leading="15" spaceBefore="6.0" spaceAfter="6.0" alignment="CENTER"/>
175                     <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/>
176                     <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.0"/>
177                     <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
178                     <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
179                     <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
180                     <paraStyle name="terp_default_9_Bold" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
181                     <paraStyle name="terp_tblheader_General_Centre_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
182                     <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
183                     <paraStyle name="terp_tblheader_General_right_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
184                     <paraStyle name="terp_tblheader_General_right" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
185                     <paraStyle name="descriptive_text" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
186                     <paraStyle name="descriptive_text_heading" fontName="helvetica-bold" fontSize="18.0" alignment="RIGHT" leftIndent="0.0" textColor="white"/>
187                   </stylesheet>
188                   <images/>
189                   <story>"""
190         surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response')
191         rml_obj=report_sxw.rml_parse(cr, uid, surv_resp_obj._name,context)
192         if datas.has_key('form') and datas['form'].has_key('response_ids'):
193             response_id = datas['form']['response_ids']
194         elif context.has_key('response_id') and context['response_id']:
195             response_id = [int(context['response_id'][0])]
196         else:
197             response_id = surv_resp_obj.search(cr, uid, [('survey_id', 'in', ids)])
198
199         surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line')
200         surv_obj = pooler.get_pool(cr.dbname).get('survey')
201
202         for response in surv_resp_obj.browse(cr, uid, response_id):
203             for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
204                 tbl_width = float(_tbl_widths.replace('cm', ''))
205                 colwidth =  "2.5cm,4.8cm," + str(tbl_width - 15.0) +"cm,3.2cm,4.5cm"
206                 resp_create = tools.ustr(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S')))
207                 rml += """<blockTable colWidths='""" + colwidth + """' style="Table_heading">
208                           <tr>
209                             <td><para style="terp_default_9_Bold">Print Date : </para></td>
210                             <td><para style="terp_default_9">""" + to_xml(rml_obj.formatLang(time.strftime("%Y-%m-%d %H:%M:%S"),date_time=True)) + """</para></td>
211                             <td><para style="terp_default_9"></para></td>
212                             <td><para style="terp_default_9_Bold">Answered by : </para></td>
213                             <td><para style="terp_default_9">""" + to_xml(response.user_id.login or '') + """</para></td>
214                           </tr>
215                           <tr>
216                             <td><para style="terp_default_9"></para></td>
217                             <td><para style="terp_default_9"></para></td>
218                             <td><para style="terp_default_9"></para></td>
219                             <td><para style="terp_default_9_Bold">Answer Date : </para></td>
220                             <td><para style="terp_default_9">""" + to_xml(resp_create) +  """</para></td>
221                           </tr>
222                         </blockTable><para style="P2"></para>"""
223
224                 status = "Not Finished"
225                 if response.state == "done": status = "Finished"
226                 colwidth =  str(tbl_width - 7) + "cm,"
227                 colwidth +=  "7cm"
228                 rml += """<blockTable colWidths='""" + str(colwidth) + """' style="title_tbl">
229                             <tr>
230                             <td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td>
231                             <td><para style="descriptive_text_heading">Status :- """ + to_xml(tools.ustr(status)) + """</para><para style="P2"><font></font></para></td>
232                             </tr>
233                         </blockTable>"""
234
235                 if survey.note:
236                     rml += """<blockTable colWidths='""" + _tbl_widths + """' style="note_table">
237                             <tr><td><para style="response">""" + to_xml(tools.ustr(survey.note or '')) + """</para><para style="P2"><font></font></para></td></tr>
238                         </blockTable>"""
239
240                 for page in survey.page_ids:
241                     rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="page_tbl">
242                                   <tr><td><para style="page">Page :- """ + to_xml(tools.ustr(page.title or '')) + """</para></td></tr>
243                               </blockTable>"""
244                     if page.note:
245                         rml += """<para style="P2"></para>
246                                  <blockTable colWidths='""" + str(_tbl_widths) + """' style="note_table">
247                                       <tr><td><para style="response">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
248                                  </blockTable>"""
249
250                     for que in page.question_ids:
251                         rml += """<para style="P2"></para>
252                                 <blockTable colWidths='""" + str(_tbl_widths) + """' style="Table5">
253                                   <tr><td><para style="question">""" + to_xml(to_xml(que.question)) + """</para></td></tr>
254                                 </blockTable>"""
255
256                         answer = surv_resp_line_obj.browse(cr ,uid, surv_resp_line_obj.search(cr, uid, [('question_id', '=', que.id),('response_id', '=', response.id)]))
257                         if que.type in ['descriptive_text']:
258                             rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
259                                          <tr><td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr>
260                                     </blockTable>"""
261
262                         elif que.type in ['table']:
263                             if len(answer) and answer[0].state == "done":
264                                 col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading')
265                                 cols_widhts = []
266                                 tbl_width = float(_tbl_widths.replace('cm', ''))
267                                 for i in range(0, len(que.column_heading_ids)):
268                                     cols_widhts.append(tbl_width / float(len(que.column_heading_ids)))
269                                 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
270                                 colWidths = colWidths + 'cm'
271                                 matrix_ans = []
272                                 rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
273
274                                 for col in que.column_heading_ids:
275                                     if col.title not in matrix_ans:
276                                         matrix_ans.append(col.title)
277                                         rml += """<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>"""
278                                 rml += """</tr></blockTable>"""
279                                 i = 0
280
281                                 for row in range(0, que.no_of_rows):
282                                     if i%2 != 0:
283                                         style = 'tbl_white'
284                                     else:
285                                         style = 'tbl_gainsboro'
286                                     i +=1
287                                     rml += """<blockTable colWidths=" """ + str(colWidths) + """ " style='"""+style+"""'><tr>"""
288                                     table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id), ('name', '=', row)]))
289                                     for column in matrix_ans:
290                                         value = False
291                                         for col in table_data:
292                                             if column == col.column_id.title:
293                                                 value = col.value
294                                         if value:
295                                             rml += """<td> <para style="terp_default_9">""" + to_xml(tools.ustr(value)) +"""</para></td>"""
296                                         else:
297                                             rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>"""
298                                     rml += """</tr></blockTable>"""
299
300                             else:
301                                 rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
302                                              <tr><td> <para style="response">No Answer</para></td> </tr>
303                                         </blockTable>"""
304
305                         elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
306                             if len(answer) and answer[0].state == "done":
307                                 ans_list = []
308                                 for ans in answer[0].response_answer_ids:
309                                     ans_list.append(to_xml(tools.ustr(ans.answer_id.answer)))
310                                 answer_choice=[]
311
312                                 for ans in que['answer_choice_ids']:
313                                     answer_choice.append(to_xml(tools.ustr((ans.answer))))
314
315                                 def divide_list(lst, n):
316                                     return [lst[i::n] for i in range(n)]
317
318                                 divide_list = divide_list(answer_choice,_display_ans_in_rows)
319                                 for lst in divide_list:
320                                     if que.type == 'multiple_choice_multiple_ans':
321                                         if len(lst) <> 0 and len(lst) <> int(round(float(len(answer_choice)) / _display_ans_in_rows, 0)):
322                                            lst.append('')
323                                     if not lst:
324                                        del divide_list[divide_list.index(lst):]
325
326                                 for divide in divide_list:
327                                     a = _divide_columns_for_matrix * len(divide)
328                                     b = float(_tbl_widths.replace('cm', '')) - float(a)
329                                     cols_widhts = []
330                                     for div in range(0, len(divide)):
331                                         cols_widhts.append(float(a / len(divide)))
332                                         cols_widhts.append(float(b / len(divide)))
333                                     colWidths = "cm,".join(map(tools.ustr, cols_widhts))
334                                     colWidths = colWidths +'cm'
335                                     rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
336
337                                     for div in range(0, len(divide)):
338                                        if divide[div] != '':
339                                            if que.type == 'multiple_choice_multiple_ans':
340                                                if divide[div] in ans_list:
341                                                    rml += """<td><illustration><fill color="white"/>
342                                                                 <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes"  round="0.1cm"/>
343                                                                 <fill color="gray"/>
344                                                                 <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no"  round="0.1cm"/>
345                                                                 </illustration></td>
346                                                              <td><para style="answer">""" + divide[div] + """</para></td>"""
347                                                else:
348                                                    rml+="""<td><illustration>
349                                                            <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"  round="0.1cm"/>
350                                                             </illustration></td>
351                                                            <td><para style="answer">""" + divide[div] + """</para></td>"""
352                                            else:
353                                                if divide[div] in ans_list:
354                                                    rml += """<td><illustration><fill color="white"/>
355                                                             <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
356                                                             <fill color="gray"/>
357                                                             <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no" round="0.1cm"/>
358                                                         </illustration></td>
359                                                    <td><para style="answer">""" + divide[div] + """</para></td>"""
360                                                else:
361                                                    rml += """<td>
362                                                                <illustration>
363                                                                    <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/>
364                                                                 </illustration>
365                                                            </td>
366                                                            <td><para style="answer">""" + divide[div] + """</para></td>"""
367                                        else:
368                                            rml += """<td></td><td></td>"""
369                                     rml += """</tr></blockTable>"""
370
371                                 if que.is_comment_require and answer[0].comment:
372                                     rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr>
373                                                 <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
374                             else:
375                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
376                                              <tr><td> <para style="response">No Answer</para></td> </tr>
377                                           </blockTable>"""
378
379                         elif que.type in ['multiple_textboxes_diff_type','multiple_textboxes','date','date_and_time','numerical_textboxes','multiple_textboxes_diff_type']:
380                             if len(answer) and answer[0].state == "done":
381                                 cols_widhts = []
382                                 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
383                                 cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
384                                 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
385                                 colWidths = tools.ustr(colWidths) + 'cm'
386                                 answer_list = {}
387
388                                 for ans in answer[0].response_answer_ids:
389                                     answer_list[ans.answer_id.answer] = ans.answer
390                                 for que_ans in que['answer_choice_ids']:
391                                     if que_ans.answer in answer_list:
392                                         rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table">
393                                                  <tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
394                                                  <td> <para style="response">""" + to_xml(tools.ustr(answer_list[que_ans.answer])) + """</para></td></tr>
395                                                 </blockTable>"""
396                                     else:
397                                         rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table">
398                                                  <tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
399                                                  <td> <para style="response"></para></td></tr>
400                                                 </blockTable>"""
401                             else:
402                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
403                                          <tr>  <td> <para style="response">No Answer</para></td> </tr>
404                                         </blockTable>"""
405
406                         elif que.type in ['single_textbox']:
407                             if len(answer) and answer[0].state == "done":
408                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
409                                          <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr>
410                                         </blockTable>"""
411                             else:
412                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
413                                          <tr>  <td> <para style="response">No Answer</para></td> </tr>
414                                         </blockTable>"""
415
416                         elif que.type in ['comment']:
417                             if len(answer) and answer[0].state == "done":
418                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
419                                          <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr>
420                                         </blockTable>"""
421                             else:
422                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
423                                          <tr>  <td> <para style="response">No Answer</para></td> </tr>
424                                         </blockTable>"""
425
426                         elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans', 'rating_scale', 'matrix_of_drop_down_menus']:
427                             if len(answer) and answer[0].state == "done":
428                                 if que.type  in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
429                                     pass
430                                 cols_widhts = []
431                                 if len(que.column_heading_ids):
432                                     cols_widhts.append(float(_tbl_widths.replace('cm','')) / float(2.0))
433                                     for col in que.column_heading_ids:
434                                         cols_widhts.append(float((float(_tbl_widths.replace('cm','')) / float(2.0)) / len(que.column_heading_ids)))
435                                 else:
436                                     cols_widhts.append(float(_tbl_widths.replace('cm','')))
437
438                                 tmp = 0.0
439                                 sum =  0.0
440                                 i = 0
441                                 if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
442                                     for col in cols_widhts:
443                                         if i == 0:
444                                             cols_widhts[i] = cols_widhts[i] / 2.0
445                                             tmp = cols_widhts[i]
446                                         sum += col
447                                         i += 1
448                                     cols_widhts.append(round(tmp, 2))
449                                 colWidths = "cm,".join(map(tools.ustr, cols_widhts))
450                                 colWidths = colWidths + 'cm'
451                                 matrix_ans = [(0, ''),]
452
453                                 for col in que.column_heading_ids:
454                                     if col.title not in matrix_ans:
455                                         matrix_ans.append((col.id, col.title))
456                                 len_matrix = len(matrix_ans)
457                                 if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
458                                     matrix_ans.append((0,que.column_name))
459                                 rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
460
461                                 for mat_col in range(0, len(matrix_ans)):
462                                     rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
463                                 rml += """</tr>"""
464                                 rml += """</blockTable>"""
465                                 i = 0
466
467                                 for ans in que.answer_choice_ids:
468                                     if i%2 != 0:
469                                         style = 'ans_tbl_white'
470                                     else:
471                                         style = 'ans_tbl_gainsboro'
472                                     i += 1
473                                     rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
474                                             <tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
475                                     comment_value = ""
476                                     for mat_col in range(1, len_matrix):
477                                         value = """"""
478                                         for res_ans in answer[0].response_answer_ids:
479                                             if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[mat_col][0]:
480                                                 comment_value = to_xml(tools.ustr(res_ans.comment_field))
481                                                 if que.type in ['matrix_of_drop_down_menus']:
482                                                     value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>"""
483                                                 elif que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']:
484                                                     value = """<illustration><fill color="white"/>
485                                                                 <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/>
486                                                                 <fill color="gray"/>
487                                                                 <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/>
488                                                             </illustration>"""
489                                                 elif que.type in ['matrix_of_choices_only_multi_ans']:
490                                                     value = """<illustration>
491                                                                 <fill color="white"/>
492                                                                 <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes"  round="0.1cm"/>
493                                                                 <fill color="gray"/>
494                                                                 <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no"  round="0.1cm"/>
495                                                                 </illustration>"""
496                                                 break
497                                             else:
498                                                 if que.type in ['matrix_of_drop_down_menus']:
499                                                     value = """"""
500                                                 elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
501                                                     value = """<illustration><fill color="white"/>
502                                                                     <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"  round="0.1cm"/>
503                                                                 </illustration>"""
504                                                 elif que.type in ['matrix_of_choices_only_multi_ans']:
505                                                     value = """<illustration><fill color="white"/>
506                                                                 <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes"  round="0.1cm"/>
507                                                                 </illustration>"""
508                                         rml+= """<td>""" + value + """</td>"""
509                                     if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
510                                         if comment_value == 'False':
511                                             comment_value = ''
512                                         rml += """<td><para style="response">""" + to_xml(tools.ustr(comment_value)) + """</para></td>"""
513                                     rml += """</tr></blockTable>"""
514
515                                 if que.is_comment_require:
516                                     rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr>
517                                             <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment or '')) + """</para></td></tr></blockTable>"""
518                             else:
519                                 rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
520                                          <tr><td> <para style="response">No Answer</para></td> </tr>
521                                         </blockTable>"""
522
523                 if datas.has_key('form') and not datas['form']['without_pagebreak']:
524                     rml += """<pageBreak/>"""
525                 elif not datas.has_key('form'):
526                     rml += """<pageBreak/>"""
527                 else:
528                     rml += """<para style="P2"><font></font></para>"""
529
530         rml += """</story></document>"""
531         report_type = datas.get('report_type', 'pdf')
532         create_doc = self.generators[report_type]
533         pdf = create_doc(rml, title=self.title)
534         return (pdf, report_type)
535
536 survey_browse_response('report.survey.browse.response', 'survey','','')
537
538 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: