From f2a3daf2178f91bdd2bacdfc73b7971a274baf5e Mon Sep 17 00:00:00 2001 From: MuK IT GmbH Date: Sun, 7 Apr 2019 20:54:08 +0000 Subject: [PATCH] publish muk_utils - 12.0 --- muk_utils/__init__.py | 1 + muk_utils/__manifest__.py | 2 +- muk_utils/controllers/__init__.py | 20 +++++++++++++ muk_utils/controllers/backend.py | 50 +++++++++++++++++++++++++++++++ 4 files changed, 72 insertions(+), 1 deletion(-) create mode 100644 muk_utils/controllers/__init__.py create mode 100644 muk_utils/controllers/backend.py diff --git a/muk_utils/__init__.py b/muk_utils/__init__.py index 5b5d62d..c1ac23e 100644 --- a/muk_utils/__init__.py +++ b/muk_utils/__init__.py @@ -17,5 +17,6 @@ # ################################################################################### +from . import controllers from . import models from . import tools \ No newline at end of file diff --git a/muk_utils/__manifest__.py b/muk_utils/__manifest__.py index 7ac5ad8..bf62846 100644 --- a/muk_utils/__manifest__.py +++ b/muk_utils/__manifest__.py @@ -19,7 +19,7 @@ { "name": "MuK Utils", "summary": """Utility Features""", - "version": '12.0.1.6.16', + "version": '12.0.1.6.17', "category": 'Extra Tools', "license": "AGPL-3", "author": "MuK IT", diff --git a/muk_utils/controllers/__init__.py b/muk_utils/controllers/__init__.py new file mode 100644 index 0000000..4631769 --- /dev/null +++ b/muk_utils/controllers/__init__.py @@ -0,0 +1,20 @@ +################################################################################### +# +# Copyright (C) 2017 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +from . import backend diff --git a/muk_utils/controllers/backend.py b/muk_utils/controllers/backend.py new file mode 100644 index 0000000..d817c4f --- /dev/null +++ b/muk_utils/controllers/backend.py @@ -0,0 +1,50 @@ +################################################################################### +# +# Copyright (C) 2017 MuK IT GmbH +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +################################################################################### + +import json +import base64 +import logging + +from odoo import http +from odoo.http import request + +_logger = logging.getLogger(__name__) + +class BackendController(http.Controller): + + @http.route('/utils/attachment/add', type='http', auth="user", methods=['POST']) + def add_attachment(self, ufile=None, **kw): + content = ufile.read() + attachment = request.env['ir.attachment'].create({ + 'name': "Access Attachment: %s" % ufile.filename, + 'datas': base64.b64encode(content), + 'datas_fname': ufile.filename, + 'type': 'binary', + 'public': False, + }) + attachment.generate_access_token() + base_url = request.env['ir.config_parameter'].sudo().get_param('web.base.url') + result = attachment.read(['name', 'datas_fname', 'mimetype', 'checksum', 'access_token'])[0] + result['url'] = '%s/web/content/%s?access_token=%s' % (base_url, attachment.id, attachment.access_token) + return json.dumps(result) + + @http.route('/utils/attachment/remove', type='http', auth="user", methods=['POST']) + def remove_attachment(self, id, **kw): + return json.dumps(request.env['ir.attachment'].browse(id).unlink()) + \ No newline at end of file