summaryrefslogtreecommitdiff
path: root/addons/website_theme_install/models
diff options
context:
space:
mode:
authorChristophe Simonis <chs@odoo.com>2016-01-05 15:51:49 +0100
committerChristophe Simonis <chs@odoo.com>2016-01-05 15:51:49 +0100
commit31ce19bd7c8ff90aa3a3f34ba13dfbbe00865b3b (patch)
tree4f24c985d7f4f7d08af1830f8199b120f35018f7 /addons/website_theme_install/models
parent9b5311e0c94ea2b3ad6c36bc9a4ea63228779b66 (diff)
parent97e87a42cdfaed04a6f50d928d86ac6e3bec9f91 (diff)
[MERGE] forward port of branch 9.0 up to 97e87a4
Diffstat (limited to 'addons/website_theme_install/models')
-rw-r--r--addons/website_theme_install/models/__init__.py1
-rw-r--r--addons/website_theme_install/models/ir_module_module.py50
2 files changed, 51 insertions, 0 deletions
diff --git a/addons/website_theme_install/models/__init__.py b/addons/website_theme_install/models/__init__.py
new file mode 100644
index 00000000000..7b3c2ef6a78
--- /dev/null
+++ b/addons/website_theme_install/models/__init__.py
@@ -0,0 +1 @@
+import ir_module_module \ No newline at end of file
diff --git a/addons/website_theme_install/models/ir_module_module.py b/addons/website_theme_install/models/ir_module_module.py
new file mode 100644
index 00000000000..93c62acee0f
--- /dev/null
+++ b/addons/website_theme_install/models/ir_module_module.py
@@ -0,0 +1,50 @@
+import os
+from openerp import api, fields, models, _
+
+class IrModuleModule(models.Model):
+ _name = "ir.module.module"
+ _inherit = _name
+
+ image_ids = fields.One2many('ir.attachment', 'res_id',
+ domain=[('res_model', '=', _name), ('mimetype', '=like', 'image/%')],
+ string='Screenshots', readonly=True)
+
+ @api.model
+ def update_list(self, context=None):
+ res = super(IrModuleModule, self).update_list(context=context)
+
+ IrAttachment = self.env['ir.attachment']
+ existing_urls = IrAttachment.search_read([['res_model', '=', self._name], ['type', '=', 'url']], ['url'])
+ existing_urls = [url_wrapped['url'] for url_wrapped in existing_urls]
+
+ for app in self.search([]):
+ terp = self.get_module_info(app.name)
+ images = terp.get('images', [])
+ for image in images:
+ image_path = os.path.join(app.name, image)
+ if image_path not in existing_urls:
+ image_name = os.path.basename(image_path)
+ IrAttachment.create({
+ 'type': 'url',
+ 'name': image_name,
+ 'datas_fname': image_name,
+ 'url': image_path,
+ 'res_model': self._name,
+ 'res_id': app.id,
+ })
+
+ return res
+
+ @api.multi
+ def button_choose_theme(self, context):
+ self.search([ # Uninstall the theme(s) which is (are) installed
+ ('state', '=', 'installed'),
+ '|', ('category_id', '!=', 'Hidden'), ('name', '=', 'theme_default'),
+ '|', ('category_id', '=', 'Theme'), ('category_id.parent_id', '=', 'Theme')
+ ]).button_immediate_uninstall(context=context)
+
+ next_action = self.button_immediate_install(context=context) # Then install the new chosen one
+ if next_action.get('tag') == 'reload' and not next_action.get('params', {}).get('menu_id'):
+ next_action = self.env.ref('website.action_website_tutorial').read()[0]
+
+ return next_action