[IMP] server behavior fix: split tree view mode into tree and list based on view_type, nuke view_type
bzr revid: xmo@openerp.com-20110331152531-cpff6js0k8v4dtk9
This commit is contained in:
@@ -230,8 +230,38 @@ class Menu(openerpweb.Controller):
|
||||
req.session.evaluation_context(
|
||||
action['context'])) or []
|
||||
|
||||
self.fix_view_modes(action)
|
||||
|
||||
return {"action": actions}
|
||||
|
||||
def fix_view_modes(self, action):
|
||||
""" For historical reasons, OpenERP has weird dealings in relation to
|
||||
view_mode and the view_type attribute (on window actions):
|
||||
|
||||
* one of the view modes is ``tree``, which stands for both list views
|
||||
and tree views
|
||||
* the choice is made by checking ``view_type``, which is either
|
||||
``form`` for a list view or ``tree`` for an actual tree view
|
||||
|
||||
This methods simply folds the view_type into view_mode by adding a
|
||||
new view mode ``list`` which is the result of the ``tree`` view_mode
|
||||
in conjunction with the ``form`` view_type.
|
||||
|
||||
TODO: this should go into the doc, some kind of "peculiarities" section
|
||||
|
||||
:param dict action: an action descriptor
|
||||
:returns: nothing, the action is modified in place
|
||||
"""
|
||||
if action.pop('view_type') != 'form':
|
||||
return
|
||||
|
||||
action['view_mode'] = ','.join(
|
||||
mode if mode != 'tree' else 'list'
|
||||
for mode in action['view_mode'].split(','))
|
||||
action['views'] = [
|
||||
[id, mode if mode != 'tree' else 'list']
|
||||
for id, mode in action['views']
|
||||
]
|
||||
|
||||
class DataSet(openerpweb.Controller):
|
||||
_cp_path = "/base/dataset"
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
|
||||
openerp.base.list = function (openerp) {
|
||||
|
||||
openerp.base.views.add('tree', 'openerp.base.ListView');
|
||||
openerp.base.views.add('list', 'openerp.base.ListView');
|
||||
openerp.base.ListView = openerp.base.Controller.extend({
|
||||
init: function(session, element_id, dataset, view_id) {
|
||||
this._super(session, element_id);
|
||||
|
||||
@@ -250,6 +250,14 @@ openerp.base.GanttView = openerp.base.Controller.extend({
|
||||
// Dhtmlx gantt ?
|
||||
});
|
||||
|
||||
openerp.base.views.add('tree', 'openerp.base.TreeView');
|
||||
/**
|
||||
* Genuine tree view (the one displayed as a tree, not the list)
|
||||
*/
|
||||
openerp.base.TreeView = openerp.base.Controller.extend({
|
||||
|
||||
});
|
||||
|
||||
openerp.base.DiagramView = openerp.base.Controller.extend({
|
||||
//
|
||||
});
|
||||
|
||||
@@ -97,3 +97,55 @@ class LoadTest(unittest2.TestCase):
|
||||
}]
|
||||
}]
|
||||
)
|
||||
|
||||
class ActionMungerTest(unittest2.TestCase):
|
||||
def setUp(self):
|
||||
self.menu = base.controllers.main.Menu()
|
||||
def test_actual_treeview(self):
|
||||
action = {
|
||||
"views": [[False, "tree"], [False, "form"],
|
||||
[False, "calendar"]],
|
||||
"view_type": "tree",
|
||||
"view_id": False,
|
||||
"view_mode": "tree,form,calendar"
|
||||
}
|
||||
changed = action.copy()
|
||||
del action['view_type']
|
||||
self.menu.fix_view_modes(changed)
|
||||
|
||||
self.assertEqual(changed, action)
|
||||
|
||||
def test_list_view(self):
|
||||
action = {
|
||||
"views": [[False, "tree"], [False, "form"],
|
||||
[False, "calendar"]],
|
||||
"view_type": "form",
|
||||
"view_id": False,
|
||||
"view_mode": "tree,form,calendar"
|
||||
}
|
||||
self.menu.fix_view_modes(action)
|
||||
|
||||
self.assertEqual(action, {
|
||||
"views": [[False, "list"], [False, "form"],
|
||||
[False, "calendar"]],
|
||||
"view_id": False,
|
||||
"view_mode": "list,form,calendar"
|
||||
})
|
||||
|
||||
def test_redundant_views(self):
|
||||
|
||||
action = {
|
||||
"views": [[False, "tree"], [False, "form"],
|
||||
[False, "calendar"], [42, "tree"]],
|
||||
"view_type": "form",
|
||||
"view_id": False,
|
||||
"view_mode": "tree,form,calendar"
|
||||
}
|
||||
self.menu.fix_view_modes(action)
|
||||
|
||||
self.assertEqual(action, {
|
||||
"views": [[False, "list"], [False, "form"],
|
||||
[False, "calendar"], [42, "list"]],
|
||||
"view_id": False,
|
||||
"view_mode": "list,form,calendar"
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user