[FIX] website_forum: be sure to have a tag name before to substract the first letter

If a tag with an empty name was existing in database, the controller /forum/forum_id/tag
return a server 500 because tag.name[0] from an empty string raise a traceback.
This commit is contained in:
Jeremy Kersten
2016-01-08 19:14:31 +01:00
parent 499c2b8da5
commit aabe0cb8fe
+2 -2
View File
@@ -174,7 +174,7 @@ class Forum(models.Model):
else:
# check if user have Karma needed to create need tag
user = User.sudo().browse(self._uid)
if user.exists() and user.karma >= self.karma_retag:
if user.exists() and user.karma >= self.karma_retag and len(tag.strip('_').strip()) > 0:
post_tags.append((0, 0, {'name': tag[1:], 'forum_id': self.id}))
else:
existing_keep.append(int(tag))
@@ -184,7 +184,7 @@ class Forum(models.Model):
def get_tags_first_char(self):
""" get set of first letter of forum tags """
tags = self.env['forum.tag'].search([('forum_id', '=', self.id), ('posts_count', '>', 0)])
return sorted(set([tag.name[0].upper() for tag in tags]))
return sorted(set([tag.name[0].upper() for tag in tags if len(tag.name)]))
class Post(models.Model):