mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-21 19:47:24 -06:00
use new API
This commit is contained in:
parent
910179599d
commit
fc55bca7aa
@ -20,7 +20,6 @@
|
||||
##############################################################################
|
||||
import difflib
|
||||
from openerp import models, fields, api, _
|
||||
from openerp import exceptions
|
||||
|
||||
|
||||
class document_page(models.Model):
|
||||
@ -122,26 +121,31 @@ class document_page(models.Model):
|
||||
if self.parent_id.type == "category":
|
||||
self.content = self.parent_id.content
|
||||
|
||||
def create_history(self, cr, uid, ids, vals, context=None):
|
||||
for i in ids:
|
||||
history = self.pool.get('document.page.history')
|
||||
if vals.get('content'):
|
||||
res = {
|
||||
'content': vals.get('content', ''),
|
||||
'page_id': i,
|
||||
}
|
||||
history.create(cr, uid, res)
|
||||
def create_history(self, page_id, content):
|
||||
history = self.env['document.page.history']
|
||||
return history.create({
|
||||
"content": content,
|
||||
"page_id": page_id
|
||||
})
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
page_id = super(document_page, self).create(cr, uid, vals, context)
|
||||
self.create_history(cr, uid, [page_id], vals, context)
|
||||
return page_id
|
||||
|
||||
def write(self, cr, uid, ids, vals, context=None):
|
||||
result = super(document_page, self).write(cr, uid, ids, vals, context)
|
||||
self.create_history(cr, uid, ids, vals, context)
|
||||
@api.multi
|
||||
def write(self, vals):
|
||||
result = super(document_page, self).write(vals)
|
||||
content = vals.get('content')
|
||||
if content:
|
||||
for page in self:
|
||||
self.create_history(page.id, content)
|
||||
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):
|
||||
_name = "document.page.history"
|
||||
@ -155,19 +159,21 @@ class document_page_history(models.Model):
|
||||
create_date = fields.Datetime("Date")
|
||||
create_uid = fields.Many2one('res.users', "Modified By")
|
||||
|
||||
def getDiff(self, cr, uid, v1, v2, context=None):
|
||||
history_pool = self.pool.get('document.page.history')
|
||||
text1 = history_pool.read(cr, uid, [v1], ['content'])[0]['content']
|
||||
text2 = history_pool.read(cr, uid, [v2], ['content'])[0]['content']
|
||||
def getDiff(self, v1, v2):
|
||||
text1 = self.browse(v1).content
|
||||
text2 = self.browse(v2).content
|
||||
line1 = line2 = ''
|
||||
if text1:
|
||||
line1 = text1.splitlines(1)
|
||||
if text2:
|
||||
line2 = text2.splitlines(1)
|
||||
if (not line1 and not line2) or (line1 == line2):
|
||||
raise exceptions.Warning(
|
||||
_('There are no changes in revisions.')
|
||||
return _('There are no changes in revisions.')
|
||||
else:
|
||||
diff = difflib.HtmlDiff()
|
||||
return diff.make_table(
|
||||
line1, line2,
|
||||
"Revision-{}".format(v1),
|
||||
"Revision-{}".format(v2),
|
||||
context=True
|
||||
)
|
||||
diff = difflib.HtmlDiff()
|
||||
return diff.make_table(line1, line2, "Revision-%s" % (v1),
|
||||
"Revision-%s" % (v2), context=True)
|
||||
|
@ -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>
|
||||
|
Loading…
Reference in New Issue
Block a user