MuK IT GmbH
6 years ago
10 changed files with 139 additions and 5 deletions
-
5muk_web_utils/__manifest__.py
-
1muk_web_utils/controllers/__init__.py
-
52muk_web_utils/controllers/attachment.py
-
2muk_web_utils/controllers/backend.py
-
31muk_web_utils/data/autovacuum.xml
-
5muk_web_utils/doc/changelog.rst
-
1muk_web_utils/models/__init__.py
-
43muk_web_utils/models/ir_attachment.py
-
2muk_web_utils/static/src/js/fields/binary.js
-
2muk_web_utils/static/src/js/fields/image.js
@ -0,0 +1,52 @@ |
|||
################################################################################### |
|||
# |
|||
# 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################### |
|||
|
|||
import json |
|||
import base64 |
|||
import logging |
|||
|
|||
from odoo import http |
|||
from odoo.http import request |
|||
from odoo.tools.misc import str2bool |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
class AttachmentController(http.Controller): |
|||
|
|||
@http.route('/utils/attachment/add', type='http', auth="user", methods=['POST']) |
|||
def add_attachment(self, ufile, temporary=False, **kw): |
|||
tmp = temporary and str2bool(temporary) or False |
|||
attachment = request.env['ir.attachment'].create({ |
|||
'name': tmp and "%s (Temporary)" % name or name, |
|||
'datas': base64.b64encode(ufile.read()), |
|||
'datas_fname': ufile.filename, |
|||
'type': 'binary', |
|||
'public': False, |
|||
'temporary': tmp, |
|||
}) |
|||
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=['DELETE']) |
|||
def remove_attachment(self, id, **kw): |
|||
return json.dumps(request.env['ir.attachment'].browse(id).unlink()) |
|||
|
@ -0,0 +1,31 @@ |
|||
<?xml version="1.0" encoding="UTF-8"?> |
|||
|
|||
<!-- |
|||
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 <http://www.gnu.org/licenses/>. |
|||
--> |
|||
|
|||
<odoo noupdate="1"> |
|||
|
|||
<record id="autovacuum_temporary_attachments" model="muk_autovacuum.rules"> |
|||
<field name="name">Delete temporary Attachments</field> |
|||
<field name="model" ref="base.model_ir_attachment"/> |
|||
<field name="active" eval="True" /> |
|||
<field name="state">domain</field> |
|||
<field name="domain">[('temporary','=',True), ('create_date', '<=', (datetime.datetime.utcnow() - datetime.timedelta(hours=24)).strftime('%Y-%m-%d %H:%M:%S'))]</field> |
|||
<field name="protect_starred" eval="False" /> |
|||
</record> |
|||
|
|||
</odoo> |
@ -0,0 +1,43 @@ |
|||
################################################################################### |
|||
# |
|||
# Copyright (C) 2018 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 <http://www.gnu.org/licenses/>. |
|||
# |
|||
################################################################################### |
|||
|
|||
import base64 |
|||
import logging |
|||
import mimetypes |
|||
|
|||
from odoo import api, models, fields, _ |
|||
from odoo.exceptions import AccessError |
|||
from odoo.tools.mimetypes import guess_mimetype |
|||
|
|||
_logger = logging.getLogger(__name__) |
|||
|
|||
class IrAttachment(models.Model): |
|||
|
|||
_inherit = 'ir.attachment' |
|||
|
|||
#---------------------------------------------------------- |
|||
# Database |
|||
#---------------------------------------------------------- |
|||
|
|||
temporary = fields.Boolean( |
|||
string="Temporary", |
|||
default=False, |
|||
help="Attachments will be deleted by Autovacuum.", |
|||
) |
|||
|
Write
Preview
Loading…
Cancel
Save
Reference in new issue