Example #1
0
 def content(self):
     if self.env.context.get('bin_size'):
         file_path = self._build_path()
         return human_size(self._read_size(file_path))
     else:
         file_path = self._build_path()
         return self._read_file(file_path)
Example #2
0
    def _compute_datas(self):
        if self._context.get('bin_size'):
            for attach in self:
                attach.datas = human_size(attach.file_size)
            return

        for attach in self:
            attach.datas = base64.b64encode(attach.raw or b'')
Example #3
0
 def _file_read(self, fname, bin_size=False):
     full_path = self._full_path(fname)
     r = ''
     try:
         if bin_size:
             r = human_size(os.path.getsize(full_path))
         else:
             r = base64.b64encode(open(full_path,'rb').read())
     except (IOError, OSError):
         _logger.info("_read_file reading %s", full_path, exc_info=True)
     return r
Example #4
0
 def convert_to_record(self, value, record):
     if value:
         lobject = record.env.cr._cnx.lobject(value, 'rb')
         if record._context.get('human_size'):
             return human_size(lobject.seek(0, 2))
         elif record._context.get('bin_size'):
             return lobject.seek(0, 2)
         elif record._context.get('oid'):
             return lobject.oid
         elif record._context.get('stream'):
             file = tempfile.TemporaryFile()
             while True:
                 chunk = lobject.read(4096)
                 if not chunk:
                     file.seek(0)
                     return file
                 file.write(chunk)
         else:
             return lobject.read()
     return False
Example #5
0
 def get_human_size(self):
     return human_size(self.size)