mirror of
https://github.com/OCA/knowledge.git
synced 2025-07-25 01:48:41 -06:00
document_page: fix link
This commit is contained in:
parent
9f8c2bfa06
commit
264075e351
@ -101,6 +101,17 @@ class DocumentPage(models.Model):
|
|||||||
index=True,
|
index=True,
|
||||||
ondelete='cascade',
|
ondelete='cascade',
|
||||||
)
|
)
|
||||||
|
backend_url = fields.Char(
|
||||||
|
string='Backend URL',
|
||||||
|
help='Use it to link resources univocally',
|
||||||
|
compute='_compute_backend_url',
|
||||||
|
)
|
||||||
|
|
||||||
|
@api.depends()
|
||||||
|
def _compute_backend_url(self):
|
||||||
|
tmpl = '/web#id={}&model=document.page&view_type=form'
|
||||||
|
for rec in self:
|
||||||
|
rec.backend_url = tmpl.format(rec.id)
|
||||||
|
|
||||||
@api.constrains('parent_id')
|
@api.constrains('parent_id')
|
||||||
def _check_parent_id(self):
|
def _check_parent_id(self):
|
||||||
@ -116,11 +127,12 @@ class DocumentPage(models.Model):
|
|||||||
index += ["<li>" + subpage._get_page_index() + "</li>"]
|
index += ["<li>" + subpage._get_page_index() + "</li>"]
|
||||||
r = ''
|
r = ''
|
||||||
if link:
|
if link:
|
||||||
r = '<a href="#id=%s">%s</a>' % (self.id, self.name)
|
r = '<a href="{}">{}</a>'.format(self.backend_url, self.name)
|
||||||
|
|
||||||
if index:
|
if index:
|
||||||
r += "<ul>" + "".join(index) + "</ul>"
|
r += "<ul>" + "".join(index) + "</ul>"
|
||||||
return r
|
return r
|
||||||
|
|
||||||
|
|
||||||
@api.multi
|
@api.multi
|
||||||
@api.depends('history_head')
|
@api.depends('history_head')
|
||||||
|
@ -37,3 +37,13 @@ class TestDocumentPage(common.TransactionCase):
|
|||||||
})
|
})
|
||||||
page.content = 'New content'
|
page.content = 'New content'
|
||||||
self.assertIsNotNone(page.history_ids[0].diff)
|
self.assertIsNotNone(page.history_ids[0].diff)
|
||||||
|
|
||||||
|
def test_page_link(self):
|
||||||
|
page = self.page_obj.create({
|
||||||
|
'name': 'Test Page 3',
|
||||||
|
'content': 'Test content'
|
||||||
|
})
|
||||||
|
self.assertEqual(
|
||||||
|
page.backend_url,
|
||||||
|
'/web#id={}&model=document.page&view_type=form'.format(page.id)
|
||||||
|
)
|
||||||
|
Loading…
Reference in New Issue
Block a user