[FIX] ir.ui.view,ir.ui.view.custom: cleanup handling of customized views + add menu...
authorOlivier Dony <odo@openerp.com>
Fri, 7 Jan 2011 16:03:37 +0000 (17:03 +0100)
committerOlivier Dony <odo@openerp.com>
Fri, 7 Jan 2011 16:03:37 +0000 (17:03 +0100)
Custom views are used when users reorganize their dashboards (drag and drop in web), but this should not be
special-cased for board.board model in the core. The web client will instead directly write to the ir.ui.view.custom
table, and the board module will override board.board.fields_view_get to take custom views into account.
The only responsibility of the core is to drop custom views when the original view is updated, to be sure there
are no outdated customizations that remain.

bzr revid: odo@openerp.com-20110107160337-0rovd484id4gfc16

bin/addons/base/ir/ir.xml
bin/addons/base/ir/ir_ui_view.py

index 29a8368..cfa76e3 100644 (file)
         </record>
         <menuitem action="action_ui_view" id="menu_action_ui_view" parent="base.next_id_2"/>
 
+
+        <!-- View customizations -->
+        <record id="view_view_custom_search" model="ir.ui.view">
+            <field name="name">ir.ui.view.custom.search</field>
+            <field name="model">ir.ui.view.custom</field>
+            <field name="type">search</field>
+            <field name="arch" type="xml">
+                <search string="Customized Views">
+                    <field name="user_id"/>
+                    <field name="ref_id"/>
+                </search>
+            </field>
+        </record>
+        <record id="view_view_custom_form" model="ir.ui.view">
+            <field name="name">ir.ui.view.custom.form</field>
+            <field name="model">ir.ui.view.custom</field>
+            <field name="type">form</field>
+            <field name="arch" type="xml">
+                <form string="Customized Views">
+                    <field name="user_id"/>
+                    <field name="ref_id"/>
+                    <separator colspan="4" string="Customized Architecture"/>
+                    <field name="arch" colspan="4" nolabel="1"/>
+                </form>
+            </field>
+        </record>
+        <record id="view_view_custom_tree" model="ir.ui.view">
+            <field name="name">ir.ui.view.custom.tree</field>
+            <field name="model">ir.ui.view.custom</field>
+            <field name="type">tree</field>
+            <field name="arch" type="xml">
+                <tree string="Customized Views">
+                    <field name="user_id"/>
+                    <field name="ref_id"/>
+                </tree>
+            </field>
+        </record>
+        <record id="action_ui_view_custom" model="ir.actions.act_window">
+            <field name="name">Customized Views</field>
+            <field name="type">ir.actions.act_window</field>
+            <field name="res_model">ir.ui.view.custom</field>
+            <field name="help">Customized views are used when users reorganize the content of their dashboard views (via web client)</field>
+        </record>
+        <menuitem action="action_ui_view_custom" id="menu_action_ui_view_custom" parent="base.next_id_4"/>
+
+
         <!-- Attachment -->
         <record id="view_attachment_form" model="ir.ui.view">
             <field name="name">ir.attachment.view</field>
index 023c0cc..b906348 100644 (file)
@@ -95,44 +95,18 @@ class view(osv.osv):
         if not cr.fetchone():
             cr.execute('CREATE INDEX ir_ui_view_model_type_inherit_id ON ir_ui_view (model, type, inherit_id)')
 
-    def read(self, cr, uid, ids, fields=None, context={}, load='_classic_read'):
-
-        if not isinstance(ids, (list, tuple)):
-            ids = [ids]
-
-        result = super(view, self).read(cr, uid, ids, fields, context, load)
-
-        for rs in result:
-            if rs.get('model') == 'board.board':
-                cr.execute("select id,arch,ref_id from ir_ui_view_custom where user_id=%s and ref_id=%s", (uid, rs['id']))
-                oview = cr.dictfetchall()
-                if oview:
-                    rs['arch'] = oview[0]['arch']
-
-
-        return result
-
     def write(self, cr, uid, ids, vals, context={}):
-
         if not isinstance(ids, (list, tuple)):
             ids = [ids]
+        result = super(view, self).write(cr, uid, ids, vals, context)
 
-        exist = self.pool.get('ir.ui.view').browse(cr, uid, ids[0])
-        if exist.model == 'board.board' and 'arch' in vals:
-            vids = self.pool.get('ir.ui.view.custom').search(cr, uid, [('user_id','=',uid), ('ref_id','=',ids[0])])
-            vals2 = {'user_id': uid, 'ref_id': ids[0], 'arch': vals.pop('arch')}
+        # drop the corresponding view customizations (used for dashboards for example), otherwise
+        # not all users would see the updated views
+        custom_view_ids = self.pool.get('ir.ui.view.custom').search(cr, uid, [('ref_id','in',ids)])
+        if custom_view_ids:
+            self.pool.get('ir.ui.view.custom').unlink(cr, uid, custom_view_ids)
 
-            # write fields except arch to the `ir.ui.view`
-            result = super(view, self).write(cr, uid, ids, vals, context)
-
-            if not vids:
-                self.pool.get('ir.ui.view.custom').create(cr, uid, vals2)
-            else:
-                self.pool.get('ir.ui.view.custom').write(cr, uid, vids, vals2)
-
-            return result
-
-        return super(view, self).write(cr, uid, ids, vals, context)
+        return result
 
     def graph_get(self, cr, uid, id, model, node_obj, conn_obj, src_node, des_node,label,scale,context={}):
         if not label: