[FIX] web_editor, website: fix customize_template_get

Commit e11f23b701 split the website
customize_template_get into web_editor and website ones. This split
was not perfect and commit 20861b482a
tried to make it work... but did not made it totally and added an
indirect dependency to website module in web_editor...

As the final result is wrong and inconsistent and that the previous
9.0 implementation was already ugly, this was not possible to make
a consistent full-stable fix.

This commit tries to make a fix as stable as possible (the main method
name did not change, the arguments did not change, their purpose is
the same, ...) which makes the code work and be less ugly. However,
the function returns are now slightly different (and JS depends on it).
It returns only valid view information (not header stuff which is not
related to anything and the inherit_id value is now a combination of
the inherit view id and name). Also, a new private method has been
created.

Also, the method contained code which was deprecated since saas-6 but
was never removed (and never broke anything "by chance").

In master these methods will be refactored to make more sense.
This commit is contained in:
qsm-odoo
2016-10-14 13:16:49 +02:00
parent 7a7723eacf
commit a2ae219d4e
6 changed files with 38 additions and 70 deletions
+1 -1
View File
@@ -226,7 +226,7 @@ class Web_Editor(http.Controller):
@http.route('/web_editor/customize_template_get', type='json', auth='user', website=True)
def customize_template_get(self, key, full=False, bundles=False):
""" Get inherit view's informations of the template ``key``.
returns templates (which can be active or not)
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)
+14 -35
View File
@@ -175,42 +175,21 @@ class IrUiView(models.Model):
return views_to_return
@api.model
def customize_template_get(self, key, full=False, bundles=False):
""" Get inherit view's informations of the template ``key``.
returns templates (which can be active or not)
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 = self.env.user
user_groups = set(user.groups_id)
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
view_theme_id = self.env['ir.model.data'].xmlid_to_res_id('website.theme')
done = set()
result = []
for view in views:
if full or (view.customize_show and view.inherit_id.id != view_theme_id):
if not user_groups.issuperset(view.groups_id):
continue
if view.inherit_id not in done:
result.append({
'name': view.inherit_id.name,
'id': view.id,
'key': view.key,
'xml_id': view.xml_id,
'arch': view.arch,
'inherit_id': view.inherit_id.id,
'header': True,
'active': False
})
done.add(view.inherit_id)
result.append({
'name': view.name,
'id': view.id,
'key': view.key,
'xml_id': view.xml_id,
'arch': view.arch,
'inherit_id': view.inherit_id.id,
'header': False,
'active': view.active,
})
return result
@api.model
def customize_template_get(self, key, full=False, 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'])
+1 -1
View File
@@ -149,7 +149,7 @@ var ViewEditor = Widget.extend({
view.children = [];
});
_.each(index, function (view) {
var parentId = view.inherit_id;
var parentId = view.inherit_id[0];
if (parentId && index[parentId]) {
index[parentId].children.push(view);
} else {
+4 -4
View File
@@ -262,10 +262,10 @@ class Website(Home):
@http.route('/website/customize_template_get', type='json', auth='user', website=True)
def customize_template_get(self, key, full=False, bundles=False):
""" Get inherit view's informations of the template ``key``. By default, only
:returns ``customize_show`` templates (which can be active or not), if
``full=True`` returns inherit view's informations of the template ``key``.
``bundles=True`` returns also the asset bundles
""" Get inherit view's informations of the template ``key``.
returns templates info (which can be active or not)
``full=False`` returns only the customize_show template
``bundles=True`` returns also the asset bundles
"""
return request.env["ir.ui.view"].customize_template_get(key, full=full, bundles=bundles)
+9 -21
View File
@@ -136,25 +136,13 @@ class View(models.Model):
return qcontext
@api.model
def customize_template_get(self, key, full=False, bundles=False):
""" Get inherit view's informations of the template ``key``. By default, only
:returns ``customize_show`` templates (which can be active or not), if
``full=True`` returns inherit view's informations of the template ``key``.
``bundles=True`` returns also the asset bundles
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
"""
result = super(View, self).customize_template_get(key, full=full, bundles=bundles)
imd = self.env['ir.model.data']
view_theme_id = imd.xmlid_to_res_id('website.theme')
result_filtered = []
for x in result:
if not full:
view = self.browse(x['id'])
if not view.customize_show:
continue
if view_theme_id and x['inherit_id'] == view_theme_id:
continue
result_filtered.append(x)
return result_filtered
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)
@@ -74,16 +74,17 @@ website.TopBarCustomize = Widget.extend({
key: this.view_name,
full: false
}).then(function (result) {
var current_group = "";
_.each(result, function (item) {
if (item.header) {
$menu.append('<li class="dropdown-header">' + item.name + '</li>');
} else {
var $li = $('<li/>', {role: 'presentation'})
.append($('<a/>', {href: '#', 'data-view-id': item.id, role: 'menuitem'})
.append(qweb.render('web_editor.components.switch', {id: 'switch-' + item.id, label: item.name})));
$li.find('input').prop('checked', !!item.active);
$menu.append($li);
if (current_group !== item.inherit_id[1]) {
current_group = item.inherit_id[1];
$menu.append("<li class=\"dropdown-header\">" + current_group + "</li>");
}
var $li = $('<li/>', {role: 'presentation'})
.append($('<a/>', {href: '#', 'data-view-id': item.id, role: 'menuitem'})
.append(qweb.render('web_editor.components.switch', {id: 'switch-' + item.id, label: item.name})));
$li.find('input').prop('checked', !!item.active);
$menu.append($li);
});
});
},