[ADD] website_theme_install (+ base: remove comment)
New module to propose theme installation on website installation.
This commit is contained in:
@@ -0,0 +1 @@
|
||||
import models
|
||||
@@ -0,0 +1,13 @@
|
||||
{
|
||||
'name': 'Website Theme Install',
|
||||
'description': "Propose to install a theme on website installation",
|
||||
'category': 'Website',
|
||||
'version': '1.0',
|
||||
'author': 'Odoo S.A.',
|
||||
'data': [
|
||||
'views/assets.xml',
|
||||
'views/views.xml',
|
||||
],
|
||||
'depends': ['website'],
|
||||
'auto_install': True,
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
import ir_module_module
|
||||
@@ -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
|
||||
@@ -0,0 +1,43 @@
|
||||
.o_kanban_view.o_theme_kanban {
|
||||
&.o_kanban_ungrouped {
|
||||
.o-justify-content(center);
|
||||
|
||||
.o_kanban_record {
|
||||
.o-flex(0, 0, auto);
|
||||
width: 100%;
|
||||
@media (min-width: @screen-sm-min) {
|
||||
width: 45%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.o_kanban_record {
|
||||
padding: 0;
|
||||
|
||||
position: relative;
|
||||
overflow: hidden;
|
||||
.o_button_area {
|
||||
.o-position-absolute(@bottom: -100px, @right: 0);
|
||||
.o-transition(bottom, 400ms, ease);
|
||||
width: 100%;
|
||||
padding: @odoo-horizontal-padding/2;
|
||||
background-color: fade(@odoo-brand-secondary, 70%);
|
||||
text-align: right;
|
||||
}
|
||||
&:hover .o_button_area {
|
||||
bottom: 0;
|
||||
}
|
||||
|
||||
> div {
|
||||
width: 100%;
|
||||
padding-bottom: 50%;
|
||||
background-repeat: no-repeat;
|
||||
background-position: center center;
|
||||
.o-background-size(auto 90%);
|
||||
|
||||
&.o_screenshot {
|
||||
.o-background-size(cover);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<template id="website_theme_install_assets" inherit_id="web.assets_backend" name="Website Theme Install Assets">
|
||||
<xpath expr="//link[last()]" position="after">
|
||||
<link href="/website_theme_install/static/src/less/website_theme_install.less" rel="stylesheet" type="text/less"/>
|
||||
</xpath>
|
||||
</template>
|
||||
</odoo>
|
||||
@@ -0,0 +1,71 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
<!-- Custom module kanban : install button (even if already installed) which redirects to website after (fake or not) installation + live preview button -->
|
||||
<record model="ir.ui.view" id="theme_view_kanban">
|
||||
<field name="name">Themes Kanban</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
<field name="arch" type="xml">
|
||||
<kanban create="false" class="o_theme_kanban" default_order="sequence,name">
|
||||
<field name="icon"/>
|
||||
<field name="name"/>
|
||||
<field name="state"/>
|
||||
<field name="url"/>
|
||||
<field name="image_ids"/>
|
||||
<templates>
|
||||
<div t-name="kanban-box">
|
||||
<t t-set="has_screenshot" t-value="record.image_ids.raw_value.length > 0"/>
|
||||
<div t-if="has_screenshot" class="o_screenshot" t-attf-style="background-image: url(web/image/#{record.image_ids.raw_value[0]});"/>
|
||||
<div t-if="!has_screenshot" t-attf-style="background-image: url(#{record.icon.value});"/>
|
||||
<div class="o_button_area">
|
||||
<button type="object" name="button_choose_theme" states="uninstalled" class="btn btn-primary btn-sm">Install</button>
|
||||
<button type="action" name="website.action_website_tutorial" states="installed" class="btn btn-primary btn-sm">Install</button>
|
||||
<a t-if="record.url.value" class="btn btn-sm btn-primary" t-att-href="record.url.value" target="_blank">Live Preview</a>
|
||||
</div>
|
||||
</div>
|
||||
</templates>
|
||||
</kanban>
|
||||
</field>
|
||||
</record>
|
||||
<record model="ir.ui.view" id="theme_view_search">
|
||||
<field name="name">Themes Search</field>
|
||||
<field name="model">ir.module.module</field>
|
||||
<field name="arch" type="xml">
|
||||
<search>
|
||||
<field name="name" filter_domain="['|', '|', ('summary', 'ilike', self), ('shortdesc', 'ilike', self), ('name', 'ilike', self)]" string="Theme"/>
|
||||
<group>
|
||||
<filter string="Author" domain="[]" context="{'group_by':'author'}"/>
|
||||
<filter string="Category" domain="[]" context="{'group_by':'category_id'}"/>
|
||||
</group>
|
||||
</search>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Actions to list themes with custom kanban (launched on module installation) -->
|
||||
<record id="theme_install_kanban_action" model="ir.actions.act_window">
|
||||
<field name="name">Choose Your Theme</field>
|
||||
<field name="res_model">ir.module.module</field>
|
||||
<field name="view_mode">kanban</field>
|
||||
<field name="view_id" ref="theme_view_kanban"/>
|
||||
<field name="search_view_id" ref="theme_view_search"/>
|
||||
<field name="domain">[
|
||||
'|', ('category_id', '!=', 'Hidden'), ('name', '=', 'theme_default'),
|
||||
'|', ('category_id', '=', 'Theme'), ('category_id.parent_id', '=', 'Theme')
|
||||
]</field>
|
||||
</record>
|
||||
<record id="theme_install_todo_action" model="ir.actions.server">
|
||||
<field name="name">Choose Your Theme Todo Action</field>
|
||||
<field name="model_id" ref="model_ir_module_module"/>
|
||||
<field name="code">
|
||||
self.update_list(cr, uid, context=context)
|
||||
action = {
|
||||
'type': 'ir.actions.act_url',
|
||||
'url': '/web?reload#action=website_theme_install.theme_install_kanban_action', # the ?reload option is there to fool the webclient into thinking it is a different location and so to force a reload
|
||||
'target': 'self',
|
||||
}
|
||||
</field>
|
||||
</record>
|
||||
<record id="theme_install_todo" model="ir.actions.todo">
|
||||
<field name="action_id" ref="theme_install_todo_action"/>
|
||||
<field name="type">automatic</field>
|
||||
</record>
|
||||
</odoo>
|
||||
@@ -545,7 +545,6 @@ class module(osv.osv):
|
||||
'params': {'menu_id': menu_ids and menu_ids[0] or False}
|
||||
}
|
||||
|
||||
#TODO remove me in master, not called anymore
|
||||
def button_immediate_uninstall(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
Uninstall the selected module(s) immediately and fully,
|
||||
|
||||
Reference in New Issue
Block a user