[FIX] website_forum: fix post/forum website URL computation on memory records
'slug' cannot be called on records which are not yet saved, aka have no ID. In this commit we set the website_url to False for records that do not have any ID. Code managing those URLs is updated to be defensive, as notably when using studio you may end up trying to call methods on in-memory records. Followup of odoo/odoo@da3f4c2aff Task-3254382 closes odoo/odoo#117255 X-original-commit: 36c734ab37fdf1d6a245e0e29cfefe3cc46c6d92 Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
@@ -181,7 +181,9 @@ class Forum(models.Model):
|
||||
# EXTENDS WEBSITE.MULTI.MIXIN
|
||||
|
||||
def _compute_website_url(self):
|
||||
return '/forum/%s' % (slug(self))
|
||||
if not self.id:
|
||||
return False
|
||||
return f'/forum/{slug(self)}'
|
||||
|
||||
# ----------------------------------------------------------------------
|
||||
# CRUD
|
||||
@@ -261,6 +263,9 @@ class Forum(models.Model):
|
||||
|
||||
def go_to_website(self):
|
||||
self.ensure_one()
|
||||
website_url = self._compute_website_url
|
||||
if not website_url:
|
||||
return False
|
||||
return self.env['website'].get_client_action(self._compute_website_url())
|
||||
|
||||
@api.model
|
||||
|
||||
@@ -172,8 +172,9 @@ class Post(models.Model):
|
||||
|
||||
@api.depends('name')
|
||||
def _compute_website_url(self):
|
||||
for post in self:
|
||||
anchor = post.parent_id and '#answer_%d' % post.id or ''
|
||||
self.website_url = False
|
||||
for post in self.filtered(lambda post: post.id):
|
||||
anchor = f'#answer_{post.id}' if post.parent_id else ''
|
||||
post.website_url = f'/forum/{slug(post.forum_id)}/{slug(post)}{anchor}'
|
||||
|
||||
@api.depends('vote_count', 'forum_id.relevancy_post_vote', 'forum_id.relevancy_time_decay')
|
||||
@@ -793,6 +794,8 @@ class Post(models.Model):
|
||||
|
||||
def go_to_website(self):
|
||||
self.ensure_one()
|
||||
if not self.website_url:
|
||||
return False
|
||||
return self.env['website'].get_client_action(self.website_url)
|
||||
|
||||
@api.model
|
||||
|
||||
Reference in New Issue
Block a user