mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-21 04:42:18 -06:00
use new API
This commit is contained in:
committed by
Justine Doutreloux
parent
0f0dc88d03
commit
fa5f889f5f
@@ -18,8 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import document_page_create_menu
|
||||
import document_page_show_diff
|
||||
from . import document_page_create_menu
|
||||
from . import document_page_show_diff
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -18,50 +18,43 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp import SUPERUSER_ID
|
||||
from openerp.osv import fields, osv
|
||||
from openerp import models, fields, api
|
||||
|
||||
|
||||
class document_page_create_menu(osv.osv_memory):
|
||||
class document_page_create_menu(models.TransientModel):
|
||||
""" Create Menu """
|
||||
_name = "document.page.create.menu"
|
||||
_description = "Wizard Create Menu"
|
||||
|
||||
_columns = {
|
||||
'menu_name': fields.char('Menu Name', size=256, required=True),
|
||||
'menu_parent_id': fields.many2one('ir.ui.menu', 'Parent Menu',
|
||||
required=True),
|
||||
}
|
||||
menu_name = fields.Char(
|
||||
'Menu Name',
|
||||
required=True
|
||||
)
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(document_page_create_menu, self).default_get(cr, uid,
|
||||
fields,
|
||||
context=
|
||||
context)
|
||||
page_id = context.get('active_id')
|
||||
obj_page = self.pool.get('document.page')
|
||||
page = obj_page.browse(cr, uid, page_id, context=context)
|
||||
menu_parent_id = fields.Many2one(
|
||||
'ir.ui.menu',
|
||||
'Parent Menu',
|
||||
required=True
|
||||
)
|
||||
|
||||
@api.model
|
||||
def default_get(self, fields_list):
|
||||
res = super(document_page_create_menu, self).default_get(fields_list)
|
||||
page_id = self.env.context.get('active_id')
|
||||
obj_page = self.env['document.page']
|
||||
page = obj_page.browse(page_id)
|
||||
res['menu_name'] = page.name
|
||||
return res
|
||||
|
||||
def document_page_menu_create(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
obj_page = self.pool.get('document.page')
|
||||
obj_menu = self.pool.get('ir.ui.menu')
|
||||
obj_action = self.pool.get('ir.actions.act_window')
|
||||
page_id = context.get('active_id', False)
|
||||
page = obj_page.browse(cr, uid, page_id, context=context)
|
||||
@api.multi
|
||||
def document_page_menu_create(self):
|
||||
obj_page = self.env['document.page']
|
||||
obj_menu = self.env['ir.ui.menu']
|
||||
obj_action = self.env['ir.actions.act_window']
|
||||
page_id = self.env.context.get('active_id', False)
|
||||
page = obj_page.browse(page_id)
|
||||
|
||||
datas = self.browse(cr, uid, ids, context=context)
|
||||
data = False
|
||||
if datas:
|
||||
data = datas[0]
|
||||
if not data:
|
||||
return {}
|
||||
data = self[0]
|
||||
value = {
|
||||
'name': 'Document Page',
|
||||
'view_type': 'form',
|
||||
@@ -74,16 +67,18 @@ class document_page_create_menu(osv.osv_memory):
|
||||
value['domain'] = "[('parent_id','=',%d)]" % (page.id)
|
||||
value['res_id'] = page.id
|
||||
|
||||
action_id = obj_action.create(cr, SUPERUSER_ID, value)
|
||||
# only the super user is allowed to create menu due to security rules
|
||||
# on ir.values
|
||||
menu_id = obj_menu.create(cr, SUPERUSER_ID, {
|
||||
# see.: http://goo.gl/Y99S7V
|
||||
action_id = obj_action.sudo().create(value)
|
||||
|
||||
menu_id = obj_menu.sudo().create({
|
||||
'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_page.write(cr, uid, [page_id], {'menu_id': menu_id})
|
||||
'action': 'ir.actions.act_window,' + str(action_id.id),
|
||||
})
|
||||
page.write({'menu_id': menu_id.id})
|
||||
return {
|
||||
'type': 'ir.actions.client',
|
||||
'tag': 'reload',
|
||||
|
||||
@@ -12,15 +12,23 @@
|
||||
<field name="menu_parent_id" />
|
||||
</group>
|
||||
<footer>
|
||||
<button name="document_page_menu_create" string="Create Menu" type="object" class="oe_highlight"/>
|
||||
<button name="document_page_menu_create"
|
||||
string="Create Menu"
|
||||
type="object"
|
||||
class="oe_highlight" />
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
<button string="Cancel"
|
||||
class="oe_link"
|
||||
special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- Create Menu Action -->
|
||||
<record id="action_wiki_create_menu" model="ir.actions.act_window">
|
||||
<record id="action_wiki_create_menu"
|
||||
model="ir.actions.act_window">
|
||||
<field name="name">Create Menu</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">document.page.create.menu</field>
|
||||
|
||||
@@ -18,46 +18,44 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
from openerp.osv import fields, osv
|
||||
from openerp.tools.translate import _
|
||||
from openerp import models, fields, _
|
||||
from openerp import exceptions
|
||||
|
||||
|
||||
class showdiff(osv.osv_memory):
|
||||
""" Disp[ay Difference for History """
|
||||
class showdiff(models.TransientModel):
|
||||
""" Display Difference for History """
|
||||
|
||||
_name = 'wizard.document.page.history.show_diff'
|
||||
|
||||
def get_diff(self, cr, uid, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
history = self.pool.get('document.page.history')
|
||||
ids = context.get('active_ids', [])
|
||||
def get_diff(self):
|
||||
history = self.env["document.page.history"]
|
||||
ids = self.env.context.get('active_ids', [])
|
||||
|
||||
diff = ""
|
||||
if len(ids) == 2:
|
||||
if ids[0] > ids[1]:
|
||||
diff = history.getDiff(cr, uid, ids[1], ids[0])
|
||||
diff = history.getDiff(ids[1], ids[0])
|
||||
else:
|
||||
diff = history.getDiff(cr, uid, ids[0], ids[1])
|
||||
|
||||
diff = history.getDiff(ids[0], ids[1])
|
||||
elif len(ids) == 1:
|
||||
old = history.browse(cr, uid, ids[0])
|
||||
nids = history.search(cr, uid, [('page_id', '=', old.page_id.id)])
|
||||
nids.sort()
|
||||
diff = history.getDiff(cr, uid, ids[0], nids[-1])
|
||||
old = history.browse(ids[0])
|
||||
nids = history.search(
|
||||
[('page_id', '=', old.page_id.id)],
|
||||
order='id DESC',
|
||||
limit=1
|
||||
)
|
||||
diff = history.getDiff(ids[0], nids.id)
|
||||
else:
|
||||
raise osv.except_osv(_('Warning!'), _('You need to select minimum \
|
||||
one or maximum two history \
|
||||
revisions!'))
|
||||
raise exceptions.Warning(
|
||||
_("You need to select minimum one or maximum "
|
||||
"two history revisions!")
|
||||
)
|
||||
return diff
|
||||
|
||||
_columns = {
|
||||
'diff': fields.text('Diff', readonly=True),
|
||||
}
|
||||
|
||||
_defaults = {
|
||||
'diff': get_diff
|
||||
}
|
||||
diff = fields.Text(
|
||||
'Diff',
|
||||
readonly=True,
|
||||
default=get_diff
|
||||
)
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
@@ -8,13 +8,19 @@
|
||||
<field name="model">wizard.document.page.history.show_diff</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Difference" version="7.0">
|
||||
<field name="diff" widget="html" options='{"safe": True}'/>
|
||||
<field name="diff"
|
||||
widget="html"
|
||||
options='{"safe": True}' />
|
||||
<footer>
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
<button string="Close"
|
||||
class="oe_link"
|
||||
special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- Create Index Action -->
|
||||
<record id="action_view_wiki_show_diff" model="ir.actions.act_window">
|
||||
<field name="name">Difference</field>
|
||||
@@ -24,8 +30,10 @@
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
|
||||
<!-- Create Index Action Window -->
|
||||
<act_window
|
||||
<act_window
|
||||
id="action_view_wiki_show_diff_values"
|
||||
key2="client_action_multi"
|
||||
name="Difference"
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRl (<http://tiny.be>).
|
||||
#
|
||||
# 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 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.
|
||||
#
|
||||
# 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 osv
|
||||
from tools.translate import _
|
||||
|
||||
|
||||
class wiki_make_index(osv.osv_memory):
|
||||
""" Create Index For Selected Page """
|
||||
|
||||
_name = "wiki.make.index"
|
||||
_description = "Create Index"
|
||||
|
||||
def wiki_do_index(self, cr, uid, ids, context=None):
|
||||
|
||||
""" 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,
|
||||
@param ids: list of wiki index’s IDs
|
||||
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
data = context and context.get('active_ids', []) or []
|
||||
|
||||
if not data:
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
for index_obj in self.browse(cr, uid, ids, context=context):
|
||||
wiki_pool = self.pool.get('wiki.wiki')
|
||||
cr.execute("Select id, section from wiki_wiki where id IN %s \
|
||||
order by section ", (tuple(data),))
|
||||
lst0 = cr.fetchall()
|
||||
if not lst0[0][1]:
|
||||
raise osv.except_osv(_('Warning!'), _('There is no section in\
|
||||
this Page.'))
|
||||
|
||||
lst = []
|
||||
s_ids = {}
|
||||
|
||||
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:
|
||||
wiki_pool.write(cr, uid, [rs[1]], {'section': rs[0]})
|
||||
|
||||
return {'type': 'ir.actions.act_window_close'}
|
||||
|
||||
wiki_make_index()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,43 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Create Index Form view -->
|
||||
|
||||
<record id="view_wiki_make_index" model="ir.ui.view">
|
||||
<field name="name">Create Index</field>
|
||||
<field name="model">wiki.make.index</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Create Menu" version="7.0">
|
||||
<separator string="Menu Information"/>
|
||||
<label string="Want to create a Index on Selected Pages ? "/>
|
||||
<footer>
|
||||
<button name="wiki_do_index" string="Create Index" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Create Index Action -->
|
||||
|
||||
<record id="action_view_wiki_make_index" model="ir.actions.act_window">
|
||||
<field name="name">Create Index</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">wiki.make.index</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
|
||||
<!-- Create Index Action Window -->
|
||||
|
||||
<act_window id="action_view_wiki_make_index_values"
|
||||
key2="client_action_multi" name="Create Index"
|
||||
res_model="wiki.make.index" src_model="wiki.wiki"
|
||||
view_mode="form" target="new" view_type="form" />
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
@@ -1,71 +0,0 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
##############################################################################
|
||||
#
|
||||
# OpenERP, Open Source Management Solution
|
||||
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
||||
#
|
||||
# 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 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.
|
||||
#
|
||||
# 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 osv
|
||||
|
||||
|
||||
class wiki_wiki_page_open(osv.osv_memory):
|
||||
""" wizard Open Page """
|
||||
|
||||
_name = "wiki.wiki.page.open"
|
||||
_description = "wiz open page"
|
||||
|
||||
def open_wiki_page(self, cr, uid, ids, context=None):
|
||||
|
||||
""" 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 page’s IDs
|
||||
@return: dictionay of open wiki window on give group id
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
group_ids = context.get('active_ids', [])
|
||||
for group in self.pool.get('wiki.groups').browse(cr, uid, group_ids,
|
||||
context=context):
|
||||
value = {
|
||||
'domain': "[('group_id','=',%d)]" % (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.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.children')])
|
||||
value['view_id'] = view_id
|
||||
value['domain'] = [('group_id', '=', group.id), ('parent_id', '=',
|
||||
False)]
|
||||
value['view_type'] = 'tree'
|
||||
|
||||
return value
|
||||
|
||||
wiki_wiki_page_open()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
@@ -1,34 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<openerp>
|
||||
<data>
|
||||
|
||||
<!-- Open Page Form view -->
|
||||
|
||||
<record id="view_wiki_wiki_page_open" model="ir.ui.view">
|
||||
<field name="name">Open Page</field>
|
||||
<field name="model">wiki.wiki.page.open</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Open Page" version="7.0">
|
||||
<label string="Want to open a wiki page? "/>
|
||||
<footer>
|
||||
<button name="open_wiki_page" string="Open Wiki Page" type="object" class="oe_highlight"/>
|
||||
or
|
||||
<button string="Cancel" class="oe_link" special="cancel" />
|
||||
</footer>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<!-- Open Page Action -->
|
||||
|
||||
<record id="action_view_wiki_wiki_page_open" model="ir.actions.act_window">
|
||||
<field name="name">Open Page</field>
|
||||
<field name="type">ir.actions.act_window</field>
|
||||
<field name="res_model">wiki.wiki.page.open</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">form</field>
|
||||
<field name="target">new</field>
|
||||
</record>
|
||||
</data>
|
||||
</openerp>
|
||||
Reference in New Issue
Block a user