[IMP]:survey-(Ref-YSA)

-Improved survey browse response report with print option.

bzr revid: apa@tinyerp.com-20100209072937-80cjw1q7lqhx5dnj
This commit is contained in:
apa-tiny 2010-02-09 12:59:37 +05:30
parent a7acb84fa2
commit 9069425fd4
2 changed files with 265 additions and 204 deletions

View File

@ -28,13 +28,61 @@ import time
class survey_browse_response(report_rml): class survey_browse_response(report_rml):
def create(self, cr, uid, ids, datas, context): def create(self, cr, uid, ids, datas, context):
rml ="""<document filename="Survey Analysis Report.pdf"> _divide_columns_for_matrix = 0.7
<template pageSize="(595.0,842.0)" title="Test" author="Martin Simon" allowSplitting="20"> _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':
_pageSize = ('21.6cm','27.9cm')
elif datas['form']['paper_size']=='legal':
_pageSize = ('21.6cm','35.6cm')
elif datas['form']['paper_size']=='a4':
_pageSize = ('21.1cm','29.7cm')
elif datas.has_key('form') and datas['form']['orientation']=='horizontal':
if datas['form']['paper_size']=='letter':
_pageSize = ('27.9cm','21.6cm')
elif datas['form']['paper_size']=='legal':
_pageSize = ('35.6cm','21.6cm')
elif datas['form']['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 Response Report.pdf">
<template pageSize="("""+_pageSize[0]+""","""+_pageSize[1]+""")" title='Survey Response.pdf' author="Martin Simon" allowSplitting="20" >
<pageTemplate id="first"> <pageTemplate id="first">
<frame id="first" x1="57.0" y1="57.0" width="481" height="728"/> <frame id="first" x1="0.0cm" y1="1.0cm" width='"""+_frame_width+"""' height='"""+_frame_height+"""'/>
</pageTemplate> <pageGraphics>
</template> <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>"""
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>"""
rml +="""</pageGraphics>
</pageTemplate>
</template>
<stylesheet> <stylesheet>
<blockTableStyle id="tbl_white">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="tbl_gainsboro">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBEFORE" colorName="#777777" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#777777" start="0,0" stop="-1,-1"/>
<blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
</blockTableStyle>
<blockTableStyle id="ans_tbl_white"> <blockTableStyle id="ans_tbl_white">
<blockAlignment value="LEFT"/> <blockAlignment value="LEFT"/>
<blockValign value="TOP"/> <blockValign value="TOP"/>
@ -46,7 +94,7 @@ class survey_browse_response(report_rml):
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" start="0,0" stop="-1,-1"/>
</blockTableStyle> </blockTableStyle>
<blockTableStyle id="Table1"> <blockTableStyle id="simple_table">
<blockAlignment value="LEFT"/> <blockAlignment value="LEFT"/>
<blockValign value="TOP"/> <blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6"/>
@ -91,22 +139,25 @@ class survey_browse_response(report_rml):
<blockTableStyle id="Table_heading"> <blockTableStyle id="Table_heading">
<blockAlignment value="LEFT"/> <blockAlignment value="LEFT"/>
<blockValign value="TOP"/> <blockValign value="TOP"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/>
</blockTableStyle> </blockTableStyle>
<blockTableStyle id="Table_head_2"> <blockTableStyle id="title_tbl">
<blockAlignment value="LEFT"/> <blockAlignment value="LEFT"/>
<blockValign value="TOP"/> <blockValign value="TOP"/>
<lineStyle kind="LINEBEFORE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
<lineStyle kind="LINEAFTER" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockBackground colorName="black" start="0,0" stop="-1,-1"/>
<lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/>
<lineStyle kind="LINEABOVE" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle>
<blockTableStyle id="page_tbl">
<blockAlignment value="LEFT"/>
<blockValign value="TOP"/>
<lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/>
<blockBackground colorName="gray" start="0,0" stop="-1,-1"/>
<blockTextColor colorName="white" start="0,0" stop="0,0"/>
</blockTableStyle> </blockTableStyle>
<initialize> <initialize>
<paraStyle name="all" alignment="justify"/> <paraStyle name="all" alignment="justify"/>
</initialize> </initialize>
<paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
<paraStyle name="answer_right" alignment="RIGHT" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/> <paraStyle name="answer_right" alignment="RIGHT" fontName="helvetica" fontSize="09.0" leftIndent="2.0"/>
<paraStyle name="Standard1" fontName="helvetica-bold" alignment="RIGHT" fontSize="09.0"/> <paraStyle name="Standard1" fontName="helvetica-bold" alignment="RIGHT" fontSize="09.0"/>
<paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/> <paraStyle name="Standard" alignment="LEFT" fontName="Helvetica-Bold" fontSize="11.0"/>
@ -123,107 +174,96 @@ class survey_browse_response(report_rml):
<paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/> <paraStyle name="P1" fontName="Helvetica" fontSize="9.0" leading="12" spaceBefore="0.0" spaceAfter="1.0"/>
<paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_Details" fontName="Helvetica-Bold" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/>
<paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="terp_tblheader_General_Centre_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_default_Centre_8" fontName="Helvetica" fontSize="9.0" leading="10" alignment="CENTER" spaceBefore="0.0" spaceAfter="0.0"/> <paraStyle name="terp_tblheader_General_Centre" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="LEFT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General_right_simple" fontName="Helvetica" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="terp_tblheader_General_right" fontName="Helvetica-Bold" fontSize="10.0" leading="10" alignment="RIGHT" spaceBefore="6.0" spaceAfter="6.0"/>
<paraStyle name="descriptive_text" fontName="helvetica-bold" fontSize="18.0" leftIndent="0.0" textColor="white"/>
<paraStyle name="descriptive_text_heading" fontName="helvetica-bold" fontSize="18.0" alignment="RIGHT" leftIndent="0.0" textColor="white"/>
</stylesheet> </stylesheet>
<images/> <images/>
<story> <story>"""
<para style="Title"><u>Browse Responses </u></para>
<para style="Standard"><font></font></para>
<para style="P2">
<font color="white"> </font>
</para>
"""
surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response') surv_resp_obj = pooler.get_pool(cr.dbname).get('survey.response')
if datas.has_key('form') and datas['form'].has_key('response_ids'): if datas.has_key('form') and datas['form'].has_key('response_ids'):
response_id = datas['form']['response_ids'][0][2] response_id = datas['form']['response_ids'][0][2]
elif context.has_key('response_id'): elif context.has_key('response_id'):
response_id = [int(context['response_id'])] response_id = [int(context['response_id'])]
else: else:
response_id = surv_resp_obj.search(cr, uid, [('survey_id','in',ids)]) 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_resp_line_obj = pooler.get_pool(cr.dbname).get('survey.response.line')
surv_obj = pooler.get_pool(cr.dbname).get('survey') surv_obj = pooler.get_pool(cr.dbname).get('survey')
surv_ans_obj = pooler.get_pool(cr.dbname).get('survey.answer') surv_ans_obj = pooler.get_pool(cr.dbname).get('survey.answer')
for response in surv_resp_obj.browse(cr,uid, response_id): for response in surv_resp_obj.browse(cr, uid, response_id):
for survey in surv_obj.browse(cr, uid, [response.survey_id.id]): for survey in surv_obj.browse(cr, uid, [response.survey_id.id]):
tbl_width = float(_tbl_widths.replace('cm', ''))
colwidth = "4.6cm,5cm," + str(tbl_width - 16.4) +"cm,4cm,3cm"
rml += """<blockTable colWidths='""" + colwidth + """' style="Table_heading">
<tr>
<td><para style="terp_tblheader_General_Centre">Response Create Date:- </para></td>
<td><para style="terp_tblheader_General_Centre_simple">""" + to_xml(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """</para></td>
<td><para style="terp_tblheader_General_Centre"></para></td>
<td><para style="terp_tblheader_General_right">Response By:- </para></td>
<td><para style="terp_tblheader_General_right_simple">""" + to_xml(response.user_id.name) + """</para></td>
</tr>
</blockTable><para style="P2"></para>"""
status = "Not Finished" status = "Not Finished"
if response.state == "done": if response.state == "done": status = "Finished"
status = "Finished" colwidth = str(tbl_width - 7) + "cm,"
rml += """<blockTable colWidths="210.0,120.0,100.0,70" style="Table_heading"> colwidth += "7cm"
<tr> rml += """<blockTable colWidths='""" + str(colwidth) + """' style="title_tbl">
<td> <tr>
<para style="terp_tblheader_General_Centre">Survey Title </para> <td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td>
</td> <td><para style="descriptive_text_heading">Status :- """ + to_xml(tools.ustr(status)) + """</para><para style="P2"><font></font></para></td>
<td> </tr>
<para style="terp_tblheader_General_Centre">Response Create Date </para> </blockTable>"""
</td> if survey.note:
<td> rml += """<blockTable colWidths='""" + _tbl_widths + """' style="note_table">
<para style="terp_tblheader_General_Centre">Response By </para> <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(survey.note)) + """</para><para style="P2"><font></font></para></td></tr>
</td>
<td>
<para style="terp_tblheader_General_Centre">Status</para>
</td>
</tr>
</blockTable>
<blockTable colWidths="210.0,120.0,100.0,70" 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">""" + to_xml(time.strftime('%d-%m-%Y %I:%M:%S %p', time.strptime(response.date_create.split('.')[0], '%Y-%m-%d %H:%M:%S'))) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + to_xml(response.user_id.name) + """</para>
</td>
<td>
<para style="terp_default_Centre_8">""" + status + """</para>
</td>
</tr>
</blockTable>""" </blockTable>"""
for page in survey.page_ids: for page in survey.page_ids:
rml += """<para style="P2"></para> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="page_tbl">
<blockTable colWidths="500" style="Table4"> <tr><td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td></tr>
<tr> </blockTable>"""
<td><para style="page">Page :- """ + to_xml(tools.ustr(page.title)) + """</para></td>
</tr>
</blockTable>"""
if page.note: if page.note:
rml += """<para style="P2"></para> rml += """<para style="P2"></para>
<blockTable colWidths="500" style="note_table"> <blockTable colWidths='""" + str(_tbl_widths) + """' style="note_table">
<tr> <tr><td><para style="response">""" + to_xml(tools.ustr(page.note)) + """</para></td></tr>
<td><para style="response">""" + to_xml(tools.ustr(page.note)) + """</para></td> </blockTable>"""
</tr>
</blockTable>"""
for que in page.question_ids: for que in page.question_ids:
rml += """<para style="P2"></para> rml += """<para style="P2"></para>
<blockTable colWidths="500" style="Table5"> <blockTable colWidths='""" + str(_tbl_widths) + """' style="Table5">
<tr> <tr><td><para style="question">Que : """ + to_xml(to_xml(que.question)) + """</para></td></tr>
<td><para style="question">Que : """ + to_xml(to_xml(que.question)) + """</para></td> </blockTable>"""
</tr> answer = surv_resp_line_obj.browse(cr ,uid, surv_resp_line_obj.search(cr, uid, [('question_id', '=', que.id),('response_id', '=', response.id)]))
</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']: if que.type in ['descriptive_text']:
rml +="""<blockTable colWidths="500" style="Table1"> rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr> <tr><td> <para style="response">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para></td> </tr>
</blockTable>""" </blockTable>"""
elif que.type in ['table']: elif que.type in ['table']:
if len(answer) and answer[0].state == "done": if len(answer) and answer[0].state == "done":
col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading') col_heading = pooler.get_pool(cr.dbname).get('survey.tbl.column.heading')
cols_widhts = [] cols_widhts = []
for col in range(0, len(que.column_heading_ids)): tbl_width = float(_tbl_widths.replace('cm', ''))
cols_widhts.append(float(500 / (len(que.column_heading_ids)))) for i in range(0, len(que.column_heading_ids)):
colWidths = ",".join(map(tools.ustr, cols_widhts)) cols_widhts.append(tbl_width / float(len(que.column_heading_ids)))
colWidths = "cm,".join(map(tools.ustr, cols_widhts))
colWidths = colWidths + 'cm'
matrix_ans = [] matrix_ans = []
rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>""" rml +="""<para style="P2"></para><blockTable colWidths=" """ + str(colWidths) + """ " style="Table41"><tr>"""
for col in que.column_heading_ids: for col in que.column_heading_ids:
if col.title not in matrix_ans: if col.title not in matrix_ans:
matrix_ans.append(col.title) matrix_ans.append(col.title)
rml +="""<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>""" rml += """<td> <para style="terp_tblheader_Details">""" + to_xml(tools.ustr(col.title)) +"""</para></td>"""
rml += """</tr></blockTable>""" rml += """</tr></blockTable>"""
i = 0
for row in range(0, que.no_of_rows): for row in range(0, que.no_of_rows):
rml +="""<blockTable colWidths=" """ + str(colWidths) + """ " style="Table51"><tr>""" if i%2!=0:
table_data = col_heading.browse(cr, uid, col_heading.search(cr, uid, [('response_table_id', '=', answer[0].id),('name','=',row)])) style='tbl_white'
else:
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: for column in matrix_ans:
value = False value = False
for col in table_data: for col in table_data:
@ -235,19 +275,15 @@ class survey_browse_response(report_rml):
rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>""" rml += """<td><para style="terp_default_9"><font color ="white"> </font></para></td>"""
rml += """</tr></blockTable>""" rml += """</tr></blockTable>"""
else: else:
rml +="""<blockTable colWidths="500" style="Table1"> rml +="""<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr> <tr><td> <para style="response">No Response</para></td> </tr>
</blockTable>""" </blockTable>"""
elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']: elif que.type in ['multiple_choice_only_one_ans','multiple_choice_multiple_ans']:
if len(answer) and answer[0].state == "done": if len(answer) and answer[0].state == "done":
ans_list = [] ans_list = []
for ans in answer[0].response_answer_ids: for ans in answer[0].response_answer_ids:
ans_list.append(to_xml(tools.ustr(ans.answer_id.answer))) ans_list.append(to_xml(tools.ustr(ans.answer_id.answer)))
answer_choice=[] answer_choice=[]
_divide_columns_for_matrix = 20
_display_ans_in_rows = 5
_tbl_widths = 500
for ans in que['answer_choice_ids']: for ans in que['answer_choice_ids']:
answer_choice.append(to_xml(tools.ustr((ans.answer)))) answer_choice.append(to_xml(tools.ustr((ans.answer))))
@ -257,38 +293,35 @@ class survey_browse_response(report_rml):
divide_list = divide_list(answer_choice,_display_ans_in_rows) divide_list = divide_list(answer_choice,_display_ans_in_rows)
for lst in divide_list: for lst in divide_list:
if que.type == 'multiple_choice_multiple_ans': if que.type == 'multiple_choice_multiple_ans':
if len(lst)<>0 and len(lst)<>int(round(float(len(answer_choice))/_display_ans_in_rows,0)): if len(lst) <> 0 and len(lst) <> int(round(float(len(answer_choice)) / _display_ans_in_rows, 0)):
lst.append('') lst.append('')
if not lst: if not lst:
del divide_list[divide_list.index(lst):] del divide_list[divide_list.index(lst):]
for divide in divide_list: for divide in divide_list:
a = _divide_columns_for_matrix*len(divide) a = _divide_columns_for_matrix * len(divide)
b = float(_tbl_widths) - float(a) b = float(_tbl_widths.replace('cm', '')) - float(a)
cols_widhts=[] cols_widhts = []
for div in range(0,len(divide)): for div in range(0, len(divide)):
cols_widhts.append(float(a/len(divide))) cols_widhts.append(float(a / len(divide)))
cols_widhts.append(float(b/len(divide))) cols_widhts.append(float(b / len(divide)))
colWidths = ",".join(map(tools.ustr, cols_widhts)) colWidths = "cm,".join(map(tools.ustr, cols_widhts))
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"> colWidths = colWidths +'cm'
<tr>""" rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
for div in range(0,len(divide)): for div in range(0, len(divide)):
if divide[div]!='': if divide[div] != '':
if que.type == 'multiple_choice_multiple_ans': if que.type == 'multiple_choice_multiple_ans':
if divide[div] in ans_list: if divide[div] in ans_list:
rml += """<td><illustration><fill color="white"/> rml += """<td><illustration><fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/> <fill color="gray"/>
<rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration></td> </illustration></td>
<td><para style="answer">""" + divide[div] + """</para></td>""" <td><para style="answer">""" + divide[div] + """</para></td>"""
else: else:
rml+=""" rml+="""<td><illustration>
<td>
<illustration>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes" round="0.1cm"/>
</illustration> </illustration></td>
</td> <td><para style="answer">""" + divide[div] + """</para></td>"""
<td><para style="answer">""" + divide[div] + """</para></td>"""
else: else:
if divide[div] in ans_list: if divide[div] in ans_list:
rml += """<td><illustration><fill color="white"/> rml += """<td><illustration><fill color="white"/>
@ -298,154 +331,162 @@ class survey_browse_response(report_rml):
</illustration></td> </illustration></td>
<td><para style="answer">""" + divide[div] + """</para></td>""" <td><para style="answer">""" + divide[div] + """</para></td>"""
else: else:
rml+=""" rml += """<td>
<td> <illustration>
<illustration> <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/>
<circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes" round="0.1cm"/> </illustration>
</illustration> </td>
</td> <td><para style="answer">""" + divide[div] + """</para></td>"""
<td><para style="answer">""" + divide[div] + """</para></td>"""
else: else:
rml+=""" rml += """<td></td><td></td>"""
<td></td> rml += """</tr></blockTable>"""
<td></td>"""
rml+="""</tr></blockTable>"""
if que.is_comment_require and answer[0].comment: if que.is_comment_require and answer[0].comment:
rml+="""<blockTable colWidths="500" style="Table1"><tr> 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>""" <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr></blockTable>"""
else: else:
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr> <tr><td> <para style="response">No Response</para></td> </tr>
</blockTable>""" </blockTable>"""
elif que.type in ['multiple_textboxes_diff_type','multiple_textboxes','date','date_and_time','numerical_textboxes','multiple_textboxes_diff_type']: 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": if len(answer) and answer[0].state == "done":
cols_widhts = []
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'
answer_list = {} answer_list = {}
for ans in answer[0].response_answer_ids: for ans in answer[0].response_answer_ids:
answer_list[ans.answer_id.answer] = ans.answer answer_list[ans.answer_id.answer] = ans.answer
for que_ans in que['answer_choice_ids']: for que_ans in que['answer_choice_ids']:
if que_ans.answer in answer_list: if que_ans.answer in answer_list:
rml +="""<blockTable colWidths="200,300" style="Table1"> rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td> <tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
<td> <para style="response">""" + to_xml(tools.ustr(answer_list[que_ans.answer])) + """</para></td></tr> <td> <para style="response">""" + to_xml(tools.ustr(answer_list[que_ans.answer])) + """</para></td></tr>
</blockTable>""" </blockTable>"""
else: else:
rml +="""<blockTable colWidths="200,300" style="Table1"> rml += """<blockTable colWidths='""" + str(colWidths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td> <tr> <td> <para style="response">""" + to_xml(tools.ustr(que_ans.answer)) + """</para></td>
<td> <para style="response"></para></td></tr> <td> <para style="response"></para></td></tr>
</blockTable>""" </blockTable>"""
else: else:
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr> <tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>""" </blockTable>"""
elif que.type in ['single_textbox']: elif que.type in ['single_textbox']:
if len(answer) and answer[0].state == "done": if len(answer) and answer[0].state == "done":
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr> <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].single_text)) + """</para></td></tr>
</blockTable>""" </blockTable>"""
else: else:
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr> <tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>""" </blockTable>"""
elif que.type in ['comment']: elif que.type in ['comment']:
if len(answer) and answer[0].state == "done": if len(answer) and answer[0].state == "done":
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr> <tr> <td> <para style="response">""" + to_xml(tools.ustr(answer[0].comment)) + """</para></td></tr>
</blockTable>""" </blockTable>"""
else: else:
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr> <tr> <td> <para style="response">No Response</para></td> </tr>
</blockTable>""" </blockTable>"""
elif que.type in ['matrix_of_choices_only_one_ans','matrix_of_choices_only_multi_ans','rating_scale','matrix_of_drop_down_menus']: 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 len(answer) and answer[0].state == "done":
if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
pass pass
cols_widhts = [] cols_widhts = []
cols_widhts.append(200) if len(que.column_heading_ids):
len_col_heading = len(que.column_heading_ids) cols_widhts.append(float(_tbl_widths.replace('cm','')) / float(2.0))
for col in range(0, len_col_heading): for col in que.column_heading_ids:
cols_widhts.append(float(300 / len_col_heading)) cols_widhts.append(float((float(_tbl_widths.replace('cm','')) / float(2.0)) / len(que.column_heading_ids)))
tmp=0.0 else:
sum = 0.0 cols_widhts.append(float(_tbl_widths.replace('cm','')))
tmp = 0.0
sum = 0.0
i = 0 i = 0
if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
for col in cols_widhts: for col in cols_widhts:
if i==0: if i == 0:
cols_widhts[i] = cols_widhts[i]/2.0 cols_widhts[i] = cols_widhts[i] / 2.0
tmp = cols_widhts[i] tmp = cols_widhts[i]
sum += col sum += col
i+=1 i += 1
cols_widhts.append(round(tmp,2)) cols_widhts.append(round(tmp, 2))
colWidths = ",".join(map(tools.ustr, cols_widhts)) colWidths = "cm,".join(map(tools.ustr, cols_widhts))
matrix_ans = [(0,''),] colWidths = colWidths + 'cm'
matrix_ans = [(0, ''),]
for col in que.column_heading_ids: for col in que.column_heading_ids:
if col.title not in matrix_ans: if col.title not in matrix_ans:
matrix_ans.append((col.id,col.title)) matrix_ans.append((col.id, col.title))
len_matrix = len(matrix_ans) len_matrix = len(matrix_ans)
if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: if que.type in ['matrix_of_choices_only_one_ans', 'rating_scale'] and que.comment_column:
matrix_ans.append(que.column_name) matrix_ans.append(que.column_name)
rml+="""<blockTable colWidths=" """ + colWidths + """ " style="Table1"><tr>""" rml += """<blockTable colWidths=" """ + colWidths + """ " style="simple_table"><tr>"""
for mat_col in range(0, len(matrix_ans)): 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">""" + to_xml(tools.ustr(matrix_ans[mat_col][1])) + """</para></td>"""
rml +="""</tr>""" rml +="""</tr>"""
rml+="""</blockTable>""" rml+="""</blockTable>"""
i=0 i=0
for ans in que.answer_choice_ids: for ans in que.answer_choice_ids:
if i%2!=0: if i%2 != 0:
style='ans_tbl_white' style = 'ans_tbl_white'
else: else:
style='ans_tbl_gainsboro' style = 'ans_tbl_gainsboro'
i+=1 i += 1
rml+="""<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'> rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'>
<tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>""" <tr><td><para style="response">""" + to_xml(tools.ustr(ans.answer)) + """</para></td>"""
comment_value = "" comment_value = ""
for mat_col in range(1, len_matrix): for mat_col in range(1, len_matrix):
value = """""" value = """"""
for res_ans in answer[0].response_answer_ids: for res_ans in answer[0].response_answer_ids:
if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[mat_col][0]: if res_ans.answer_id.id == ans.id and res_ans.column_id.id == matrix_ans[mat_col][0]:
comment_value = to_xml(tools.ustr(res_ans.comment_field)) comment_value = to_xml(tools.ustr(res_ans.comment_field))
if que.type in ['matrix_of_drop_down_menus']: if que.type in ['matrix_of_drop_down_menus']:
value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>""" value = """<para style="response">""" + to_xml(tools.ustr(res_ans.value_choice)) + """</para>"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: elif que.type in ['matrix_of_choices_only_one_ans', 'rating_scale']:
value = """<illustration><fill color="white"/> value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes"/>
<fill color="gray"/> <fill color="gray"/>
<circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/> <circle x="0.3cm" y="-0.18cm" radius="0.10 cm" fill="yes" stroke="no"/>
</illustration>""" </illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']: elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration> value = """<illustration>
<fill color="white"/> <fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
<fill color="gray"/> <fill color="gray"/>
<rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/> <rect x="0.2cm" y="-0.35cm" width="0.3 cm" height="0.3cm" fill="yes" stroke="no" round="0.1cm"/>
</illustration>""" </illustration>"""
break break
else: else:
if que.type in ['matrix_of_drop_down_menus']: if que.type in ['matrix_of_drop_down_menus']:
value = """""" value = """"""
elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']:
value = """<illustration><fill color="white"/> value = """<illustration><fill color="white"/>
<circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/> <circle x="0.3cm" y="-0.18cm" radius="0.22 cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>""" </illustration>"""
elif que.type in ['matrix_of_choices_only_multi_ans']: elif que.type in ['matrix_of_choices_only_multi_ans']:
value = """<illustration><fill color="white"/> value = """<illustration><fill color="white"/>
<rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/> <rect x="0.1cm" y="-0.45cm" width="0.5 cm" height="0.5cm" fill="yes" stroke="yes" round="0.1cm"/>
</illustration>""" </illustration>"""
rml+= """<td>""" + value + """</td>""" rml+= """<td>""" + value + """</td>"""
if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column: if que.type in ['matrix_of_choices_only_one_ans','rating_scale'] and que.comment_column:
if comment_value=='False': if comment_value == 'False':
comment_value = '' comment_value = ''
rml+= """<td><para style="response">"""+ to_xml(tools.ustr(comment_value)) + """</para></td>""" rml += """<td><para style="response">""" + to_xml(tools.ustr(comment_value)) + """</para></td>"""
rml+=""" </tr></blockTable>""" rml += """</tr></blockTable>"""
if que.is_comment_require: if que.is_comment_require:
rml+="""<blockTable colWidths="500" style="Table1"><tr> 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>""" <td><para style="answer">""" + to_xml(tools.ustr(answer[0].comment or '')) + """</para></td></tr></blockTable>"""
else: else:
rml +="""<blockTable colWidths="500" style="Table1"> rml += """<blockTable colWidths='""" + str(_tbl_widths) + """' style="simple_table">
<tr> <td> <para style="response">No Response</para></td> </tr> <tr><td> <para style="response">No Response</para></td> </tr>
</blockTable>""" </blockTable>"""
if datas.has_key('form') and not datas['form']['without_pagebreak']:
rml += """<pageBreak/>""" rml += """<pageBreak/>"""
elif not datas.has_key('form'):
rml += """<pageBreak/>"""
else:
rml += """<para style="P2"><font></font></para>"""
rml += """</story></document>""" rml += """</story></document>"""
report_type = datas.get('report_type', 'pdf') report_type = datas.get('report_type', 'pdf')
create_doc = self.generators[report_type] create_doc = self.generators[report_type]
@ -455,4 +496,3 @@ class survey_browse_response(report_rml):
survey_browse_response('report.survey.browse.response', 'survey','','') survey_browse_response('report.survey.browse.response', 'survey','','')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -30,11 +30,32 @@ from tools.translate import _
_survey_form = '''<?xml version="1.0"?> _survey_form = '''<?xml version="1.0"?>
<form string="Browse Answer"> <form string="Browse Answer">
<field name="response_ids" colspan="4" nolabel="1"/> <separator string="Responses" colspan="4"/>
<field name="response_ids" colspan="4" nolabel="1"/>
<separator string="Print Option" colspan="4"/>
<field name="orientation" colspan="4"/>
<field name="paper_size" colspan="4"/>
<field name="page_number" colspan="4"/>
<field name="without_pagebreak" colspan="4"/>
</form>''' </form>'''
_survey_fields = { _survey_fields = {
'response_ids': {'string': 'Survey', 'type': 'many2many', 'relation': 'survey.response'}, 'response_ids': {'string': 'Survey', 'type': 'many2many', 'relation': 'survey.response','required':'1'},
'orientation':{
'string':"Orientation",
'type':'selection',
'selection':[('vertical','Portrait(Vertical)'),
('horizontal','Landscape(Horizontal)')],
'default': lambda *a:'vertical'},
'paper_size':{
'string':"Paper Size",
'type':'selection',
'selection':[('letter','Letter (8.5" x 11")'),
('legal','Legal (8.5" x 14")'),
('a4','A4 (210mm x 297mm)')],
'default': lambda *a:'letter'},
'page_number': {'string':'Include Page Numbers', 'type':'boolean', 'default':lambda *a: 0},
'without_pagebreak': {'string':'Print Without Page Breaks', 'type':'boolean', 'default':lambda *a: 0},
} }
class browse_answer_wizard(wizard.interface): class browse_answer_wizard(wizard.interface):