[REF] web_editor, website: split customize_template_get
Commita2ae219d4efixed the customize_template_get function(s) which had been modified for the 10.0 web_studio release. While the fix also reorganized the structure to make it more efficient and understandable, it promised that the function would be refactored in master. This is what this commit does. The customize_template_get route of the website module was also removed with commit5a030db3ebas it was an useless duplicate of the web_editor customize_template_get route. The old route handled two totally different features of odoo: getting all the page-related views to allow their edition with the HTML editor and getting the "toggable views" which appear in the "Customize" website menu. The parameter "full" allowed to determine which one the route was supposed to do and was useless until website was installed to add its feature (by extending the route behavior). In both cases, views informations are returned, only the number of views differs. The above-mentionned fix already did part of the refactoring by returning the same info structure for each view in both cases. Now, the function has been split. The web_editor customize_template_get route is renamed as get_assets_editor_resources and returns the info the HTML editor needs to work (the "assets" term is in prevision of the new LESS editor). A new website route "get_switchable_related_views" has been created to return the info the "Customize" website menu needs. Both use the renamed ir.ui.view function "get_related_views" (old ir.ui.view customize_template_get function) which now returns a recordset and not a list of dictionnaries.
This commit is contained in:
@@ -223,10 +223,11 @@ class Web_Editor(http.Controller):
|
||||
attachments_to_remove.unlink()
|
||||
return removal_blocked_by
|
||||
|
||||
@http.route('/web_editor/customize_template_get', type='json', auth='user', website=True)
|
||||
def customize_template_get(self, key, full=False, bundles=False):
|
||||
@http.route('/web_editor/get_assets_editor_resources', type='json', auth='user', website=True)
|
||||
def get_assets_editor_resources(self, key, bundles=False):
|
||||
""" Get inherit view's informations of the template ``key``.
|
||||
returns templates info (which can be active or not)
|
||||
``bundles=True`` returns also the asset bundles
|
||||
"""
|
||||
return request.env["ir.ui.view"].customize_template_get(key, full=full, bundles=bundles)
|
||||
views = request.env["ir.ui.view"].get_related_views(key, bundles=bundles)
|
||||
return views.read(['name', 'id', 'key', 'xml_id', 'arch', 'active', 'inherit_id'])
|
||||
|
||||
@@ -175,21 +175,11 @@ class IrUiView(models.Model):
|
||||
return views_to_return
|
||||
|
||||
@api.model
|
||||
def _customize_template_get_views(self, key, full=False, bundles=False):
|
||||
""" Get inherit views of the template ``key``.
|
||||
returns views (which can be active or not)
|
||||
``bundles=True`` returns also the asset bundles
|
||||
"""
|
||||
user_groups = set(self.env.user.groups_id)
|
||||
views = self.with_context(active_test=False)._views_get(key, bundles=bundles)
|
||||
views = views.filtered(lambda v: user_groups.issuperset(v.groups_id))
|
||||
return views
|
||||
|
||||
@api.model
|
||||
def customize_template_get(self, key, full=False, bundles=False):
|
||||
def get_related_views(self, key, bundles=False):
|
||||
""" Get inherit view's informations of the template ``key``.
|
||||
returns templates info (which can be active or not)
|
||||
``bundles=True`` returns also the asset bundles
|
||||
"""
|
||||
views = self._customize_template_get_views(key, full=full, bundles=bundles)
|
||||
return views.read(['name', 'id', 'key', 'xml_id', 'arch', 'active', 'inherit_id'])
|
||||
user_groups = set(self.env.user.groups_id)
|
||||
views = self.with_context(active_test=False)._views_get(key, bundles=bundles)
|
||||
return views.filtered(lambda v: user_groups.issuperset(v.groups_id))
|
||||
|
||||
@@ -186,9 +186,8 @@ var ViewEditor = Widget.extend({
|
||||
* @return a deferred which is resolved once everything is loaded and processed.
|
||||
*/
|
||||
loadResources: function () {
|
||||
return ajax.jsonRpc('/web_editor/customize_template_get', 'call', {
|
||||
return ajax.jsonRpc("/web_editor/get_assets_editor_resources", "call", {
|
||||
key: this.viewKey,
|
||||
full: true,
|
||||
bundles: this.options.includeBundles
|
||||
}).then((function (views) {
|
||||
// Only keep the active views and index them by ID.
|
||||
|
||||
@@ -244,6 +244,11 @@ class Website(Home):
|
||||
def snippets(self):
|
||||
return request.env['ir.ui.view'].render_template('website.snippets')
|
||||
|
||||
@http.route("/website/get_switchable_related_views", type="json", auth="user", website=True)
|
||||
def get_switchable_related_views(self, key):
|
||||
views = request.env["ir.ui.view"].get_related_views(key, bundles=False).filtered(lambda v: v.customize_show)
|
||||
return views.read(['name', 'id', 'key', 'xml_id', 'arch', 'active', 'inherit_id'])
|
||||
|
||||
@http.route('/website/reset_templates', type='http', auth='user', methods=['POST'], website=True)
|
||||
def reset_template(self, templates, redirect='/'):
|
||||
templates = request.httprequest.form.getlist('templates')
|
||||
|
||||
@@ -134,15 +134,3 @@ class View(models.Model):
|
||||
menu_data=self.env['ir.ui.menu'].load_menus_root() if request.website.is_user() else None,
|
||||
)
|
||||
return qcontext
|
||||
|
||||
@api.model
|
||||
def _customize_template_get_views(self, key, full=False, bundles=False):
|
||||
""" Get inherit view's informations of the template ``key``.
|
||||
returns views (which can be active or not)
|
||||
``full=False`` returns only the customize_show template
|
||||
``bundles=True`` returns also the asset bundles
|
||||
"""
|
||||
views = super(View, self)._customize_template_get_views(key, full=full, bundles=bundles)
|
||||
if full:
|
||||
return views
|
||||
return views.filtered(lambda v: v.customize_show)
|
||||
|
||||
@@ -70,9 +70,8 @@ website.TopBarCustomize = Widget.extend({
|
||||
},
|
||||
load_menu: function () {
|
||||
var $menu = this.$el.children("ul");
|
||||
ajax.jsonRpc('/web_editor/customize_template_get', 'call', {
|
||||
ajax.jsonRpc('/website/get_switchable_related_views', 'call', {
|
||||
key: this.view_name,
|
||||
full: false
|
||||
}).then(function (result) {
|
||||
var current_group = "";
|
||||
_.each(result, function (item) {
|
||||
|
||||
Reference in New Issue
Block a user