change implementation for the opening page / group list

* change in create menu
* add new wizard that open the page in form view

bzr revid: mga@tinyerp.com-20081205110648-rxgy2sfxl3tp5lkm
This commit is contained in:
Mantavya Gajjar 2008-12-05 16:36:48 +05:30
parent c195f13786
commit bf4d49d238
7 changed files with 92 additions and 145 deletions

View File

@ -44,6 +44,8 @@ class WikiGroup(osv.osv):
'create_date':fields.datetime("Created Date", select=True),
'template': fields.text('Wiki Template'),
'section': fields.boolean("Make Section ?"),
'home':fields.many2one('wiki.wiki', 'Pages'),
'action_id': fields.many2one('ir.ui.menu', 'Menu')
}
WikiGroup()

View File

@ -8,6 +8,7 @@
<wizard
id="wizard_group_menu_create"
string="Create Menu"
menu="True"
name="wiki.create.menu"/>
<record model="ir.ui.view" id="wiki_group_tree">

View File

@ -1,3 +1,4 @@
import open_page
import create_menu
import show_diff
import make_index

View File

@ -20,7 +20,6 @@
#
##############################################################################
import time
import wizard
import osv
@ -31,31 +30,34 @@ section_form = '''<?xml version="1.0"?>
<separator string="Menu Information" colspan="4"/>
<field name="menu_name"/>
<field name="menu_parent_id"/>
<field name="page" colspan="4" domain="[('group_id','=', active_id)]"/>
</form>'''
section_fields = {
'menu_name': {'string':'Menu Name', 'type':'char', 'required':True, 'size':64},
'menu_parent_id': {'string':'Parent Menu', 'type':'many2one', 'relation':'ir.ui.menu', 'required':True},
'page': {'string':'Group Home Page', 'type':'many2one', 'relation':'wiki.wiki'},
}
def wiki_menu_create(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
group = pool.get('wiki.groups').browse(cr, uid, data['id'])
action_id = pool.get('ir.actions.wizard').search(cr, uid, [('wiz_name','=','wiki.wiki.page.open')])
action_id = pool.get('ir.actions.act_window').create(cr, uid, {
'name': group.name,
'view_type':'form',
'view_mode':"tree,form",
'context': "{'group_id':%d, 'section':%d}" % (group.id, group.section),
'domain': "[('group_id','child_of',[%d])]" % (group.id,),
'res_model': 'wiki.wiki'
})
pool.get('ir.ui.menu').create(cr, uid, {
menu_id = pool.get('ir.ui.menu').create(cr, uid, {
'name': data['form']['menu_name'],
'parent_id': data['form']['menu_parent_id'],
'icon': 'STOCK_JUSTIFY_FILL',
'action': 'ir.actions.act_window,'+str(action_id)
'icon': 'STOCK_DIALOG_QUESTION',
'action': 'ir.actions.wizard,'+str(action_id[0])
}, context)
home = data['form']['page']
res = {
'home':home,
'action_id':menu_id
}
pool.get('wiki.groups').write(cr, uid, [data['id']], res)
return {}
class wizard_create_menu(wizard.interface):

View File

@ -0,0 +1,68 @@
# -*- encoding: utf-8 -*-
##############################################################################
#
# OpenERP, Open Source Management Solution
# Copyright (C) 2004-2008 Tiny SPRL (<http://tiny.be>). All Rights Reserved
# $Id$
#
# 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 3 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
##############################################################################
import wizard
import netsvc
import time
import pooler
from osv import osv
from tools.translate import _
class wiz_timesheet_open(wizard.interface):
def _open_wiki_page(self, cr, uid, data, context):
pool = pooler.get_pool(cr.dbname)
menu_id = data['id']
group_ids = pool.get('wiki.groups').search(cr, uid, [('action_id','=',menu_id)])
group = pool.get('wiki.groups').browse(cr, uid, group_ids[0])
value = {
'context': "{'group_id':%d}" % (group.id),
'domain': "[('group_id','child_of',[%s])]" % (group.id),
'name': 'Wiki Page',
'view_type': 'form',
'view_mode': 'form,tree',
'res_model': 'wiki.wiki',
'view_id': False,
'type': 'ir.actions.act_window',
}
if group.home :
value['res_id'] = group.home.id
else:
value['view_type'] = 'form'
value['view_mode'] = 'tree,form'
return value
states = {
'init' : {
'actions' : [],
'result' : {'type':'action', 'action':_open_wiki_page, 'state':'end'}
}
}
wiz_timesheet_open('wiki.wiki.page.open')
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

View File

@ -1,133 +0,0 @@
def sort(data, index):
for i in range(len(data)):
j = i + 1
for j in range(len(data)-1):
d1 = data[i].split('.')
d2 = data[j].split('.')
l1 = len(d1)
l2 = len(d2)
max = 0
if l1 < l2:
max = l1
elif l2 < l1:
max = l2
else:
max = l1
if max == 1:
if int(d1[0]) == int(d2[0]):
if len(d1) < len(d2):
tmp = data[i]
data[i] = data[j]
data[j] = tmp
continue
for p in range(0, max):
val1 = val2 = 0
try:
val1 = int(d1[p])
except:
val1 = 0
try:
val2 = int(d2[p])
except:
val2 = 0
if val1 < val2:
tmp = data[i]
data[i] = data[j]
data[j] = tmp
if data[i].startswith(data[j]):
tmp = data[i]
tmp = tmp.replace(data[j],'')
def group(data):
gp = {}
for i in range(len(data)):
d1 = data[i].split('.')[0]
if gp.has_key(d1):
gp[d1].append(data[i])
else:
gp[d1] = [data[i]]
return gp
def max(data):
max = 0
for i in range(len(data)):
d = str(data[i]).split('.')
if len(d) > max:
max = len(d)
return max
def toint(data):
for i in range(len(data)):
data[i] = int(data[i])
def rearrange(key, groups):
i = 1
new = {}
for ky in key:
new[i] = groups[str(ky)]
i += 1
return new
def reindex(key, groups):
if groups[0] != key:
groups[0] = key
lvl_group = {}
level = max(groups)
for i in range(len(groups)):
dg = str(groups[i]).split('.')
index = len(dg)
if lvl_group.has_key(str(index)):
lvl_group[str(index)].append(groups[i])
else:
lvl_group[str(index)] = [groups[i]]
for i in range(2, level+1):
ixd = 1
gps = lvl_group[str(i)]
for j in range(len(gps)):
dt = gps[j].split('.')
new =""
for k in range(i-1):
new += str(dt[k])
new += '.'
new += str(ixd)
ixd += 1
gps[j] = new
print lvl_group
if __name__ == '__main__':
data = ['1', '10.1', '10.3', '1.1', '1.2.3', '1.7', '3.1.8', '1.2.2', '1.2.10', '1.3', '1.4', '2', '20.2', '2.1', '2.2', '3', '3.1', '1.2.1', '2.1.2']
sort(data, 0)
grp = group(data)
for gp in grp:
loop = max(grp[gp])
for lp in range(1, loop):
sort(grp[gp],lp)
key = grp.keys()
toint(key)
key.sort()
groups = rearrange(key, grp)
new_data = []
for key in groups:
new_data.extend(groups[key])
#print groups[key]
print 'XXXXXXXXXXXXXXXXX : ', new_data
# print groups
#

View File

@ -25,5 +25,11 @@
string="Create Index"
name="wiki.make.index"
model="wiki.wiki"/>
<wizard
id="wizard_open_page"
string="Open Page"
name="wiki.wiki.page.open"
model="wiki.wiki"/>
</data>
</openerp>