1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2010 Tiny SPRl (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public license as
9 # published by the Free Software Foundation, either version 3 of the
10 # license, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABIlITY or FITNESS FOR A PARTICUlAR PURPOSE. See the
15 # GNU Affero General Public license for more details.
17 # You should have received a copy of the GNU Affero General Public license
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
23 from tools.translate import _
25 class wiki_make_index(osv.osv_memory):
26 """ Create Index For Selected Page """
28 _name = "wiki.make.index"
29 _description = "Create Index"
31 def wiki_do_index(self, cr, uid, ids, context=None):
33 """ Makes Index according to page hierarchy
34 @param cr: the current row, from the database cursor,
35 @param uid: the current user’s ID for security checks,
36 @param ids: list of wiki index’s IDs
41 data = context and context.get('active_ids', []) or []
44 return {'type': 'ir.actions.act_window_close'}
46 for index_obj in self.browse(cr, uid, ids, context=context):
47 wiki_pool = self.pool.get('wiki.wiki')
48 cr.execute("Select id, section from wiki_wiki where id IN %s \
49 order by section ", (tuple(data),))
52 raise osv.except_osv(_('Warning!'), _('There is no section in this Page.'))
69 lst = map(lambda x: map(toint, x.split('.')), lst)
76 for pos in range(len(l)):
77 if pos >= len(current):
80 if (pos == len(l) - 1) or (pos >= len(current2)) or (toint(l[pos]) > toint(current2[pos])):
81 current[pos] = str(toint(current[pos]) + 1)
82 current = current[:pos + 1]
85 key = ('.'.join([str(x) for x in l]))
87 val = ('.'.join([str(x) for x in current[:]]), id)
94 wiki_pool.write(cr, uid, [rs[1]], {'section':rs[0]})
96 return {'type': 'ir.actions.act_window_close'}
100 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: