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/main.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'addons/website/controllers/main.py') diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 5689b37352c..5287d480d71 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -81,6 +81,11 @@ class Website(Home): raise request.not_found() + @http.route('/website/set_session_website', type='json', auth="user") + def set_session_website(self, website_id): + request.env['website'].browse(int(website_id) if website_id else False)._fix_to_session() + return True + #------------------------------------------------------ # Login - overwrite of the web login so that regular users are redirected to the backend # while portal users are redirected to the frontend by default @@ -221,7 +226,7 @@ class Website(Home): # default sortby order sort_order = searchbar_sortings.get(sortby, 'name')['order'] - domain = ['|', ('website_ids', 'in', request.website.id), ('website_ids', '=', False)] + domain = ['|', ('website_id', '=', False), ('website_id', '=', request.website.id)] if search: domain += ['|', ('name', 'ilike', search), ('url', 'ilike', search)] @@ -236,6 +241,9 @@ class Website(Home): ) pages = Page.search(domain, order=sort_order, limit=50, offset=pager['offset']) + # only include pages if they are the most specific one available + pages = pages.filtered(pages._is_most_specific_page) + values = { 'pager': pager, 'pages': pages, -- 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/main.py | 41 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'addons/website/controllers/main.py') diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 5287d480d71..3ee178d1de5 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -18,7 +18,7 @@ from odoo import http, models, fields, _ from odoo.http import request from odoo.tools import pycompat, OrderedSet from odoo.addons.http_routing.models.ir_http import slug, _guess_mimetype -from odoo.addons.web.controllers.main import WebClient, Binary +from odoo.addons.web.controllers.main import Binary from odoo.addons.portal.controllers.portal import pager as portal_pager from odoo.addons.portal.controllers.web import Home @@ -81,15 +81,15 @@ class Website(Home): raise request.not_found() - @http.route('/website/set_session_website', type='json', auth="user") - def set_session_website(self, website_id): - request.env['website'].browse(int(website_id) if website_id else False)._fix_to_session() + @http.route('/website/force_website', type='json', auth="user") + def force_website(self, website_id): + request.env['website']._force_website(website_id) return True - #------------------------------------------------------ + # ------------------------------------------------------ # Login - overwrite of the web login so that regular users are redirected to the backend # while portal users are redirected to the frontend by default - #------------------------------------------------------ + # ------------------------------------------------------ @http.route(website=True, auth="public") def web_login(self, redirect=None, *args, **kw): @@ -102,9 +102,9 @@ class Website(Home): return http.redirect_with_hash(redirect) return response - #------------------------------------------------------ + # ------------------------------------------------------ # Business - #------------------------------------------------------ + # ------------------------------------------------------ @http.route('/website/lang/', type='http', auth="public", website=True, multilang=False) def change_lang(self, lang, r='/', **kwargs): @@ -140,7 +140,7 @@ class Website(Home): 'name': url, 'url': url, }) - dom = [('url', '=' , '/sitemap-%d.xml' % current_website.id), ('type', '=', 'binary')] + dom = [('url', '=', '/sitemap-%d.xml' % current_website.id), ('type', '=', 'binary')] sitemap = Attachment.search(dom, limit=1) if sitemap: # Check if stored version is still valid @@ -208,9 +208,9 @@ class Website(Home): } return request.render('website.website_info', values) - #------------------------------------------------------ + # ------------------------------------------------------ # Edit - #------------------------------------------------------ + # ------------------------------------------------------ @http.route(['/website/pages', '/website/pages/page/'], type='http', auth="user", website=True) def pages_management(self, page=1, sortby='name', search='', **kw): @@ -226,7 +226,7 @@ class Website(Home): # default sortby order sort_order = searchbar_sortings.get(sortby, 'name')['order'] - domain = ['|', ('website_id', '=', False), ('website_id', '=', request.website.id)] + domain = request.website.website_domain() if search: domain += ['|', ('name', 'ilike', search), ('url', 'ilike', search)] @@ -251,13 +251,12 @@ class Website(Home): 'sortby': sortby, 'searchbar_sortings': searchbar_sortings, } - return request.render("website.edit_website_pages", values) + return request.render("website.list_website_pages", values) @http.route(['/website/add/', '/website/add/'], type='http', auth="user", website=True) def pagenew(self, path="", noredirect=False, add_menu=False, template=False): # for supported mimetype, get correct default template _, ext = os.path.splitext(path) - View = request.env['ir.ui.view'] ext_special_case = ext and ext in _guess_mimetype() and ext != '.html' if not template and ext_special_case: @@ -271,7 +270,7 @@ class Website(Home): if noredirect: return werkzeug.wrappers.Response(url, mimetype='text/plain') - if ext_special_case: # redirect non html pages to backend to edit + if ext_special_case: # redirect non html pages to backend to edit return werkzeug.utils.redirect('/web#id=' + str(page.get('view_id')) + '&view_type=form&model=ir.ui.view') return werkzeug.utils.redirect(url + "?enable_editor=1") @@ -329,9 +328,9 @@ class Website(Home): xmlroot = ET.fromstring(response) return json.dumps([sugg[0].attrib['data'] for sugg in xmlroot if len(sugg) and sugg[0].attrib['data']]) - #------------------------------------------------------ + # ------------------------------------------------------ # Themes - #------------------------------------------------------ + # ------------------------------------------------------ def get_view_ids(self, xml_ids): ids = [] @@ -394,9 +393,9 @@ class Website(Home): res[id_or_xml_id] = View.render_template(id_or_xml_id, values) return res - #------------------------------------------------------ + # ------------------------------------------------------ # Server actions - #------------------------------------------------------ + # ------------------------------------------------------ @http.route([ '/website/action/', @@ -430,9 +429,9 @@ class Website(Home): return request.redirect('/') -#------------------------------------------------------ +# ------------------------------------------------------ # Retrocompatibility routes -#------------------------------------------------------ +# ------------------------------------------------------ class WebsiteBinary(http.Controller): @http.route([ -- cgit v1.2.3 From a45bb90fac04e454e9792dfea82772227e963e17 Mon Sep 17 00:00:00 2001 From: Jeremy Kersten Date: Tue, 24 Jul 2018 17:01:28 +0200 Subject: [IMP] website: improve pagemanager to be multi website compliant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Now we can see which specific page override wich page when page are sorted by url. Co-authored-by: Derie Romain Co-authored-by: Kersten Jérémy --- addons/website/controllers/main.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) (limited to 'addons/website/controllers/main.py') diff --git a/addons/website/controllers/main.py b/addons/website/controllers/main.py index 3ee178d1de5..f9c7d700e15 100644 --- a/addons/website/controllers/main.py +++ b/addons/website/controllers/main.py @@ -224,25 +224,27 @@ class Website(Home): 'name': {'label': _('Sort by Name'), 'order': 'name'}, } # default sortby order - sort_order = searchbar_sortings.get(sortby, 'name')['order'] + sort_order = searchbar_sortings.get(sortby, 'name')['order'] + ', website_id desc' domain = request.website.website_domain() if search: domain += ['|', ('name', 'ilike', search), ('url', 'ilike', search)] - pages_count = Page.search_count(domain) + pages = Page.search(domain, order=sort_order) + if sortby != 'url': + pages = pages.filtered(pages._is_most_specific_page) + pages_count = len(pages) + step = 50 pager = portal_pager( url="/website/pages", url_args={'sortby': sortby}, total=pages_count, page=page, - step=50 + step=step ) - pages = Page.search(domain, order=sort_order, limit=50, offset=pager['offset']) - # only include pages if they are the most specific one available - pages = pages.filtered(pages._is_most_specific_page) + pages = pages[(page - 1) * step:page * step] values = { 'pager': pager, -- cgit v1.2.3