mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-22 03:56:56 -06:00
use new API
This commit is contained in:
parent
910179599d
commit
fc55bca7aa
@ -20,7 +20,6 @@
|
|||||||
##############################################################################
|
##############################################################################
|
||||||
import difflib
|
import difflib
|
||||||
from openerp import models, fields, api, _
|
from openerp import models, fields, api, _
|
||||||
from openerp import exceptions
|
|
||||||
|
|
||||||
|
|
||||||
class document_page(models.Model):
|
class document_page(models.Model):
|
||||||
@ -122,26 +121,31 @@ class document_page(models.Model):
|
|||||||
if self.parent_id.type == "category":
|
if self.parent_id.type == "category":
|
||||||
self.content = self.parent_id.content
|
self.content = self.parent_id.content
|
||||||
|
|
||||||
def create_history(self, cr, uid, ids, vals, context=None):
|
def create_history(self, page_id, content):
|
||||||
for i in ids:
|
history = self.env['document.page.history']
|
||||||
history = self.pool.get('document.page.history')
|
return history.create({
|
||||||
if vals.get('content'):
|
"content": content,
|
||||||
res = {
|
"page_id": page_id
|
||||||
'content': vals.get('content', ''),
|
})
|
||||||
'page_id': i,
|
|
||||||
}
|
|
||||||
history.create(cr, uid, res)
|
|
||||||
|
|
||||||
def create(self, cr, uid, vals, context=None):
|
@api.multi
|
||||||
page_id = super(document_page, self).create(cr, uid, vals, context)
|
def write(self, vals):
|
||||||
self.create_history(cr, uid, [page_id], vals, context)
|
result = super(document_page, self).write(vals)
|
||||||
return page_id
|
content = vals.get('content')
|
||||||
|
if content:
|
||||||
def write(self, cr, uid, ids, vals, context=None):
|
for page in self:
|
||||||
result = super(document_page, self).write(cr, uid, ids, vals, context)
|
self.create_history(page.id, content)
|
||||||
self.create_history(cr, uid, ids, vals, context)
|
|
||||||
return result
|
return result
|
||||||
|
|
||||||
|
@api.model
|
||||||
|
@api.returns('self', lambda value: value.id)
|
||||||
|
def create(self, vals):
|
||||||
|
page_id = super(document_page, self).create(vals)
|
||||||
|
content = vals.get('content')
|
||||||
|
if content:
|
||||||
|
self.create_history(page_id.id, content)
|
||||||
|
return page_id
|
||||||
|
|
||||||
|
|
||||||
class document_page_history(models.Model):
|
class document_page_history(models.Model):
|
||||||
_name = "document.page.history"
|
_name = "document.page.history"
|
||||||
@ -155,19 +159,21 @@ class document_page_history(models.Model):
|
|||||||
create_date = fields.Datetime("Date")
|
create_date = fields.Datetime("Date")
|
||||||
create_uid = fields.Many2one('res.users', "Modified By")
|
create_uid = fields.Many2one('res.users', "Modified By")
|
||||||
|
|
||||||
def getDiff(self, cr, uid, v1, v2, context=None):
|
def getDiff(self, v1, v2):
|
||||||
history_pool = self.pool.get('document.page.history')
|
text1 = self.browse(v1).content
|
||||||
text1 = history_pool.read(cr, uid, [v1], ['content'])[0]['content']
|
text2 = self.browse(v2).content
|
||||||
text2 = history_pool.read(cr, uid, [v2], ['content'])[0]['content']
|
|
||||||
line1 = line2 = ''
|
line1 = line2 = ''
|
||||||
if text1:
|
if text1:
|
||||||
line1 = text1.splitlines(1)
|
line1 = text1.splitlines(1)
|
||||||
if text2:
|
if text2:
|
||||||
line2 = text2.splitlines(1)
|
line2 = text2.splitlines(1)
|
||||||
if (not line1 and not line2) or (line1 == line2):
|
if (not line1 and not line2) or (line1 == line2):
|
||||||
raise exceptions.Warning(
|
return _('There are no changes in revisions.')
|
||||||
_('There are no changes in revisions.')
|
else:
|
||||||
)
|
|
||||||
diff = difflib.HtmlDiff()
|
diff = difflib.HtmlDiff()
|
||||||
return diff.make_table(line1, line2, "Revision-%s" % (v1),
|
return diff.make_table(
|
||||||
"Revision-%s" % (v2), context=True)
|
line1, line2,
|
||||||
|
"Revision-{}".format(v1),
|
||||||
|
"Revision-{}".format(v2),
|
||||||
|
context=True
|
||||||
|
)
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
# 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
|
from openerp import SUPERUSER_ID
|
||||||
|
|
||||||
|
|
||||||
@ -38,35 +38,30 @@ class document_page_create_menu(models.TransientModel):
|
|||||||
required=True
|
required=True
|
||||||
)
|
)
|
||||||
|
|
||||||
def default_get(self, cr, uid, fields, context=None):
|
@api.model
|
||||||
if context is None:
|
def default_get(self, fields_list):
|
||||||
context = {}
|
res = super(document_page_create_menu, self).default_get(fields_list)
|
||||||
res = super(document_page_create_menu, self).default_get(
|
page_id = self.env.context.get('active_id')
|
||||||
cr, uid,
|
obj_page = self.env['document.page']
|
||||||
fields,
|
page = obj_page.browse(page_id)
|
||||||
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)
|
|
||||||
res['menu_name'] = page.name
|
res['menu_name'] = page.name
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def document_page_menu_create(self, cr, uid, ids, context=None):
|
@api.multi
|
||||||
if context is None:
|
def document_page_menu_create(self):
|
||||||
context = {}
|
# events = self.env['event.event'].browse(self._context.get('event_ids', []))
|
||||||
obj_page = self.pool.get('document.page')
|
# events.do_confirm()
|
||||||
obj_menu = self.pool.get('ir.ui.menu')
|
# return {'type': 'ir.actions.act_window_close'}
|
||||||
obj_action = self.pool.get('ir.actions.act_window')
|
# def document_page_menu_create(self, cr, uid, ids, context=None):
|
||||||
page_id = context.get('active_id', False)
|
# if context is None:
|
||||||
page = obj_page.browse(cr, uid, page_id, context=context)
|
# 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 = self[0]
|
||||||
data = False
|
|
||||||
if datas:
|
|
||||||
data = datas[0]
|
|
||||||
if not data:
|
|
||||||
return {}
|
|
||||||
value = {
|
value = {
|
||||||
'name': 'Document Page',
|
'name': 'Document Page',
|
||||||
'view_type': 'form',
|
'view_type': 'form',
|
||||||
@ -79,16 +74,18 @@ class document_page_create_menu(models.TransientModel):
|
|||||||
value['domain'] = "[('parent_id','=',%d)]" % (page.id)
|
value['domain'] = "[('parent_id','=',%d)]" % (page.id)
|
||||||
value['res_id'] = 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
|
# only the super user is allowed to create menu due to security rules
|
||||||
# on ir.values
|
# 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,
|
'name': data.menu_name,
|
||||||
'parent_id': data.menu_parent_id.id,
|
'parent_id': data.menu_parent_id.id,
|
||||||
'icon': 'STOCK_DIALOG_QUESTION',
|
'icon': 'STOCK_DIALOG_QUESTION',
|
||||||
'action': 'ir.actions.act_window,' + str(action_id),
|
'action': 'ir.actions.act_window,' + str(action_id.id),
|
||||||
}, context)
|
})
|
||||||
obj_page.write(cr, uid, [page_id], {'menu_id': menu_id})
|
page.write({'menu_id': menu_id.id})
|
||||||
return {
|
return {
|
||||||
'type': 'ir.actions.client',
|
'type': 'ir.actions.client',
|
||||||
'tag': 'reload',
|
'tag': 'reload',
|
||||||
|
@ -27,24 +27,24 @@ class showdiff(models.TransientModel):
|
|||||||
|
|
||||||
_name = 'wizard.document.page.history.show_diff'
|
_name = 'wizard.document.page.history.show_diff'
|
||||||
|
|
||||||
def get_diff(self, cr, uid, context=None):
|
def get_diff(self):
|
||||||
if context is None:
|
history = self.env["document.page.history"]
|
||||||
context = {}
|
ids = self.env.context.get('active_ids', [])
|
||||||
history = self.pool.get('document.page.history')
|
|
||||||
ids = context.get('active_ids', [])
|
|
||||||
|
|
||||||
diff = ""
|
diff = ""
|
||||||
if len(ids) == 2:
|
if len(ids) == 2:
|
||||||
if ids[0] > ids[1]:
|
if ids[0] > ids[1]:
|
||||||
diff = history.getDiff(cr, uid, ids[1], ids[0])
|
diff = history.getDiff(ids[1], ids[0])
|
||||||
else:
|
else:
|
||||||
diff = history.getDiff(cr, uid, ids[0], ids[1])
|
diff = history.getDiff(ids[0], ids[1])
|
||||||
|
|
||||||
elif len(ids) == 1:
|
elif len(ids) == 1:
|
||||||
old = history.browse(cr, uid, ids[0])
|
old = history.browse(ids[0])
|
||||||
nids = history.search(cr, uid, [('page_id', '=', old.page_id.id)])
|
nids = history.search(
|
||||||
nids.sort()
|
[('page_id', '=', old.page_id.id)],
|
||||||
diff = history.getDiff(cr, uid, ids[0], nids[-1])
|
order='id DESC',
|
||||||
|
limit=1
|
||||||
|
)
|
||||||
|
diff = history.getDiff(ids[0], nids.id)
|
||||||
else:
|
else:
|
||||||
raise exceptions.Warning(
|
raise exceptions.Warning(
|
||||||
_("You need to select minimum one or maximum "
|
_("You need to select minimum one or maximum "
|
||||||
|
@ -12,7 +12,7 @@
|
|||||||
widget="html"
|
widget="html"
|
||||||
options='{"safe": True}' />
|
options='{"safe": True}' />
|
||||||
<footer>
|
<footer>
|
||||||
<button string="Cancel"
|
<button string="Close"
|
||||||
class="oe_link"
|
class="oe_link"
|
||||||
special="cancel" />
|
special="cancel" />
|
||||||
</footer>
|
</footer>
|
||||||
|
Loading…
Reference in New Issue
Block a user