[IMP] survey :- improve codeing in all report

bzr revid: ysa@tinyerp.co.in-20100315111953-ylieyt9xmjm8g336
This commit is contained in:
Ysa (Open ERP) 2010-03-15 16:49:53 +05:30
parent 13096f9058
commit 9721577f4a
3 changed files with 198 additions and 127 deletions

View File

@ -106,31 +106,31 @@ class survey_analysis(report_rml):
for survey in surv_obj.browse(cr, uid, ids):
rml += """<blockTable colWidths="280.0,100.0,120.0" style="Table_heading">
<tr>
<td>
<para style="terp_tblheader_General_Centre">Survey Title </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Total Started Survey </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Total Completed Survey </para>
</td>
</tr>
</blockTable>
<blockTable colWidths="280.0,100.0,120.0" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_start_survey) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_comp_survey) + """</para>
</td>
</tr>
</blockTable>"""
<tr>
<td>
<para style="terp_tblheader_General_Centre">Survey Title </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Total Started Survey </para>
</td>
<td>
<para style="terp_tblheader_General_Centre">Total Completed Survey </para>
</td>
</tr>
</blockTable>
<blockTable colWidths="280.0,100.0,120.0" style="Table_head_2">
<tr>
<td>
<para style="terp_default_Centre_8">""" + to_xml(tools.ustr(survey.title)) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_start_survey) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + str(survey.tot_comp_survey) + """</para>
</td>
</tr>
</blockTable>"""
for page in survey.page_ids:
rml += """ <blockTable colWidths="500" style="Table4">
# <tr>
@ -144,24 +144,27 @@ class survey_analysis(report_rml):
</tr>
</blockTable>"""
cols_widhts = []
if que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans']:
cols_widhts.append(200)
for col in range(0, len(que.column_heading_ids) + 1):
cols_widhts.append(float(300 / (len(que.column_heading_ids) + 1)))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = [(0,'')]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append((col.id,col.title))
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in range(0, len(matrix_ans)):
rml+="""<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml+="""<td><para style="response-bold">Response Count</para></td>
rml += """<td><para style="response-bold">Response Count</para></td>
</tr>"""
last_col = cols_widhts[-1]
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
cr.execute("select count(id) from survey_response_answer sra where sra.answer_id = %d"%(ans.id))
rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
cr.execute("select count(id) from survey_response_answer sra where sra.answer_id = %d" % ans.id)
tot_res = cr.fetchone()[0]
cr.execute("select count(id) ,sra.column_id from survey_response_answer sra where sra.answer_id = %d group by sra.column_id" % ans.id)
calc_res = cr.dictfetchall()
@ -177,25 +180,27 @@ class survey_analysis(report_rml):
rml += """<td color="#FFF435"><para style="answer_bold">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>"""
else:
rml += """<td color="#FFF435"><para style="answer">""" + tools.ustr(percantage) +"% (" + tools.ustr(cal_count) + """)</para></td>"""
rml+="""<td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td>
rml += """<td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td>
</tr>"""
rml+="""</blockTable>"""
rml += """</blockTable>"""
if que.is_comment_require:
cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id)
tot_res = cr.fetchone()[0]
rml+="""<blockTable colWidths=" """+ str(500 - last_col) +"," + str(last_col) + """ " style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
rml += """<blockTable colWidths=" """+ str(500 - last_col) +"," + str(last_col) + """ " style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
elif que.type in['multiple_choice_only_one_ans', 'multiple_choice_multiple_ans', 'multiple_textboxes','date_and_time','date','multiple_textboxes_diff_type']:
rml +="""<blockTable colWidths="240.0,210,50.0" style="Table1">"""
rml += """<blockTable colWidths="240.0,210,50.0" style="Table1">"""
rml += """ <tr>
<td> <para style="Standard"> </para></td>
<td> <para style="terp_default_Center_heading">Response Percentage</para></td>
<td> <para style="response-bold">Response Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
progress = ans.average * 7 / 100
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
<td>
<illustration>
<stroke color="lightslategray"/>
@ -204,13 +209,14 @@ class survey_analysis(report_rml):
if progress:
rml += """<fill color="lightsteelblue"/>
<rect x="0.2cm" y="-0.35cm" width='""" + tools.ustr(str(float(progress)) +'cm') + """' height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>"""
rml +="""
rml += """
<fill color="black"/>
<setFont name="Helvetica" size="9"/>
<drawString x="3.2cm" y="-0.30cm">""" + tools.ustr(ans.average) + """%</drawString></illustration>
</td>
<td><para style="answer_right">""" + tools.ustr(ans.response) + """</para></td></tr>"""
rml+="""</blockTable>"""
rml += """</blockTable>"""
if que.is_comment_require:
# if que.make_comment_field:
# cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id)
@ -224,12 +230,12 @@ class survey_analysis(report_rml):
# else:
cr.execute("select count(id) from survey_response_line where question_id = %d and comment != ''"% que.id)
tot_res = cr.fetchone()[0]
rml+="""<blockTable colWidths="450.0,50.0" style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
rml += """<blockTable colWidths="450.0,50.0" style="Table1"><tr><td><para style="answer_right">""" + to_xml(tools.ustr(que.comment_label)) + """</para></td>
<td><para style="answer_right">""" + tools.ustr(tot_res) + """</para></td></tr></blockTable>"""
elif que.type in['single_textbox']:
cr.execute("select count(id) from survey_response_line where question_id = %d and single_text!=''" % que.id)
rml +="""<blockTable colWidths="400.0,100.0" style="Table1">
rml += """<blockTable colWidths="400.0,100.0" style="Table1">
<tr>
<td> <para style="Standard"> </para></td>
<td> <para style="response-bold">Response Count</para></td>
@ -237,9 +243,10 @@ class survey_analysis(report_rml):
<tr><td><para style="answer"></para></td>
<td><para style="answer_right">""" + tools.ustr(cr.fetchone()[0]) + """ </para></td></tr>
</blockTable>"""
elif que.type in['comment']:
cr.execute("select count(id) from survey_response_line where question_id = %d and comment !=''" % que.id)
rml +="""<blockTable colWidths="400.0,100.0" style="Table1">
rml += """<blockTable colWidths="400.0,100.0" style="Table1">
<tr>
<td> <para style="Standard"> </para></td>
<td> <para style="response-bold">Response Count</para></td>
@ -247,23 +254,26 @@ class survey_analysis(report_rml):
<tr><td><para style="answer"></para></td>
<td><para style="answer_right">""" + tools.ustr(cr.fetchone()[0]) + """ </para></td></tr>
</blockTable>"""
elif que.type in['rating_scale']:
cols_widhts.append(200)
for col in range(0,len(que.column_heading_ids) + 2):
cols_widhts.append(float(300 / (len(que.column_heading_ids) + 2)))
colWidths = ",".join(map(tools.ustr, cols_widhts))
matrix_ans = [(0,'')]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append((col.id,col.title))
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>"""
for mat_col in range(0,len(matrix_ans)):
rml+="""<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml+="""<td><para style="response-bold">Rating Average</para></td>
rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml += """<td><para style="response-bold">Rating Average</para></td>
<td><para style="response-bold">Response Count</para></td>
</tr>"""
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
rml += """<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
res_count = 0
rating_weight_sum = 0
for mat_col in range(1, len(matrix_ans)):
@ -275,11 +285,13 @@ class survey_analysis(report_rml):
sqc.question_id = sr.question_id and sra.answer_id = %d and sqc.title ='%s'\
group by sra.answer_id,sqc.rating_weight" % (ans.id,matrix_ans[mat_col][1]))
col_weight = cr.fetchone()
if not col_weight:
col_weight= (0,0)
elif not col_weight[1]:
col_weight = (col_weight[0],0)
res_count = col_weight[0]
if tot_res and res_count:
rating_weight_sum += int(col_weight[1]) * tot_res
tot_per = round((float(tot_res) * 100) / int(res_count), 2)
@ -290,12 +302,14 @@ class survey_analysis(report_rml):
rml += """<td><para style="answer_bold">""" + tools.ustr(tot_per) + "%(" + tools.ustr(tot_res) + """)</para></td>"""
else:
rml += """<td><para style="answer">""" + tools.ustr(tot_per)+"%(" + tools.ustr(tot_res) + """)</para></td>"""
percantage = 0.00
if res_count:
percantage = round((float(rating_weight_sum)/res_count), 2)
rml+="""<td><para style="answer_right">""" + tools.ustr(percantage) + """</para></td>
rml += """<td><para style="answer_right">""" + tools.ustr(percantage) + """</para></td>
<td><para style="answer_right">""" + tools.ustr(res_count) + """</para></td></tr>"""
rml+="""</blockTable>"""
rml += """</blockTable>"""
elif que.type in['matrix_of_drop_down_menus']:
for column in que.column_heading_ids:
rml += """<blockTable colWidths="500" style="Table1"><tr>
@ -306,8 +320,9 @@ class survey_analysis(report_rml):
for col in range(0, len(menu_choices) + 1):
cols_widhts.append(float(300 / (len(menu_choices) + 1)))
colWidths = ",".join(map(tools.ustr, cols_widhts))
rml +="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>
rml += """<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>
<td><para style="response"></para></td>"""
for menu in menu_choices:
rml += """<td><para style="response">""" + to_xml(tools.ustr(menu)) + """</para></td>"""
rml += """<td><para style="response-bold">Response Count</para></td></tr>"""
@ -317,8 +332,9 @@ class survey_analysis(report_rml):
cr.execute("select count(sra.id),sra.value_choice, sra.answer_id, sra.column_id from survey_response_answer sra \
where sra.column_id='%s' group by sra.value_choice ,sra.answer_id, sra.column_id" % (column.id))
calc_percantage = cr.dictfetchall()
for ans in que.answer_choice_ids:
rml+="""<tr><td><para style="answer_right">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
rml += """<tr><td><para style="answer_right">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
for mat_col in range(0, len(menu_choices)):
calc = 0
response = 0
@ -328,19 +344,22 @@ class survey_analysis(report_rml):
if ans.id == per['answer_id'] and menu_choices[mat_col] == per['value_choice']:
calc = per['count']
percantage = 0.00
if calc and response:
percantage = round((float(calc)* 100) / response,2)
if calc:
rml+="""<td><para style="answer_bold">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
rml += """<td><para style="answer_bold">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
else:
rml+="""<td><para style="answer">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
rml += """<td><para style="answer">""" +tools.ustr(percantage)+"% (" + tools.ustr(calc) + """)</para></td>"""
response = 0
for res in res_count:
if res['answer_id'] == ans.id: response = res['count']
rml += """<td><para style="answer_right">""" + tools.ustr(response) + """</para></td></tr>"""
rml += """</blockTable>"""
elif que.type in['numerical_textboxes']:
rml +="""<blockTable colWidths="240.0,20,100.0,70,70.0" style="Table1">
rml += """<blockTable colWidths="240.0,20,100.0,70,70.0" style="Table1">
<tr>
<td> <para style="Standard"> </para></td>
<td> <para style="Standard"> </para></td>
@ -355,6 +374,7 @@ class survey_analysis(report_rml):
for tot in tot_res:
total += int(tot['answer'])
per = 0.00
if len(tot_res):
per = round((float(total) / len(tot_res)),2)
rml+="""<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
@ -377,10 +397,12 @@ class survey_analysis(report_rml):
</tr>
</blockTable>"""
rml += """<pageBreak/>"""
rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]
pdf = create_doc(rml, title=self.title)
return (pdf, report_type)
survey_analysis('report.survey.analysis', 'survey','','')

View File

@ -31,19 +31,21 @@ class survey_browse_response(report_rml):
_divide_columns_for_matrix = 0.7
_display_ans_in_rows = 5
_pageSize = ('29.7cm','21.1cm')
if datas.has_key('form') and datas['form']['orientation']=='vertical':
if datas['form']['paper_size']=='letter':
if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('21.6cm','27.9cm')
elif datas['form']['paper_size']=='legal':
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('21.6cm','35.6cm')
elif datas['form']['paper_size']=='a4':
elif datas['form'].get('paper_size','') == 'a4':
_pageSize = ('21.1cm','29.7cm')
elif datas.has_key('form') and datas['form']['orientation']=='horizontal':
if datas['form']['paper_size']=='letter':
elif datas.has_key('form') and datas['form'].get('orientation',False) == 'horizontal':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('27.9cm','21.6cm')
elif datas['form']['paper_size']=='legal':
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('35.6cm','21.6cm')
elif datas['form']['paper_size']=='a4':
elif datas['form'].get('paper_size') == 'a4':
_pageSize = ('29.7cm','21.1cm')
_frame_width = tools.ustr(_pageSize[0])
@ -190,9 +192,11 @@ class survey_browse_response(report_rml):
response_id = [int(context['response_id'][0])]
else:
response_id = surv_resp_obj.search(cr, uid, [('survey_id', 'in', ids)])
surv_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line')
surv_obj = pooler.get_pool(cr.dbname).get('survey')
surv_ans_obj = pooler.get_pool(cr.dbname).get('survey.answer')
for response in surv_resp_obj.browse(cr, uid, response_id):
for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
tbl_width = float(_tbl_widths.replace('cm', ''))
@ -206,6 +210,7 @@ class survey_browse_response(report_rml):
<td><para style="terp_tblheader_General_right_simple">""" + to_xml(response.user_id.login) + """</para></td>
</tr>
</blockTable><para style="P2"></para>"""
status = "Not Finished"
if response.state == "done": status = "Finished"
colwidth = str(tbl_width - 7) + "cm,"
@ -216,10 +221,12 @@ class survey_browse_response(report_rml):
<td><para style="descriptive_text_heading">Status :- """ + to_xml(tools.ustr(status)) + """</para><para style="P2"><font></font></para></td>
</tr>
</blockTable>"""
if survey.note:
rml += """<blockTable colWidths='""" + _tbl_widths + """' style="note_table">
<tr><td><para style="response">""" + to_xml(tools.ustr(survey.note or '')) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
for page in survey.page_ids:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="page_tbl">
<tr><td><para style="page">Page :- """ + to_xml(tools.ustr(page.title or '')) + """</para></td></tr>
@ -229,16 +236,19 @@ class survey_browse_response(report_rml):
<blockTable colWidths='""" + str(_tbl_widths) + """' style="note_table">
<tr><td><para style="response">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
</blockTable>"""
for que in page.question_ids:
rml += """<para style="P2"></para>
<blockTable colWidths='""" + str(_tbl_widths) + """' style="Table5">
<tr><td><para style="question">""" + to_xml(to_xml(que.question)) + """</para></td></tr>
</blockTable>"""
answer = surv_resp_line_obj.browse(cr ,uid, surv_resp_line_obj.search(cr, uid, [('question_id', '=', que.id),('response_id', '=', response.id)]))
if que.type in ['descriptive_text']:
rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr>
</blockTable>"""
elif que.type in ['table']:
if len(answer) and answer[0].state == "done":
col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading')
@ -250,18 +260,20 @@ class survey_browse_response(report_rml):
colWidths = colWidths + 'cm'
matrix_ans = []
rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
rml += """<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>"""
rml += """</tr></blockTable>"""
i = 0
for row in range(0, que.no_of_rows):
if i%2!=0:
style='tbl_white'
if i%2 != 0:
style = 'tbl_white'
else:
style='tbl_gainsboro'
i+=1
style = 'tbl_gainsboro'
i +=1
rml += """<blockTable colWidths=" """ + str(colWidths) + """ " style='"""+style+"""'><tr>"""
table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id), ('name', '=', row)]))
for column in matrix_ans:
@ -274,16 +286,19 @@ class survey_browse_response(report_rml):
else:
rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>"""
rml += """</tr></blockTable>"""
else:
rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
if len(answer) and answer[0].state == "done":
ans_list = []
for ans in answer[0].response_answer_ids:
ans_list.append(to_xml(tools.ustr(ans.answer_id.answer)))
answer_choice=[]
for ans in que['answer_choice_ids']:
answer_choice.append(to_xml(tools.ustr((ans.answer))))
@ -297,6 +312,7 @@ class survey_browse_response(report_rml):
lst.append('')
if not lst:
del divide_list[divide_list.index(lst):]
for divide in divide_list:
a = _divide_columns_for_matrix * len(divide)
b = float(_tbl_widths.replace('cm', '')) - float(a)
@ -307,6 +323,7 @@ class survey_browse_response(report_rml):
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths +'cm'
rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
for div in range(0, len(divide)):
if divide[div] != '':
if que.type == 'multiple_choice_multiple_ans':
@ -340,6 +357,7 @@ class survey_browse_response(report_rml):
else:
rml += """<td></td><td></td>"""
rml += """</tr></blockTable>"""
if que.is_comment_require and answer[0].comment:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
@ -347,6 +365,7 @@ class survey_browse_response(report_rml):
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['multiple_textboxes_diff_type','multiple_textboxes','date','date_and_time','numerical_textboxes','multiple_textboxes_diff_type']:
if len(answer) and answer[0].state == "done":
cols_widhts = []
@ -355,6 +374,7 @@ class survey_browse_response(report_rml):
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = tools.ustr(colWidths) + 'cm'
answer_list = {}
for ans in answer[0].response_answer_ids:
answer_list[ans.answer_id.answer] = ans.answer
for que_ans in que['answer_choice_ids']:
@ -372,6 +392,7 @@ class survey_browse_response(report_rml):
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['single_textbox']:
if len(answer) and answer[0].state == "done":
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
@ -381,6 +402,7 @@ class survey_browse_response(report_rml):
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['comment']:
if len(answer) and answer[0].state == "done":
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
@ -390,6 +412,7 @@ class survey_browse_response(report_rml):
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans', 'rating_scale', 'matrix_of_drop_down_menus']:
if len(answer) and answer[0].state == "done":
if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
@ -401,6 +424,7 @@ class survey_browse_response(report_rml):
cols_widhts.append(float((float(_tbl_widths.replace('cm','')) / float(2.0)) / len(que.column_heading_ids)))
else:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
tmp = 0.0
sum = 0.0
i = 0
@ -415,6 +439,7 @@ class survey_browse_response(report_rml):
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths + 'cm'
matrix_ans = [(0, ''),]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append((col.id, col.title))
@ -422,11 +447,13 @@ class survey_browse_response(report_rml):
if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
matrix_ans.append(que.column_name)
rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
for mat_col in range(0, len(matrix_ans)):
rml+="""<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml +="""</tr>"""
rml+="""</blockTable>"""
i=0
rml += """<td><para style="response">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml += """</tr>"""
rml += """</blockTable>"""
i = 0
for ans in que.answer_choice_ids:
if i%2 != 0:
style = 'ans_tbl_white'
@ -474,6 +501,7 @@ class survey_browse_response(report_rml):
comment_value = ''
rml += """<td><para style="response">""" + to_xml(tools.ustr(comment_value)) + """</para></td>"""
rml += """</tr></blockTable>"""
if que.is_comment_require:
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table"><tr>
<td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment or '')) + """</para></td></tr></blockTable>"""
@ -481,16 +509,19 @@ class survey_browse_response(report_rml):
rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr><td> <para style="response">No Response</para></td> </tr>
</blockTable>"""
if datas.has_key('form') and not datas['form']['without_pagebreak']:
rml += """<pageBreak/>"""
elif not datas.has_key('form'):
rml += """<pageBreak/>"""
else:
rml += """<para style="P2"><font></font></para>"""
rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]
pdf = create_doc(rml, title=self.title)
return (pdf, report_type)
survey_browse_response('report.survey.browse.response', 'survey','','')

View File

@ -30,39 +30,41 @@ class survey_form(report_rml):
_divide_columns_for_matrix = 0.7
_display_ans_in_rows = 5
_pageSize = ('29.7cm','21.1cm')
if datas.has_key('form') and datas['form']['orientation']=='vertical':
if datas['form']['paper_size']=='letter':
if datas.has_key('form') and datas['form'].get('orientation','') == 'vertical':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('21.6cm','27.9cm')
elif datas['form']['paper_size']=='legal':
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('21.6cm','35.6cm')
elif datas['form']['paper_size']=='a4':
elif datas['form'].get('paper_size','') == 'a4':
_pageSize = ('21.1cm','29.7cm')
elif datas.has_key('form') and datas['form']['orientation']=='horizontal':
if datas['form']['paper_size']=='letter':
elif datas.has_key('form') and datas['form'].get('orientation','') == 'horizontal':
if datas['form'].get('paper_size','') == 'letter':
_pageSize = ('27.9cm','21.6cm')
elif datas['form']['paper_size']=='legal':
elif datas['form'].get('paper_size','') == 'legal':
_pageSize = ('35.6cm','21.6cm')
elif datas['form']['paper_size']=='a4':
elif datas['form'].get('paper_size','') == 'a4':
_pageSize = ('29.7cm','21.1cm')
_frame_width = tools.ustr(_pageSize[0])
_frame_height = tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.90))+'cm'
_tbl_widths = tools.ustr(float(_pageSize[0].replace('cm','')) - float(2.10))+'cm'
rml="""<document filename="Survey Form.pdf">
<template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Form.pdf' author="Martin Simon" allowSplitting="20" >
<pageTemplate id="first">
<frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/>
<pageGraphics>
<lineMode width="1.0"/>
<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>
<lines>1.0cm """+tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00))+'cm'+""" 1.0cm 1.00cm</lines>
<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>
<lines>1.0cm 1.00cm """+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>"""
<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>
<lines>1.0cm """ + tools.ustr(float(_pageSize[1].replace('cm','')) - float(1.00)) +'cm'+ """ 1.0cm 1.00cm</lines>
<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>
<lines>1.0cm 1.00cm """ + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+""" 1.00cm</lines>"""
if datas.has_key('form') and datas['form']['page_number']:
rml +="""
<fill color="gray"/>
<setFont name="Helvetica" size="10"/>
<drawRightString x='"""+tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00))+'cm'+"""' y="0.6cm">Page : <pageNumber/> </drawRightString>"""
<drawRightString x='""" + tools.ustr(float(_pageSize[0].replace('cm','')) - float(1.00)) + 'cm' + """' y="0.6cm">Page : <pageNumber/> </drawRightString>"""
rml +="""</pageGraphics>
</pageTemplate>
</template>
@ -158,9 +160,10 @@ class survey_form(report_rml):
<blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
<tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(survey.note)) + """</para><para style="P2"><font></font></para></td></tr>
</blockTable>"""
seq = 0
for page in survey.page_ids:
seq+=1
seq += 1
rml += """
<blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl">
<tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para></td></tr>
@ -169,9 +172,10 @@ class survey_form(report_rml):
rml += """<para style="P2"></para><blockTable colWidths='"""+_tbl_widths+"""' style="note_table">
<tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(page.note or '')) + """</para></td></tr>
</blockTable>"""
for que in page.question_ids:
cols_widhts=[]
rml +="""
cols_widhts = []
rml += """
<para style="P2"><font></font></para>
<blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl">
<tr><td><para style="question">""" + to_xml(tools.ustr(que.question)) + """</para></td></tr>
@ -180,8 +184,8 @@ class survey_form(report_rml):
if que.type in ['descriptive_text']:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths+'cm'
rml+="""
colWidths = colWidths + 'cm'
rml += """
<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
<tr>
<td>
@ -189,8 +193,9 @@ class survey_form(report_rml):
</td>
</tr>
</blockTable>"""
elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']:
answer=[]
answer = []
for ans in que.answer_choice_ids:
answer.append(to_xml(tools.ustr((ans.answer))))
@ -207,18 +212,19 @@ class survey_form(report_rml):
for divide in divide_list:
a = _divide_columns_for_matrix*len(divide)
b = float(_tbl_widths.replace('cm','')) - float(a)
cols_widhts=[]
cols_widhts = []
for div in range(0,len(divide)):
cols_widhts.append(float(a/len(divide)))
cols_widhts.append(float(b/len(divide)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths+'cm'
colWidths = colWidths +'cm'
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
<tr>"""
for div in range(0,len(divide)):
if divide[div]!='':
if divide[div] != '':
if que.type == 'multiple_choice_multiple_ans':
rml+="""
rml += """
<td>
<illustration>
<rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/>
@ -226,7 +232,7 @@ class survey_form(report_rml):
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml+="""
rml += """
<td>
<illustration>
<circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/>
@ -234,11 +240,12 @@ class survey_form(report_rml):
</td>
<td><para style="answer">""" + divide[div] + """</para></td>"""
else:
rml+="""
rml += """
<td></td>
<td></td>"""
rml+="""
rml += """
</tr></blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale','matrix_of_choices_only_multi_ans','matrix_of_drop_down_menus']:
if len(que.column_heading_ids):
cols_widhts.append(float(_tbl_widths.replace('cm',''))/float(2.0))
@ -246,42 +253,45 @@ class survey_form(report_rml):
cols_widhts.append(float((float(_tbl_widths.replace('cm',''))/float(2.0))/len(que.column_heading_ids)))
else:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
tmp=0.0
tmp = 0.0
sum = 0.0
i = 0
if que.comment_column:
for col in cols_widhts:
if i==0:
if i == 0:
cols_widhts[i] = cols_widhts[i]/2.0
tmp = cols_widhts[i]
sum += col
i+=1
i += 1
cols_widhts.append(round(tmp,2))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths+'cm'
matrix_ans = ['',]
for col in que.column_heading_ids:
if col.title not in matrix_ans:
matrix_ans.append(col.title)
if que.comment_column:
matrix_ans.append(to_xml(tools.ustr(que.column_name)))
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl">
<tr>"""
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"><tr>"""
for mat_col in matrix_ans:
rml+="""<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml+="""</tr></blockTable>"""
i=0
rml += """<td><para style="response">""" + to_xml(tools.ustr(mat_col)) + """</para></td>"""
rml += """</tr></blockTable>"""
i = 0
for ans in que.answer_choice_ids:
if i%2!=0:
if i%2 != 0:
style='ans_tbl_white'
else:
style='ans_tbl_gainsboro'
i+=1
rml+="""
i += 1
rml += """
<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
<tr><td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
rec_width = float((sum-tmp)*10+100)
value = ""
if que.type in ['matrix_of_drop_down_menus']:
value = """ <fill color="white"/>
<rect x="-0.1cm" y="-0.45cm" width='""" + tools.ustr(cols_widhts[-1] - 0.5) +"cm" + """' height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
@ -292,22 +302,23 @@ class survey_form(report_rml):
value = """ <fill color="white"/>
<rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>"""
for mat_col in range(1,len(matrix_ans)):
if matrix_ans[mat_col]==que.column_name:
if mat_col==1:
rml+="""
if matrix_ans[mat_col] == que.column_name:
if mat_col == 1:
rml += """
<td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>"""
else:
rml+="""<td></td>"""
rml += """<td></td>"""
else:
rml+="""<td><illustration>""" + value + """</illustration></td>"""
rml+= """</tr></blockTable>"""
elif que.type in ['multiple_textboxes','numerical_textboxes', 'date_and_time','date','multiple_textboxes_diff_type']:
rml += """<td><illustration>""" + value + """</illustration></td>"""
rml += """</tr></blockTable>"""
elif que.type in ['multiple_textboxes', 'numerical_textboxes', 'date_and_time','date','multiple_textboxes_diff_type']:
cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
cols_widhts.append(float(_tbl_widths.replace('cm',''))/2)
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = tools.ustr(colWidths) + 'cm'
for ans in que.answer_choice_ids:
rml +="""<para style="P1"></para>
rml += """<para style="P1"></para>
<blockTable colWidths=" """+ colWidths + """ " style="ans_tbl">
<tr>
<td><para style="answer">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>
@ -318,10 +329,11 @@ class survey_form(report_rml):
</td>
</tr>
</blockTable>"""
elif que.type in ['comment']:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
rml+="""<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
rml += """<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
<tr>
<td><para style="comment"><font color="white"> </font></para>
<illustration>
@ -330,10 +342,11 @@ class survey_form(report_rml):
</td>
</tr>
</blockTable>"""
elif que.type in ['single_textbox']:
cols_widhts.append(float(_tbl_widths.replace('cm','')))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
rml+="""<para style="P2"><font color="white"> </font></para>
rml += """<para style="P2"><font color="white"> </font></para>
<blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl">
<tr>
<td>
@ -343,39 +356,44 @@ class survey_form(report_rml):
</td>
</tr>
</blockTable>"""
elif que.type in ['table']:
tbl_width = float(_tbl_widths.replace('cm',''))
for i in range(0,len(que.column_heading_ids)):
cols_widhts.append(tbl_width/float(len(que.column_heading_ids)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths+'cm'
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="tbl"><tr>"""
rml += """<blockTable colWidths=" """ + colWidths + """ " style="tbl"><tr>"""
for col in que.column_heading_ids:
rml+="""<td><para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) + """</para></td>"""
rml+="""</tr></blockTable>"""
i=0
rml += """</tr></blockTable>"""
i = 0
for r in range(0,que.no_of_rows):
if i%2!=0:
style='tbl_white'
if i%2 != 0:
style = 'tbl_white'
else:
style='tbl_gainsboro'
i+=1
rml+="""<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'><tr>"""
style = 'tbl_gainsboro'
i += 1
rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'><tr>"""
for c in que.column_heading_ids:
rml+="""
rml += """
<td><para style="terp_default_9"><font color="white"> </font></para></td>"""
rml+="""</tr></blockTable>"""
rml += """</tr></blockTable>"""
if datas.has_key('form') and not datas['form']['without_pagebreak']:
rml+="""<pageBreak/>"""
rml += """<pageBreak/>"""
elif not datas.has_key('form'):
rml+="""<pageBreak/>"""
rml += """<pageBreak/>"""
else:
rml+="""<para style="P2"><font></font></para>"""
rml+="""</story></document>"""
rml += """<para style="P2"><font></font></para>"""
rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type]
pdf = create_doc(rml, title=self.title)
return (pdf, report_type)
survey_form('report.survey.form', 'survey','','')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: