Saving get_pdf () variable to fields.binary

I want to store the variable automatically in fields.binary (email_attachment_file) from get_pdf function.

My codes are below:

 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

      

And, is there something wrong with the functionReport.get_pdf function?

+3


source to share


1 answer


Use encodestring () instead of decodestring () .



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)

      

+2


source







All Articles