[REF] website_forum: simplify _compute_teaser

textwrap does the ellision and we don't need to replace newlines characters.
It is done for us already (except that multiple newlines will be replaced by
a single space).

closes odoo/odoo#116778

Signed-off-by: Thibault Delavallee (tde) <tde@openerp.com>
This commit is contained in:
Florian Charlier
2023-03-29 23:37:00 +02:00
committed by Thibault Delavallée
parent 1d2057806b
commit 915dc4762c
+3 -8
View File
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-
# Part of Odoo. See LICENSE file for full copyright and licensing details.
import textwrap
from odoo import _, api, fields, models
from odoo.tools.translate import html_translate
from odoo.addons.http_routing.models.ir_http import slug
@@ -132,14 +134,7 @@ class Forum(models.Model):
@api.depends('description')
def _compute_teaser(self):
for forum in self:
if forum.description:
desc = forum.description.replace('\n', ' ')
if len(forum.description) > 180:
forum.teaser = desc[:180] + '...'
else:
forum.teaser = forum.description
else:
forum.teaser = ""
forum.teaser = textwrap.shorten(forum.description, width=180, placeholder='...') if forum.description else ""
@api.depends('post_ids')
def _compute_last_post_id(self):