From 4f6ec1cd2a9253bb0c6c17d304490c7809facf8a Mon Sep 17 00:00:00 2001 From: Joren Van Onder Date: Sun, 12 Aug 2018 22:40:50 +0200 Subject: [IMP] website,*: support multiple websites This implements support to administer multiple websites. Although the core functionality already existed, managing multiple websites was fairly technical. In the interest of database updates and migration this attempts to keep duplicated data to a minimum. To do this the usual generic records are rendered unless some website-specific record exists that replaces it. Copy-on-write (COW) is used to create these website-specific records. Through this mechanism creating a website-specific record is delayed until necessary. A COW mechanism has been implemented on 4 models: ir.ui.view, website.page, website.menu and ir.attachment. These COW mechanisms are activated when editing data through the website (aka frontend). These frontend edits (e.g. with web_editor) will be website-specific, possibly creating a website-specific record when necessary. When editing data in the backend nothing special will happen, even when editing a generic record. Note that because of this mechanism also facilitates the ability to create new, uncustomized websites because the generic data is kept. Support is provided for a website to have any theme. Themes are fairly complex to handle. Standalone themes can depend on other standalone themes (e.g. theme_beauty depends on theme_loftspace) and themes usually modify some data of the themes they depend on. Because a theme can be installed on multiple websites, using website_id m2o fields does not work well. It would require duplicate data, making updates and migration harder. Because of this, data for themes (ir.ui.view and ir.attachment specifically) have a theme_id m2o. website has a theme_ids m2m that identifies all theme modules currently installed on it. Through these fields we figure out what to render. A theme is only fully uninstalled when it's no longer active on any website. The advantage of this approach is that upgrading or migrating theme data is no different from the single-website case. The website.published.mixin class was modified to handle multiple websites. A wizard was added in the backend to easily manage this for multiple website. Although not used anywhere in this commit, a 'website_id' variable has been added in the evaluation context of ir.rule. It allows to easily make any model multi-website aware, all that's needed is a custom website_id m2o field on a model and a custom record rule. --- addons/website/controllers/backend.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'addons/website/controllers/backend.py') diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index e5a2ecfa87e..9932843ff3a 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -8,7 +8,7 @@ from odoo.http import request class WebsiteBackend(http.Controller): @http.route('/website/fetch_dashboard_data', type="json", auth='user') - def fetch_dashboard_data(self, date_from, date_to): + def fetch_dashboard_data(self, website_id, date_from, date_to): has_group_system = request.env.user.has_group('base.group_system') has_group_designer = request.env.user.has_group('website.group_website_designer') dashboard_data = { @@ -21,6 +21,13 @@ class WebsiteBackend(http.Controller): 'visits': {}, } } + + current_website = request.env['website'].browse(website_id) if website_id else request.env['website'].get_current_website() + dashboard_data['websites'] = request.env['website'].search_read([], ['id', 'name']) + for website in dashboard_data['websites']: + if website['id'] == current_website.id: + website['selected'] = True + if has_group_designer: config = request.env['res.config.settings'].sudo().create({}) if config.has_google_analytics_dashboard: -- cgit v1.2.3 From ff26b20a48e17966ffc72867b7342160c2766283 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 24 Jul 2018 11:02:40 +0200 Subject: [REF] website: small diff pep, renaming, make generic function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This commit should not change the behaviour in most cases. Co-authored-by: Derie Romain Co-authored-by: Kersten Jérémy --- addons/website/controllers/backend.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'addons/website/controllers/backend.py') diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 9932843ff3a..3d75facfc30 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -9,6 +9,7 @@ class WebsiteBackend(http.Controller): @http.route('/website/fetch_dashboard_data', type="json", auth='user') def fetch_dashboard_data(self, website_id, date_from, date_to): + Website = request.env['website'] has_group_system = request.env.user.has_group('base.group_system') has_group_designer = request.env.user.has_group('website.group_website_designer') dashboard_data = { @@ -22,7 +23,7 @@ class WebsiteBackend(http.Controller): } } - current_website = request.env['website'].browse(website_id) if website_id else request.env['website'].get_current_website() + current_website = website_id and Website.browse(website_id) or Website.get_current_website() dashboard_data['websites'] = request.env['website'].search_read([], ['id', 'name']) for website in dashboard_data['websites']: if website['id'] == current_website.id: -- cgit v1.2.3 From 066cfc9598a307a48b86104f4bf861a58de09b41 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Wed, 25 Jul 2018 16:51:50 +0200 Subject: [IMP] website_[blog|event|forum|sale|slide]: make website specific MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Set up env & tools for module website multiwebsite (blog, event, sale..) website_id in modelConverter and ir_rule add _compute_domain_keys to have a different cache per website or rules would not be correctly website_dependant eg: blog 1 on website 1, blog 2 on website 2 access blog 1 from website 1 => can access -> normal access blog 1 from website 2 => can access -> should crash because (ir rule) split mixing website.published.mixin and website.published.multi.mixin to have website_id only on last one. multi mixing will: - override website_published compute to take current_website into account (not in backend) - force website when clicking on published in backend - website blog, website_sale, website_event, website_forum, website_slides are now multi website Co-authored-by: Derie Romain Co-authored-by: Kersten Jérémy --- addons/website/controllers/backend.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'addons/website/controllers/backend.py') diff --git a/addons/website/controllers/backend.py b/addons/website/controllers/backend.py index 3d75facfc30..d9ca7981612 100644 --- a/addons/website/controllers/backend.py +++ b/addons/website/controllers/backend.py @@ -31,6 +31,7 @@ class WebsiteBackend(http.Controller): if has_group_designer: config = request.env['res.config.settings'].sudo().create({}) + config.website_id = current_website if config.has_google_analytics_dashboard: dashboard_data['dashboards']['visits'] = dict( ga_client_id=config.google_management_client_id or '', # void string instead of stringified False @@ -39,7 +40,7 @@ class WebsiteBackend(http.Controller): return dashboard_data @http.route('/website/dashboard/set_ga_data', type='json', auth='user') - def website_set_ga_data(self, ga_client_id, ga_analytics_key): + def website_set_ga_data(self, website_id, ga_client_id, ga_analytics_key): if not request.env.user.has_group('base.group_system'): return { 'error': { @@ -54,10 +55,14 @@ class WebsiteBackend(http.Controller): 'message': 'The Google Analytics Client ID or Key you entered seems incorrect.', } } + Website = request.env['website'] + current_website = website_id and Website.browse(website_id) or Website.get_current_website() + request.env['res.config.settings'].create({ 'has_google_analytics': True, 'has_google_analytics_dashboard': True, 'google_management_client_id': ga_client_id, 'google_analytics_key': ga_analytics_key, + 'website_id': current_website, }).execute() return True -- cgit v1.2.3