2017-07-21 7 views
3

変数をget_pdf関数から自動的にfields.binary(email_attachment_file)に保存したいとします。ここでは、以下の変数get_pdf()をfields.binaryに保存する

マイコード:

class example_example(models.Model): 
    email_attachment_file = fields.Binary('Data (.txt,.pdf)') 
    email_filename   = fields.Char('Filename') 

    def generate(self,etc..): 
     report_name = "report_name_template" 

     datas = { 
      'ids':[], 
      'model' : etc, 
      'form' : etc 
      'context': context 
      } 

     moddelReport = self.pool.get('report') 
     alpha = modelReport.get_pdf(cr, uid,[],report_name,None,datas,context=context) 

     #alpha = base64.decodestring(alpha) 
     #alpha = alpha.decode('unicode_escape').encode('utf-8') 

     # --------- how to save alpha variable into fields.binary 

そして、何かが間違っmodelReport.get_pdf機能がありますか?

答えて

2

decodestring()の代わりにencodestring()を使用してください。

report_obj = self.pool.get('report') 
data = modelReport.get_pdf(cr, uid,[],report_name,None,datas,context=context) 
self.email_attachment_file = base64.encodestring(data) 
+0

データからのリターンは%PDF-1.3である 1 0 OBJ << /キッズ[] /タイプ/ページ /カウント0 >> endobj 2 0 OBJ << /プロデューサー(PythonのPDFライブラリ\ 055 http \ 072 \ 057 \ 05pypybrary \ 056net \ 057pyPdf \ 057)..など..、私は解答を見つけるためにそれを理解することができません –

+0

get_pdfは、 base64.encodestring(data)を使用してバイナリで変換する必要があります。 –

関連する問題