mirror of
https://github.com/OCA/knowledge.git
synced 2025-12-22 13:22:19 -06:00
use new API
This commit is contained in:
@@ -18,7 +18,7 @@
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
from openerp import models, fields
|
||||
from openerp import models, fields, api
|
||||
from openerp import SUPERUSER_ID
|
||||
|
||||
|
||||
@@ -38,35 +38,30 @@ class document_page_create_menu(models.TransientModel):
|
||||
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)
|
||||
@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):
|
||||
# events = self.env['event.event'].browse(self._context.get('event_ids', []))
|
||||
# events.do_confirm()
|
||||
# return {'type': 'ir.actions.act_window_close'}
|
||||
# def document_page_menu_create(self, cr, uid, ids, context=None):
|
||||
# if context is None:
|
||||
# context = {}
|
||||
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',
|
||||
@@ -79,16 +74,18 @@ class document_page_create_menu(models.TransientModel):
|
||||
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',
|
||||
|
||||
@@ -27,24 +27,24 @@ class showdiff(models.TransientModel):
|
||||
|
||||
_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 exceptions.Warning(
|
||||
_("You need to select minimum one or maximum "
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
widget="html"
|
||||
options='{"safe": True}' />
|
||||
<footer>
|
||||
<button string="Cancel"
|
||||
<button string="Close"
|
||||
class="oe_link"
|
||||
special="cancel" />
|
||||
</footer>
|
||||
|
||||
Reference in New Issue
Block a user