Esempio n. 1
0
 def check_export(self, filename, **kw):
     try:
         if os.path.splitext(filename)[1][1:].strip().lower() in converter.imports():
             return True
     except Exception:
         return False
     return False
         
Esempio n. 2
0
    def convert(self):
        def export(record, content, filename):
            name = "%s.%s" % (os.path.splitext(filename)[0], record.format)
            output = record.env['muk_converter.converter'].convert(
                filename, content)
            record.write({
                'state': 'download',
                'output_name': name,
                'output_binary': base64.b64encode(output)
            })
            return {
                "name": _("Convert File"),
                'type': 'ir.actions.act_window',
                'res_model': 'muk_converter.convert',
                'view_mode': 'form',
                'view_type': 'form',
                'res_id': record.id,
                'views': [(False, 'form')],
                'target': 'new',
            }

        record = self[0]
        if record.input_url:
            status, headers, content = get_response(record.input_url)
            if status != 200:
                raise ValueError("Failed to retrieve the file from the url.")
            else:
                extension = mimetypes.guess_extension(
                    headers['content-type'])[1:].strip().lower()
                if extension not in converter.imports():
                    raise ValueError("Invalid import format.")
                else:
                    return export(
                        record, content, record.input_name
                        or "%s.%s" % (uuid.uuid4(), extension))
        elif record.input_name and record.input_binary:
            return export(record, base64.b64decode(record.input_binary),
                          record.input_name)
        else:
            raise ValueError(
                "The conversion requires either a valid url or a filename and a file."
            )
Esempio n. 3
0
 def export_formats(self, **kw):
     return converter.imports()
Esempio n. 4
0
 def _compute_is_exportable(self):
     for record in self:
         record.is_exportable = record.extension and record.extension.strip(
             ".") in converter.imports()