summaryrefslogtreecommitdiff
path: root/addons/web_unsplash/models
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
committerstephanchrst <stephanchrst@gmail.com>2022-05-10 21:51:50 +0700
commit3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch)
treea44932296ef4a9b71d5f010906253d8c53727726 /addons/web_unsplash/models
parent0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff)
initial commit 2
Diffstat (limited to 'addons/web_unsplash/models')
-rw-r--r--addons/web_unsplash/models/__init__.py6
-rw-r--r--addons/web_unsplash/models/ir_qweb.py30
-rw-r--r--addons/web_unsplash/models/res_config_settings.py9
-rw-r--r--addons/web_unsplash/models/res_users.py11
4 files changed, 56 insertions, 0 deletions
diff --git a/addons/web_unsplash/models/__init__.py b/addons/web_unsplash/models/__init__.py
new file mode 100644
index 00000000..ffce8229
--- /dev/null
+++ b/addons/web_unsplash/models/__init__.py
@@ -0,0 +1,6 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+
+from . import res_config_settings
+from . import res_users
+from . import ir_qweb
diff --git a/addons/web_unsplash/models/ir_qweb.py b/addons/web_unsplash/models/ir_qweb.py
new file mode 100644
index 00000000..9b0f60a4
--- /dev/null
+++ b/addons/web_unsplash/models/ir_qweb.py
@@ -0,0 +1,30 @@
+from werkzeug import urls
+
+from odoo import models, api
+
+
+class Image(models.AbstractModel):
+ _inherit = 'ir.qweb.field.image'
+
+ @api.model
+ def from_html(self, model, field, element):
+ if element.find('.//img') is None:
+ return False
+ url = element.find('.//img').get('src')
+ url_object = urls.url_parse(url)
+
+ if url_object.path.startswith('/unsplash/'):
+ res_id = element.get('data-oe-id')
+ if res_id:
+ res_id = int(res_id)
+ res_model = model._name
+ attachment = self.env['ir.attachment'].search([
+ '&', '|', '&',
+ ('res_model', '=', res_model),
+ ('res_id', '=', res_id),
+ ('public', '=', True),
+ ('url', '=', url_object.path),
+ ], limit=1)
+ return attachment.datas
+
+ return super(Image, self).from_html(model, field, element)
diff --git a/addons/web_unsplash/models/res_config_settings.py b/addons/web_unsplash/models/res_config_settings.py
new file mode 100644
index 00000000..2eca06a5
--- /dev/null
+++ b/addons/web_unsplash/models/res_config_settings.py
@@ -0,0 +1,9 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import fields, models
+
+
+class ResConfigSettings(models.TransientModel):
+ _inherit = 'res.config.settings'
+
+ unsplash_access_key = fields.Char("Access Key", config_parameter='unsplash.access_key')
diff --git a/addons/web_unsplash/models/res_users.py b/addons/web_unsplash/models/res_users.py
new file mode 100644
index 00000000..375a0ce3
--- /dev/null
+++ b/addons/web_unsplash/models/res_users.py
@@ -0,0 +1,11 @@
+# -*- coding: utf-8 -*-
+# Part of Odoo. See LICENSE file for full copyright and licensing details.
+from odoo import api, models
+
+
+class ResUsers(models.Model):
+ _inherit = 'res.users'
+
+ def _has_unsplash_key_rights(self):
+ self.ensure_one()
+ return self.has_group('base.group_erp_manager')