Browse Source

publish muk_web_utils - 12.0

pull/115/head
MuK IT GmbH 6 years ago
parent
commit
dbfa9a6fe2
  1. 5
      muk_web_utils/__manifest__.py
  2. 1
      muk_web_utils/controllers/__init__.py
  3. 52
      muk_web_utils/controllers/attachment.py
  4. 2
      muk_web_utils/controllers/backend.py
  5. 31
      muk_web_utils/data/autovacuum.xml
  6. 5
      muk_web_utils/doc/changelog.rst
  7. 1
      muk_web_utils/models/__init__.py
  8. 43
      muk_web_utils/models/ir_attachment.py
  9. 2
      muk_web_utils/static/src/js/fields/binary.js
  10. 2
      muk_web_utils/static/src/js/fields/image.js

5
muk_web_utils/__manifest__.py

@ -20,7 +20,7 @@
{ {
"name": "MuK Web Utils", "name": "MuK Web Utils",
"summary": """Utility Features""", "summary": """Utility Features""",
"version": "12.0.2.8.23",
"version": "12.0.2.9.0",
"category": "Extra Tools", "category": "Extra Tools",
"license": "AGPL-3", "license": "AGPL-3",
"author": "MuK IT", "author": "MuK IT",
@ -31,11 +31,12 @@
], ],
"depends": [ "depends": [
"web_editor", "web_editor",
"muk_utils",
"muk_autovacuum",
], ],
"data": [ "data": [
"template/assets.xml", "template/assets.xml",
"views/res_config_settings_view.xml", "views/res_config_settings_view.xml",
"data/autovacuum.xml",
], ],
"qweb": [ "qweb": [
"static/src/xml/*.xml", "static/src/xml/*.xml",

1
muk_web_utils/controllers/__init__.py

@ -18,3 +18,4 @@
################################################################################### ###################################################################################
from . import backend from . import backend
from . import attachment

52
muk_web_utils/controllers/attachment.py

@ -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())

2
muk_web_utils/controllers/backend.py

@ -26,7 +26,7 @@ _logger = logging.getLogger(__name__)
class BackendController(http.Controller): class BackendController(http.Controller):
@http.route('/params/muk_web_utils.binary_max_size', type='json', auth="user")
@http.route('/config/muk_web_utils.binary_max_size', type='json', auth="user")
def max_upload_size(self, **kw): def max_upload_size(self, **kw):
params = request.env['ir.config_parameter'].sudo() params = request.env['ir.config_parameter'].sudo()
return { return {

31
muk_web_utils/data/autovacuum.xml

@ -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', '&lt;=', (datetime.datetime.utcnow() - datetime.timedelta(hours=24)).strftime('%Y-%m-%d %H:%M:%S'))]</field>
<field name="protect_starred" eval="False" />
</record>
</odoo>

5
muk_web_utils/doc/changelog.rst

@ -1,3 +1,8 @@
`2.9.0`
-------
- Temporary attachments
`2.8.0` `2.8.0`
------- -------

1
muk_web_utils/models/__init__.py

@ -17,5 +17,6 @@
# #
################################################################################### ###################################################################################
from . import ir_attachment
from . import res_config_settings from . import res_config_settings

43
muk_web_utils/models/ir_attachment.py

@ -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.",
)

2
muk_web_utils/static/src/js/fields/binary.js

@ -32,7 +32,7 @@ var QWeb = core.qweb;
fields.FieldBinaryFile.include({ fields.FieldBinaryFile.include({
willStart: function () { willStart: function () {
var def = this._rpc({ var def = this._rpc({
route: '/params/muk_web_utils.binary_max_size',
route: '/config/muk_web_utils.binary_max_size',
}).done(function(result) { }).done(function(result) {
this.max_upload_size = result.max_upload_size * 1024 * 1024; this.max_upload_size = result.max_upload_size * 1024 * 1024;
}.bind(this)); }.bind(this));

2
muk_web_utils/static/src/js/fields/image.js

@ -46,7 +46,7 @@ var QWeb = core.qweb;
fields.FieldBinaryImage.include({ fields.FieldBinaryImage.include({
willStart: function () { willStart: function () {
var def = this._rpc({ var def = this._rpc({
route: '/params/muk_web_utils.binary_max_size',
route: '/config/muk_web_utils.binary_max_size',
}).done(function(result) { }).done(function(result) {
this.max_upload_size = result.max_upload_size * 1024 * 1024; this.max_upload_size = result.max_upload_size * 1024 * 1024;
}.bind(this)); }.bind(this));

Loading…
Cancel
Save