[wiki] some improvement
authorHarry (OpenERP) <hmo@tinyerp.com>
Mon, 12 Jul 2010 06:39:51 +0000 (12:09 +0530)
committerHarry (OpenERP) <hmo@tinyerp.com>
Mon, 12 Jul 2010 06:39:51 +0000 (12:09 +0530)
bzr revid: hmo@tinyerp.com-20100712063951-2jxybuidx49jw7o4

addons/wiki/security/ir.model.access.csv
addons/wiki/test/wiki_test00.yml
addons/wiki/wiki.py
addons/wiki/wiki_view.xml
addons/wiki/wizard/wiki_create_menu.py
addons/wiki/wizard/wiki_create_menu_view.xml
addons/wiki/wizard/wiki_show_diff.py
addons/wiki/wizard/wiki_show_diff_view.xml
addons/wiki/wizard/wiki_wiki_page_open_view.xml

index 67c7bf7..a54122e 100644 (file)
@@ -3,5 +3,4 @@
 "wiki_groups_all","wiki.groups","model_wiki_groups",,1,0,0,0
 "wiki_wiki","wiki.wiki","model_wiki_wiki","base.group_user",1,1,1,1
 "wiki_groups","wiki.groups","model_wiki_groups","base.group_system",1,1,1,1
-"wiki_groups_link","wiki.groups.link","model_wiki_groups_link","base.group_system",1,1,1,1
 "wiki_wiki_history","wiki.wiki.history","model_wiki_wiki_history","base.group_user",1,0,1,0
index e53871e..c77e714 100755 (executable)
       FAQs, quality manuals, technical references, etc.
 
       '
-
+-
+    Creating a wiki make index record
+-
+    !record {model: wiki.make.index, id: wiki_make_index_1}:
+    {}
 -
     I create Index on this current page by clicking on "Create Index" wizard
 -
     !python {model: wiki.make.index}: |
-      ids = self.search(cr, uid, [])
-      self.wiki_do_index(cr, uid, ids , {'active_ids': [ref('wiki_wiki_openerpwikiediting0')]})
+      self.wiki_do_index(cr, uid, [ref("wiki_make_index_1")], {"active_model":
+      wiki.wiki, "active_ids": [ref("wiki_wiki_openerpwikiediting0")], "tz": False, "active_id":
+      ref("wiki_wiki_openerpwikiediting0"), })
 -
-    # Remaining Act window
     I check the page history for the current page by clicking on "Page History".After that find difference between history.
 -
+    !python {model: wizard.wiki.history.show_diff}: |
+      ids = self.search(cr, uid, [])
+      self.get_diff(cr, uid, {'active_id': [ref('wiki_wiki_openerpwikiediting0')]})
+-
     I create a new wiki group on the Given Home Page
 -
     !record {model: wiki.groups, id: wiki_groups_wikigroupediting0}:
       name: Wiki Group Editing
       home: wiki.wiki_wiki_quickstart0
 -
-    I open a wiki page on this given group and page by clicking on Open wiki Page wizard.
+    I Open the page for click on  "Open Wiki Page" button.
 -
-    !python {model: wiki.wiki.page.open}: |
-      ids = self.search(cr, uid, [])
-      self.open_wiki_page(cr, uid, ids, {'active_ids': [ref('wiki_groups_wikigroupediting0')]})
+    !python {model: wiki.groups}: |
+      self.open_wiki_page(cr, uid, [ref("wiki_groups_wikigroupediting0")], context)
 -
-    # Remaining beacuse of Act window (I search the page by clicking on the "search page".)
     In order to create a menu I will create wizard data
 -
     !record {model: wiki.groups, id: wiki.wiki_groups_wikiformatting0}:
@@ -55,7 +61,6 @@
     !record {model: wiki.create.menu, id: wiki_create_menu_0}:
       menu_name: Wiki Test menu
       menu_parent_id: base.menu_base_partner
-      page: wiki.wiki_wiki_openerpwikiediting0
 -
     I fill in the form and create the menu
 -
index 3fe9d25..1f85f04 100644 (file)
@@ -1,31 +1,25 @@
 # -*- coding: utf-8 -*-
 ##############################################################################
 #
-# Copyright (c) 2004-2006 TINY SPRL. (http://axelor.com) All Rights Reserved.
+#    OpenERP, Open Source Management Solution
+#    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
 #
-# WARNING: This program as such is intended to be used by professional
-# programmers who take the whole responsability of assessing all potential
-# consequences resulting from its eventual inadequacies and bugs
-# End users who are looking for a ready-to-use solution with commercial
-# garantees and support are strongly adviced to contract a Free Software
-# Service Company
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU Affero General Public License as
+#    published by the Free Software Foundation, either version 3 of the
+#    License, or (at your option) any later version.
 #
-# This program is Free Software; you can redistribute it and/or
-# modify it under the terms of the GNU General Public License
-# as published by the Free Software Foundation; either version 2
-# of the License, or (at your option) any later version.
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU Affero General Public License for more details.
 #
-# This program is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with this program; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+#    You should have received a copy of the GNU Affero General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 ##############################################################################
 
+
 from osv import fields, osv
 from tools.translate import _
 import difflib
@@ -53,30 +47,56 @@ class WikiGroup(osv.osv):
        'method':fields.selection([('list', 'List'), ('page', 'Home Page'), \
                                    ('tree', 'Tree')], 'Display Method'),
        'home':fields.many2one('wiki.wiki', 'Home Page'),
+       'menu_id': fields.many2one('ir.ui.menu', "Menu", readonly=True),
     }
 
     _defaults = {
         'method': lambda *a: 'page',
     }
 
+    def open_wiki_page(self, cr, uid, ids, context):
+
+        """ Opens Wiki Page of Group
+        @param cr: the current row, from the database cursor,
+        @param uid: the current user’s ID for security checks,
+        @param ids: List of open wiki group’s IDs
+        @return: dictionay of open wiki window on give group id
+        """
+        if not context:
+            context = {}
+        if type(ids) in (int,long,):
+            ids = [ids]
+        group_id = False
+        if ids:
+            group_id = ids[0]
+        if not group_id:
+            return {}
+        value = {            
+            'name': 'Wiki Page',
+            'view_type': 'form',
+            'view_mode': 'form,tree',
+            'res_model': 'wiki.wiki',
+            'view_id': False,
+            'type': 'ir.actions.act_window',
+            'nodestroy': True,
+        }
+        group = self.browse(cr, uid, group_id, context=context)
+        value['domain'] = "[('group_id','=',%d)]" % (group.id)
+        if group.method == 'page':
+            value['res_id'] = group.home.id
+        elif group.method == 'list':
+            value['view_type'] = 'form'
+            value['view_mode'] = 'tree,form'
+        elif group.method == 'tree':
+            view_id = self.pool.get('ir.ui.view').search(cr, uid, [('name', '=', 'wiki.wiki.tree.childs')])
+            value['view_id'] = view_id
+            value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
+            value['view_type'] = 'tree'
+
+        return value
 WikiGroup()
 
 
-class GroupLink(osv.osv):
-    """ Apply Group Link """
-
-    _name = "wiki.groups.link"
-    _description = "Wiki Groups Links"
-    _rec_name = 'action_id'
-
-    _columns = {
-       'group_id': fields.many2one('wiki.groups', 'Parent Group', ondelete='set null'),
-       'action_id': fields.many2one('ir.ui.menu', 'Menu')
-    }
-
-GroupLink()
-
-
 class Wiki2(osv.osv):
     """ Wiki Page """
 
@@ -96,11 +116,11 @@ class Wiki2(osv.osv):
         'minor_edit': fields.boolean('Minor edit', select=True),
         'summary': fields.char('Summary', size=256),
         'section': fields.char('Section', size=32, help="Use page section code like 1.2.1", select=True),
-        'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null', 
+        'group_id': fields.many2one('wiki.groups', 'Wiki Group', select=1, ondelete='set null',
             help="Topic, also called Wiki Group"),
-        'toc': fields.boolean('Table of Contents', 
+        'toc': fields.boolean('Table of Contents',
             help="Indicates that this pages is a table of contents (linking to other pages)"),
-        'review': fields.boolean('Needs Review', select=True, 
+        'review': fields.boolean('Needs Review', select=True,
             help="Indicates that this page should be reviewed, raising the attention of other contributors"),
         'parent_id': fields.many2one('wiki.wiki', 'Parent Page'),
         'child_ids': fields.one2many('wiki.wiki', 'parent_id', 'Child Pages'),
index 5a0a3d5..6e6d608 100644 (file)
                         <field name="template" colspan="4" nolabel="1" widget="text_wiki"/>
                     </page>
                     </notebook>
+                     <field name="menu_id"/>
                      <button
                          name="%(wiki.action_wiki_create_menu)d"
                          string="Create Menu"
                           type="action"
-                          icon="gtk-justify-fill" />
+                          icon="gtk-justify-fill"
+                          attrs="{'invisible':[('menu_id','!=',False)]}"/>
+                     <button
+                         name="open_wiki_page"
+                         string="Open Wiki Page"
+                          type="object"
+                          icon="gtk-ok" />
                 </form>
             </field>
         </record>
                     <group col="8" colspan="4">
                         <field name="name" select="1" colspan="8"/>
                         <field name="group_id" string="Topic" select="1" on_change="onchange_group_id(group_id, text_area)"/>
-                        <field name="section" invisible="not context.get('section',False)"/>
+                        <field name="section"/>
                     </group>
                     <notebook colspan="4">
                         <page string="Content">
             </field>
         </record>
 
-<!-- wiki Search view  -->
+    <!-- wiki Search view  -->
 
         <record id="view_wiki_filter" model="ir.ui.view">
             <field name="name">wiki.wiki.search</field>
index f1b2838..7cee4f8 100644 (file)
@@ -29,7 +29,6 @@ class wiki_create_menu(osv.osv_memory):
     _columns = {
         'menu_name': fields.char('Menu Name', size=256, select=True, required=True),
         'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu', required=True),
-        'page': fields.many2one('wiki.wiki', 'Group Home Page'),
     }
 
     def wiki_menu_create(self, cr, uid, ids, context):
@@ -40,28 +39,51 @@ class wiki_create_menu(osv.osv_memory):
         @param ids: List of create menu’s IDs
 
         """
-        mod_obj = self.pool.get('ir.model.data')
-        for menu in self.browse(cr, uid, ids):
-            action_id = mod_obj._get_id(cr, uid, 'wiki', 'action_view_wiki_wiki_page_open')
-            action_id = mod_obj.copy(cr, uid, action_id, context=context, default={
-                'domain':"[('group_id','=',"+str(context.get('active_id',False))+"]",
-                "name": menu.menu_name
-            })
+        obj_wiki_group = self.pool.get('wiki.groups')
+        obj_view = self.pool.get('ir.ui.view')
+        obj_menu = self.pool.get('ir.ui.menu')
+        obj_action = self.pool.get('ir.actions.act_window')
+        group_id = context.get('active_id', False)
+        if not group_id:
+            return {}
 
-            menu_id = self.pool.get('ir.ui.menu').create(cr, uid, {
-                            'name': menu.menu_name,
-                            'parent_id':menu.menu_parent_id.id,
-                            'icon': 'STOCK_DIALOG_QUESTION',
-                            'action': 'ir.actions.act_window,'+ str(action_id)
-                            }, context)
-            home = menu.page.id
-            group_id = menu.id
-            res = {
-                    'home': home,
-                    }
-            self.pool.get('wiki.groups').write(cr, uid, ids, res)
-            self.pool.get('wiki.groups.link').create(cr, uid,
-                                {'group_id': group_id, 'action_id': menu_id})
+        datas = self.browse(cr, uid, ids, context=context)
+        data = False
+        if datas:
+            data = datas[0]
+        if not data:
+            return {}
+        value = {            
+            'name': 'Wiki Page',
+            'view_type': 'form',
+            'view_mode': 'form,tree',
+            'res_model': 'wiki.wiki',
+            'view_id': False,
+            'type': 'ir.actions.act_window',
+            'nodestroy': True,
+        }
+        group = obj_wiki_group.browse(cr, uid, group_id, context=context)
+        value['domain'] = "[('group_id','=',%d)]" % (group.id)
+        if group.method == 'page':
+            value['res_id'] = group.home.id
+        elif group.method == 'list':
+            value['view_type'] = 'form'
+            value['view_mode'] = 'tree,form'
+        elif group.method == 'tree':
+            view_id = obj_view.search(cr, uid, [('name', '=', 'wiki.wiki.tree.childs')])
+            value['view_id'] = view_id
+            value['domain'] = [('group_id', '=', group.id), ('parent_id', '=', False)]
+            value['view_type'] = 'tree'
+
+        action_id = obj_action.create(cr, uid, value)
+            
+        menu_id = obj_menu.create(cr, uid, {
+                        'name': data.menu_name,
+                        'parent_id':data.menu_parent_id.id,
+                        'icon': 'STOCK_DIALOG_QUESTION',
+                        'action': 'ir.actions.act_window,'+ str(action_id),
+                        }, context)
+        obj_wiki_group.write(cr, uid, [group_id], {'menu_id':menu_id})        
         return {}
 
 
index e62f964..c8f4661 100644 (file)
@@ -13,7 +13,6 @@
                        <separator string="Menu Information" colspan="4" />
                        <field name="menu_name" />
                        <field name="menu_parent_id" />
-                       <field name="page" colspan="4" />
                        <separator string="" colspan="4" />
                    <label string="" colspan="2" />
                        <button special="cancel" string="Cancel" />
index d1a17f0..7654ce3 100644 (file)
@@ -21,6 +21,7 @@
 
 from osv import fields, osv
 from tools.translate import _
+import base64
 
 class showdiff(osv.osv_memory):
     """ Disp[ay Difference for History """
@@ -34,29 +35,31 @@ class showdiff(osv.osv_memory):
         """
         history = self.pool.get('wiki.wiki.history')
         ids = context.get('active_ids')
+
         diff = ""
         if len(ids) == 2:
             if ids[0] > ids[1]:
-                diff = history.getDiff(cr, uid, ids[1], ids[0])
+                diff = base64.encodestring(history.getDiff(cr, uid, ids[1], ids[0]))
             else:
-                diff = history.getDiff(cr, uid, ids[0], ids[1])
+                diff = base64.encodestring(history.getDiff(cr, uid, ids[0], ids[1]))
 
         elif len(ids) == 1:
             old = history.browse(cr, uid, ids[0])
             nids = history.search(cr, uid, [('wiki_id', '=', old.wiki_id.id)])
             nids.sort()
-            diff = history.getDiff(cr, uid, ids[0], nids[-1])
+            diff = base64.encodestring(history.getDiff(cr, uid, ids[0], nids[-1]))
         else:
             raise osv.except_osv(_('Warning'), _('You need to select minimum 1 or maximum 2 history revision!'))
 
+
         return diff
 
     _columns = {
-        'diff': fields.text('Diff'),
+        'file_path':fields.binary('Diff', readonly=True),
     }
 
     _defaults = {
-        'diff': get_diff
+        'file_path': get_diff
     }
 
 showdiff()
index ec8fcb3..b9a8264 100644 (file)
             <field name="arch" type="xml">
               <form string="Difference">
                         <separator colspan="4" string="Notes"/>
-                        <field name="diff" nolabel="1" colspan="4" width="300"/>
+                         <field name="file_path" colspan="4" width="300"/>
                <label string="" colspan="2" />
                <group>
-                   <button special="cancel" string="OK" icon="gtk-ok" />
+                   <button special="cancel" string="Close" icon="gtk-close" />
                </group>
                        </form>
             </field>
index 507f3d5..bc87641 100644 (file)
             <field name="view_mode">form</field>
             <field name="target">new</field>
        </record>
-
-<!-- Open Page Action window  -->
-
-       <act_window id="action_view_wiki_wiki_page_open_vals"
-               key2="client_action_multi" name="Open Wiki Page"
-               res_model="wiki.wiki.page.open" src_model="wiki.groups"
-               view_mode="form" target="new" view_type="form" />
     </data>
 </openerp>