2010-03-02 10:56:55 +00:00
|
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
|
##############################################################################
|
|
|
|
|
#
|
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-03-17 08:36:08 +00:00
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRl (<http://tiny.be>).
|
2010-03-02 10:56:55 +00:00
|
|
|
|
#
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2010-03-17 08:36:08 +00:00
|
|
|
|
# it under the terms of the GNU Affero General Public license as
|
2010-03-02 10:56:55 +00:00
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
2010-03-17 08:36:08 +00:00
|
|
|
|
# license, or (at your option) any later version.
|
2010-03-02 10:56:55 +00:00
|
|
|
|
#
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2010-03-17 08:36:08 +00:00
|
|
|
|
# MERCHANTABIlITY or FITNESS FOR A PARTICUlAR PURPOSE. See the
|
|
|
|
|
# GNU Affero General Public license for more details.
|
2010-03-02 10:56:55 +00:00
|
|
|
|
#
|
2010-03-17 08:36:08 +00:00
|
|
|
|
# You should have received a copy of the GNU Affero General Public license
|
2010-03-02 10:56:55 +00:00
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
#
|
|
|
|
|
##############################################################################
|
|
|
|
|
|
2010-03-02 04:55:33 +00:00
|
|
|
|
from osv import fields, osv
|
2011-03-22 12:05:29 +00:00
|
|
|
|
from tools.translate import _
|
2010-03-02 04:55:33 +00:00
|
|
|
|
|
|
|
|
|
class wiki_make_index(osv.osv_memory):
|
2010-03-16 14:01:43 +00:00
|
|
|
|
""" Create Index For Selected Page """
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2010-03-02 04:55:33 +00:00
|
|
|
|
_name = "wiki.make.index"
|
|
|
|
|
_description = "Create Index"
|
|
|
|
|
|
2010-11-22 10:37:53 +00:00
|
|
|
|
def wiki_do_index(self, cr, uid, ids, context=None):
|
2010-03-17 08:36:08 +00:00
|
|
|
|
|
2010-03-15 13:40:23 +00:00
|
|
|
|
""" Makes Index according to page hierarchy
|
|
|
|
|
@param cr: the current row, from the database cursor,
|
|
|
|
|
@param uid: the current user’s ID for security checks,
|
2010-03-17 08:36:08 +00:00
|
|
|
|
@param ids: list of wiki index’s IDs
|
2010-03-15 13:40:23 +00:00
|
|
|
|
|
|
|
|
|
"""
|
2010-11-23 07:05:05 +00:00
|
|
|
|
if context is None:
|
2010-11-22 10:37:53 +00:00
|
|
|
|
context = {}
|
2010-03-16 14:01:43 +00:00
|
|
|
|
data = context and context.get('active_ids', []) or []
|
2011-03-21 09:27:55 +00:00
|
|
|
|
|
|
|
|
|
if not data:
|
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
|
|
|
|
|
2010-11-22 10:37:53 +00:00
|
|
|
|
for index_obj in self.browse(cr, uid, ids, context=context):
|
2010-03-02 04:55:33 +00:00
|
|
|
|
wiki_pool = self.pool.get('wiki.wiki')
|
2010-06-10 13:34:19 +00:00
|
|
|
|
cr.execute("Select id, section from wiki_wiki where id IN %s \
|
|
|
|
|
order by section ", (tuple(data),))
|
2010-03-02 04:55:33 +00:00
|
|
|
|
lst0 = cr.fetchall()
|
2011-03-22 12:05:29 +00:00
|
|
|
|
if not lst0[0][1]:
|
2012-08-07 11:34:14 +00:00
|
|
|
|
raise osv.except_osv(_('Warning!'), _('There is no section in this Page.'))
|
2011-03-23 09:47:15 +00:00
|
|
|
|
|
2010-03-02 04:55:33 +00:00
|
|
|
|
lst = []
|
|
|
|
|
s_ids = {}
|
2010-03-17 09:27:12 +00:00
|
|
|
|
|
2010-03-02 04:55:33 +00:00
|
|
|
|
for l in lst0:
|
|
|
|
|
s_ids[l[1]] = l[0]
|
|
|
|
|
lst.append(l[1])
|
|
|
|
|
|
|
|
|
|
lst.sort()
|
|
|
|
|
val = None
|
|
|
|
|
def toint(x):
|
|
|
|
|
try:
|
|
|
|
|
return int(x)
|
|
|
|
|
except:
|
|
|
|
|
return 1
|
|
|
|
|
|
|
|
|
|
lst = map(lambda x: map(toint, x.split('.')), lst)
|
|
|
|
|
|
|
|
|
|
result = []
|
|
|
|
|
current = ['0']
|
|
|
|
|
current2 = []
|
|
|
|
|
|
|
|
|
|
for l in lst:
|
|
|
|
|
for pos in range(len(l)):
|
|
|
|
|
if pos >= len(current):
|
|
|
|
|
current.append('1')
|
|
|
|
|
continue
|
|
|
|
|
if (pos == len(l) - 1) or (pos >= len(current2)) or (toint(l[pos]) > toint(current2[pos])):
|
|
|
|
|
current[pos] = str(toint(current[pos]) + 1)
|
|
|
|
|
current = current[:pos + 1]
|
|
|
|
|
if pos == len(l) - 1:
|
|
|
|
|
break
|
|
|
|
|
key = ('.'.join([str(x) for x in l]))
|
|
|
|
|
id = s_ids[key]
|
|
|
|
|
val = ('.'.join([str(x) for x in current[:]]), id)
|
|
|
|
|
|
|
|
|
|
if val:
|
|
|
|
|
result.append(val)
|
|
|
|
|
current2 = l
|
|
|
|
|
|
|
|
|
|
for rs in result:
|
2010-03-02 10:56:55 +00:00
|
|
|
|
wiki_pool.write(cr, uid, [rs[1]], {'section':rs[0]})
|
2010-03-17 09:27:12 +00:00
|
|
|
|
|
2010-12-28 10:41:38 +00:00
|
|
|
|
return {'type': 'ir.actions.act_window_close'}
|
2010-03-02 04:55:33 +00:00
|
|
|
|
|
|
|
|
|
wiki_make_index()
|
|
|
|
|
|
2010-03-02 10:56:55 +00:00
|
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|