[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
This commit is contained in:
Thibault Delavallée
2023-03-22 17:03:24 +01:00
parent 112622db70
commit f8c2d84024
+8 -7
View File
@@ -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