def translate_view(self, cr, node, state, lang): if node.get('string'): trans = translate(cr, self.wiz_name+','+state, 'wizard_view', lang, node.get('string').encode('utf8')) if trans: node.set('string', trans) for n in node: self.translate_view(cr, n, state, lang)
def tr(src, ttype): # We try to do the same as the _(), but without the frame # inspection, since we aready are wrapping an osv function # trans_obj = self.get('ir.translation') cannot work yet :( ctx = {} if not kwargs: if args and isinstance(args[-1], dict): ctx = args[-1] elif isinstance(kwargs, dict): # kwargception because call_kw set its context in kwargs['kwargs'] ctx = kwargs.get('context', kwargs.get('kwargs', {}).get('context', {})) uid = 1 if args and isinstance(args[0], (long, int)): uid = args[0] lang = ctx and ctx.get('lang') if not (lang or hasattr(src, '__call__')): return src # We open a *new* cursor here, one reason is that failed SQL # queries (as in IntegrityError) will invalidate the current one. cr = False if hasattr(src, '__call__'): # callable. We need to find the right parameters to call # the orm._sql_message(self, cr, uid, ids, context) function, # or we skip.. # our signature is f(registry, dbname [,uid, obj, method, args]) try: if args and len(args) > 1: # TODO self doesn't exist, but was already wrong before (it was not a registry but just the object_service. obj = self.get(args[1]) if len(args) > 3 and isinstance(args[3], (long, int, list)): ids = args[3] else: ids = [] cr = openerp.sql_db.db_connect(dbname).cursor() return src(obj, cr, uid, ids, context=(ctx or {})) except Exception: pass finally: if cr: cr.close() return False # so that the original SQL error will # be returned, it is the best we have. try: cr = openerp.sql_db.db_connect(dbname).cursor() res = translate(cr, name=False, source_type=ttype, lang=lang, source=src) if res: return res else: return src finally: if cr: cr.close()
def _(self, src): lang = self.context.get('lang', 'en_US') return translate(self.cr, _ir_translation_name, 'report', lang, src) \ or src
def translate_view(source): """Return a translation of type view of source.""" return translate( cr, None, 'view', context.get('lang'), source ) or source
def _(self, src): lang = self.context.get("lang", "en_US") res = translate(self.cr, _ir_translation_name, "report", lang, src) return res or src
def _(self, src): lang = self.context.get('lang', 'en_US') return translate(self.cr, 'report.smove', 'report', lang, src) or src
def create(self, cr, uid, ids, datas, context): _divide_columns_for_matrix = 0.7 _display_ans_in_rows = 5 _pageSize = ('29.7cm','21.1cm') 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'].get('paper_size','') == 'legal': _pageSize = ('21.6cm','35.6cm') elif datas['form'].get('paper_size','') == 'a4': _pageSize = ('21.1cm','29.7cm') elif datas.has_key('form') and datas['form'].get('orientation','') == 'horizontal': if datas['form'].get('paper_size','') == 'letter': _pageSize = ('27.9cm','21.6cm')/style elif datas['form'].get('paper_size','') == 'legal': _pageSize = ('35.6cm','21.6cm') 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' author="OpenERP S.A.([email protected])" 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>""" 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> <blockTableStyle id="ans_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <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"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> </blockTableStyle> <blockTableStyle id="ans_tbl_gainsboro"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#e6e6e6" start="0,0" stop="-1,-1"/> <blockBackground colorName="gainsboro" 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 id="title_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" start="0,-1" stop="1,-1"/> <blockBackground colorName="black" start="0,0" stop="-1,-1"/> <blockTextColor colorName="white" start="0,0" stop="0,0"/> </blockTableStyle> <blockTableStyle id="question_tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#8f8f8f" start="0,-1" stop="1,-1"/> </blockTableStyle> <blockTableStyle id="note_table"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> </blockTableStyle> <blockTableStyle id="tbl"> <blockAlignment value="LEFT"/> <blockValign value="TOP"/> <lineStyle kind="LINEBELOW" colorName="#000000" 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> <initialize> <paraStyle name="all" alignment="justify"/> </initialize> <paraStyle name="response" fontName="Helvetica-oblique" fontSize="9.5"/> <paraStyle name="page" fontName="helvetica-bold" fontSize="15.0" leftIndent="0.0" textColor="white"/> <paraStyle name="title" fontName="helvetica-bold" fontSize="18.0" leading="15" leftIndent="0.0" textColor="white"/> <paraStyle name="question" fontName="helvetica-boldoblique" fontSize="10.0" leftIndent="3.0"/> <paraStyle name="answer" fontName="helvetica" fontSize="09.0" leftIndent="0.0"/> <paraStyle name="descriptive_text" fontName="helvetica" fontSize="10.0" leftIndent="0.0"/> <paraStyle name="answer_left" alignment="LEFT" fontName="helvetica-bold" fontSize="8.0" leftIndent="0.0"/> <paraStyle name="P2" fontName="Helvetica" fontSize="14.0" leading="15" spaceBefore="6.0" spaceAfter="6.0"/> <paraStyle name="comment" fontName="Helvetica" fontSize="14.0" leading="50" spaceBefore="0.0" spaceAfter="0.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_default_9" fontName="Helvetica" fontSize="9.0" leading="11" alignment="LEFT" spaceBefore="0.0" spaceAfter="0.0"/> </stylesheet> <story>""" surv_obj = pooler.get_pool(cr.dbname).get('survey.survey') for survey in surv_obj.browse(cr,uid,ids): rml += """ if survey.lang: context['lang'] = survey.lang <blockTable colWidths='"""+_tbl_widths+"""' style="title_tbl"> <tr><td><para style="title">""" + to_xml(tools.ustr(translate(cr, 'survey,title','model',survey.lang or 'en_EN') or survey.title)) + """</para></td></tr> <tr><td><para style="title">""" + to_xml(tools.ustr(survey.title)) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" if survey.note: rml += """ <para style="P2"></para> <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 rml += """ <blockTable colWidths='"""+_tbl_widths+"""' style="page_tbl"> <tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(translate(cr, 'survey.page,title','model',survey.lang or 'en_EN',page.title) or page.title)) + """</para></td></tr> <tr><td><para style="page">"""+ tools.ustr(seq) + """. """ + to_xml(tools.ustr(page.title)) + """</para><para style="P2"><font></font></para></td></tr> </blockTable>""" if page.note: rml += """<para style="P2"></para><blockTable colWidths='"""+_tbl_widths+"""' style="note_table"> <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(translate(cr, 'survey.page,note','model',survey.lang or 'en_EN',page.note) or page.note)) + """</para></td></tr> <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 += """ <para style="P2"><font></font></para> <blockTable colWidths='"""+_tbl_widths+"""' style="question_tbl"> <tr><td><para style="question">""" + to_xml(tools.ustr(translate(cr, 'survey.question,question','model',survey.lang or 'en_EN',que.question) or que.question)) + """</para></td></tr> <tr><td><para style="question">""" + to_xml(tools.ustr(que.question)) + """</para></td></tr> </blockTable> <para style="P2"><font></font></para>""" 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 += """ <blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr><td><para style="descriptive_text">""" + to_xml(tools.ustr(translate(cr, 'survey.question,descriptive_text','model',survey.lang or 'en_EN',que.descriptive_text) or que.descriptive_text)) + """</para></td></tr> <tr> <td> <para style="descriptive_text">""" + to_xml(tools.ustr(que.descriptive_text)) + """</para> </td> </tr> </blockTable>""" elif que.type in ['multiple_choice_multiple_ans','multiple_choice_only_one_ans']: answer = [] for ans in que.answer_choice_ids: a= ' - ' + ans.answer or '' answer.append(to_xml(tools.ustr(translate(cr, 'survey.answer,answer','model',survey.lang or 'en_EN',ans.answer or '') or ans.answer or '') +a )) def divide_list(lst, n): return [lst[i::n] for i in range(n)] divide_list = divide_list(answer,_display_ans_in_rows) for lst in divide_list: if que.type == 'multiple_choice_multiple_ans': if len(lst)<>0 and len(lst)<>int(round(float(len(answer))/_display_ans_in_rows,0)): 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) 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' rml+="""<blockTable colWidths=" """ + colWidths + """ " style="ans_tbl"> <tr>""" for div in range(0,len(divide)): if divide[div] != '': if que.type == 'multiple_choice_multiple_ans': rml += """ <td> <illustration> <rect x="0.1cm" y="-0.4cm" width="0.5 cm" height="0.5cm" fill="no" stroke="yes"/> </illustration> </td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml += """ <td> <illustration> <circle x="0.3cm" y="-0.18cm" radius="0.23 cm" fill="no" stroke="yes"/> </illustration> </td> <td><para style="answer">""" + divide[div] + """</para></td>""" else: rml += """ <td></td> <td></td>""" 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)) for col in que.column_heading_ids: 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 if que.comment_column: for col in cols_widhts: if i == 0: cols_widhts[i] = cols_widhts[i]/2.0 tmp = cols_widhts[i] sum += col 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>""" for mat_col in matrix_ans: 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: style='ans_tbl_white' else: style='ans_tbl_gainsboro' 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"/>""" elif que.type in ['matrix_of_choices_only_one_ans','rating_scale']: value = """ <fill color="white"/> <circle x="0.35cm" y="-0.18cm" radius="0.25 cm" fill="yes" stroke="yes"/>""" else: 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 += """ <td><para style="answer_left">""" + to_xml(tools.ustr(que.column_name)) + """</para></td>""" else: 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']: 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: a = ' - ' + ans.answer or '' rml += """<para style="P1"></para> <blockTable colWidths=" """+ colWidths + """ " style="ans_tbl"> <tr><td><para style="answer">""" + to_xml(tools.ustr(translate(cr, 'survey.answer,answer','model',survey.lang or 'en_EN',ans.answer) or ans.answer + a)) + """</para></td> <td> <illustration> <rect x="0.0cm" y="-0.5cm" width='""" + tools.ustr(str(cols_widhts[0] - 0.3) + "cm") + """' height="0.6cm" fill="no" stroke="yes"/> </illustration> </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"> <tr> <td><para style="comment"><font color="white"> </font></para> <illustration> <rect x="0.1cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.6) +'cm') + """' height="1.5cm" fill="no" stroke="yes"/> </illustration> </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> <blockTable colWidths=" """ + colWidths + """cm " style="ans_tbl"> <tr> <td> <illustration> <rect x="0.2cm" y="0.3cm" width='""" + tools.ustr(str(float(colWidths) - 0.7) +'cm') + """' height="0.6cm" fill="no" stroke="yes"/> </illustration> </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>""" 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 for r in range(0,que.no_of_rows): if i%2 != 0: style = 'tbl_white' else: style = 'tbl_gainsboro' i += 1 rml += """<blockTable colWidths=" """ + colWidths + """ " style='"""+style+"""'><tr>""" for c in que.column_heading_ids: rml += """ <td><para style="terp_default_9"><font color="white"> </font></para></td>""" rml += """</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)
def execute_cr(self, cr, uid, data, state='init', context=None): if not context: context={} res = {} try: state_def = self.states[state] result_def = state_def.get('result', {}) actions_res = {} # iterate through the list of actions defined for this state for action in state_def.get('actions', []): # execute them action_res = action(self, cr, uid, data, context) assert isinstance(action_res, dict), 'The return value of wizard actions should be a dictionary' actions_res.update(action_res) res = copy.copy(result_def) res['datas'] = actions_res lang = context.get('lang', False) if result_def['type'] == 'action': res['action'] = result_def['action'](self, cr, uid, data, context) elif result_def['type'] == 'form': fields = copy.deepcopy(result_def['fields']) arch = copy.copy(result_def['arch']) button_list = copy.copy(result_def['state']) if isinstance(fields, UpdateableDict): fields = fields.dict if isinstance(arch, UpdateableStr): arch = arch.string # fetch user-set defaut values for the field... shouldn't we pass it the uid? ir_values_obj = pooler.get_pool(cr.dbname).get('ir.values') defaults = ir_values_obj.get(cr, uid, 'default', False, [('wizard.'+self.wiz_name, False)]) default_values = dict([(x[1], x[2]) for x in defaults]) for val in fields.keys(): if 'default' in fields[val]: # execute default method for this field if callable(fields[val]['default']): fields[val]['value'] = fields[val]['default'](uid, data, state) else: fields[val]['value'] = fields[val]['default'] del fields[val]['default'] else: # if user has set a default value for the field, use it if val in default_values: fields[val]['value'] = default_values[val] if 'selection' in fields[val]: if not isinstance(fields[val]['selection'], (tuple, list)): fields[val] = copy.copy(fields[val]) fields[val]['selection'] = fields[val]['selection'](self, cr, uid, context) elif lang: res_name = "%s,%s,%s" % (self.wiz_name, state, val) trans = lambda x: translate(cr, res_name, 'selection', lang, x) or x for idx, (key, val2) in enumerate(fields[val]['selection']): fields[val]['selection'][idx] = (key, trans(val2)) if lang: # translate fields for field in fields: res_name = "%s,%s,%s" % (self.wiz_name, state, field) trans = translate(cr, res_name, 'wizard_field', lang) if trans: fields[field]['string'] = trans if 'help' in fields[field]: t = translate(cr, res_name, 'help', lang, fields[field]['help']) if t: fields[field]['help'] = t # translate arch if not isinstance(arch, UpdateableStr): doc = etree.XML(arch) self.translate_view(cr, doc, state, lang) arch = etree.tostring(doc) # translate buttons button_list = list(button_list) for i, aa in enumerate(button_list): button_name = aa[0] trans = translate(cr, self.wiz_name+','+state+','+button_name, 'wizard_button', lang) if trans: aa = list(aa) aa[1] = trans button_list[i] = aa res['fields'] = fields res['arch'] = arch res['state'] = button_list elif result_def['type'] == 'choice': next_state = result_def['next_state'](self, cr, uid, data, context) return self.execute_cr(cr, uid, data, next_state, context) except Exception, e: if isinstance(e, except_wizard) \ or isinstance(e, except_osv) \ or isinstance(e, except_orm): self.abortResponse(2, e.name, 'warning', e.value) else: import traceback tb_s = reduce(lambda x, y: x+y, traceback.format_exception( sys.exc_type, sys.exc_value, sys.exc_traceback)) logger = Logger() logger.notifyChannel("web-services", LOG_ERROR, 'Exception in call: ' + tb_s) raise
def _(self, src): lang = self.context.get('lang', 'en_US') return translate( self.cr, _ir_translation_name, 'report', lang, src) or src
def tr(src, ttype): # We try to do the same as the _(), but without the frame # inspection, since we aready are wrapping an osv function # trans_obj = self.get('ir.translation') cannot work yet :( ctx = {} if not kwargs: if args and isinstance(args[-1], dict): ctx = args[-1] elif isinstance(kwargs, dict): if 'context' in kwargs: ctx = kwargs['context'] elif 'kwargs' in kwargs: # http entry points such as call_kw() ctx = kwargs['kwargs'].get('context') uid = 1 if args and isinstance(args[0], (long, int)): uid = args[0] lang = ctx and ctx.get('lang') if not (lang or hasattr(src, '__call__')): return src # We open a *new* cursor here, one reason is that failed SQL # queries (as in IntegrityError) will invalidate the current one. cr = False if hasattr(src, '__call__'): # callable. We need to find the right parameters to call # the orm._sql_message(self, cr, uid, ids, context) function, # or we skip.. # our signature is f(registry, dbname [,uid, obj, method, args]) try: if args and len(args) > 1: # TODO self doesn't exist, but was already wrong before (it was not a registry but just the object_service. obj = self.get(args[1]) if len(args) > 3 and isinstance( args[3], (long, int, list)): ids = args[3] else: ids = [] cr = openerp.sql_db.db_connect(dbname).cursor() return src(obj, cr, uid, ids, context=(ctx or {})) except Exception: pass finally: if cr: cr.close() return False # so that the original SQL error will # be returned, it is the best we have. try: cr = openerp.sql_db.db_connect(dbname).cursor() res = translate(cr, name=False, source_type=ttype, lang=lang, source=src) if res: return res else: return src finally: if cr: cr.close()
def _(self, src): lang = self.context.get('lang', 'en_US') return translate(self.cr, '', 'code', lang, src) or src