From 915dc4762c678f11816fee9bc0da9ceb27ecb91a Mon Sep 17 00:00:00 2001 From: Florian Charlier Date: Wed, 29 Mar 2023 11:46:30 +0000 Subject: [PATCH] [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) --- addons/website_forum/models/forum_forum.py | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/addons/website_forum/models/forum_forum.py b/addons/website_forum/models/forum_forum.py index fda408bca6a..49654555c65 100644 --- a/addons/website_forum/models/forum_forum.py +++ b/addons/website_forum/models/forum_forum.py @@ -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):