Browse Source

publish muk_converter - 11.0

pull/25/head
MuK IT GmbH 6 years ago
parent
commit
6045d6092c
  1. 3
      muk_converter/__manifest__.py
  2. 3
      muk_converter/views/convert.xml
  3. 25
      muk_converter/wizards/convert.py

3
muk_converter/__manifest__.py

@ -20,7 +20,7 @@
{
"name": "MuK Converter",
"summary": """Universal Converter""",
"version": '11.0.1.2.3',
"version": '11.0.1.2.4',
"category": 'Extra Tools',
"license": "AGPL-3",
"website": "https://www.mukit.at",
@ -28,6 +28,7 @@
"author": "MuK IT",
"contributors": [
"Mathias Markl <mathias.markl@mukit.at>",
"Kerrim Abd El-Hamed <kerrim.abdelhamed@mukit.at>",
],
"depends": [
"iap",

3
muk_converter/views/convert.xml

@ -28,7 +28,8 @@
<field invisible="1" name="state" />
<group>
<field name="input_name" invisible="1" />
<field name="input_binary" filename="input_name" />
<field name="input_url" attrs="{'invisible':[('input_url','=',False)]}" readonly="1" />
<field name="input_binary" filename="input_name" attrs="{'invisible':[('input_url','!=',False)]}" />
</group>
<group>
<field name="format" />

25
muk_converter/wizards/convert.py

@ -24,9 +24,9 @@ import logging
import mimetypes
from odoo import _, api, fields, models
from odoo.exceptions import UserError
# from odoo.addons.muk_utils.tools.http import get_response TODO
#from odoo.addons.muk_converter.tools import converter
from odoo.addons.muk_utils.tools.http import get_response
_logger = logging.getLogger(__name__)
@ -58,9 +58,11 @@ class ConverterWizard(models.TransientModel):
string="Filename",
states={'export': [('required', True)]})
input_url = fields.Char(
string="URL")
input_binary = fields.Binary(
string="File",
states={'export': [('required', True)]})
string="File")
format = fields.Selection(
selection=_format_selection,
@ -85,8 +87,21 @@ class ConverterWizard(models.TransientModel):
@api.multi
def convert(self):
self.ensure_one()
if not self.input_url and not self.input_binary:
raise UserError(_("Please choose a file to convert."))
if self.input_url:
status, headers, content = get_response(self.input_url)
if status != 200:
raise ValueError(_("Failed to retrieve the file from the url."))
else:
content = base64.b64encode(content)
else:
content = self.input_binary
name = "%s.%s" % (os.path.splitext(self.input_name)[0], self.format)
output = self.env['muk_converter.converter'].convert(self.input_name, self.input_binary)
output = self.env['muk_converter.converter'].convert(self.input_name, content, format=self.format)
self.write({
'state': 'download',
'output_name': name,

Loading…
Cancel
Save