From f8c2d840243ac1c6bc9cdb2a65934e6adf3563c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Thu, 9 Mar 2023 16:21:54 +0000 Subject: [PATCH] [FIX] website_forum: better string manipulation for tags A strange manipulation is performed when trying to create tags. In this commit we simply make styling happy by trying to first prepare data (strip, content) then use it. Feature is untouched currently. Task-3240082 (Forum: Reorganize and lint module) Part-of: odoo/odoo#114841 --- addons/website_forum/models/forum_forum.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/addons/website_forum/models/forum_forum.py b/addons/website_forum/models/forum_forum.py index bed3662483d..ff5828a6e5d 100644 --- a/addons/website_forum/models/forum_forum.py +++ b/addons/website_forum/models/forum_forum.py @@ -233,18 +233,19 @@ class Forum(models.Model): post_tags = [] existing_keep = [] user = self.env.user - for tag in (tag for tag in tags.split(',') if tag): - if tag.startswith('_'): # it's a new tag + for tag_id_or_new_name in (tag.strip() for tag in tags.split(',') if tag and tag.strip()): + if tag_id_or_new_name.startswith('_'): # it's a new tag + tag_name = tag_id_or_new_name[1:] # check that not already created meanwhile or maybe excluded by the limit on the search - tag_ids = Tag.search([('name', '=', tag[1:]), ('forum_id', '=', self.id)]) + tag_ids = Tag.search([('name', '=', tag_name), ('forum_id', '=', self.id)], limit=1) if tag_ids: - existing_keep.append(int(tag_ids[0])) + existing_keep.append(tag_ids.id) else: # check if user have Karma needed to create need tag - if user.exists() and user.karma >= self.karma_tag_create and len(tag) and len(tag[1:].strip()): - post_tags.append((0, 0, {'name': tag[1:], 'forum_id': self.id})) + if user.exists() and user.karma >= self.karma_tag_create and tag_name: + post_tags.append((0, 0, {'name': tag_name, 'forum_id': self.id})) else: - existing_keep.append(int(tag)) + existing_keep.append(int(tag_id_or_new_name)) post_tags.insert(0, [6, 0, existing_keep]) return post_tags