[FIX] website_forum: use common method to compute tags for orm
This commit is contained in:
@@ -223,12 +223,7 @@ class WebsiteForum(http.Controller):
|
||||
else:
|
||||
question_tag_ids.append((0, 0, {'name': tag, 'forum_id': forum.id}))
|
||||
elif tag_version == "select2":
|
||||
tags = filter(None, post.get('question_tags', '').split(','))
|
||||
for tag in tags:
|
||||
if tag.startswith('_'): # it's a new tag
|
||||
question_tag_ids.append((0, 0, {'name': tag[1:], 'forum_id': forum.id}))
|
||||
else:
|
||||
question_tag_ids.append((4, int(tag)))
|
||||
question_tag_ids = forum._tag_to_write_vals(cr, uid, post.get('question_tags', ''), context=context)
|
||||
|
||||
new_question_id = request.registry['forum.post'].create(
|
||||
request.cr, request.uid, {
|
||||
@@ -404,7 +399,6 @@ class WebsiteForum(http.Controller):
|
||||
def post_save(self, forum, post, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
question_tags = []
|
||||
User = request.registry['res.users']
|
||||
Tag = request.registry['forum.tag']
|
||||
tag_version = kwargs.get('tag_type', 'texttext')
|
||||
if tag_version == "texttext": # old version - retro v8 - #TODO Remove in master
|
||||
@@ -417,24 +411,12 @@ class WebsiteForum(http.Controller):
|
||||
else:
|
||||
new_tag = Tag.create(cr, uid, {'name': tag, 'forum_id': forum.id}, context=context)
|
||||
question_tags.append(new_tag)
|
||||
tags_val = [(6, 0, question_tags)]
|
||||
elif tag_version == "select2": # new version
|
||||
for tag in filter(None, kwargs.get('question_tag', '').split(',')):
|
||||
if tag.startswith('_'): # it's a new tag
|
||||
# check if user have Karma needed to create need tag
|
||||
user = User.browse(cr, SUPERUSER_ID, uid, context=context)
|
||||
if user.exists() and user.karma >= forum.karma_retag:
|
||||
# check that not arleady created meanwhile and maybe excluded by the limit on the search
|
||||
tag_ids = Tag.search(cr, uid, [('name', '=', tag[1:])], context=context)
|
||||
if tag_ids:
|
||||
new_tag = tag_ids
|
||||
else:
|
||||
new_tag = Tag.create(cr, uid, {'name': tag[1:], 'forum_id': forum.id}, context=context)
|
||||
question_tags.append(new_tag)
|
||||
else:
|
||||
question_tags += [int(tag)]
|
||||
tags_val = forum._tag_to_write_vals(cr, uid, kwargs.get('question_tag', ''), context=context)
|
||||
|
||||
vals = {
|
||||
'tag_ids': [(6, 0, question_tags)],
|
||||
'tag_ids': tags_val,
|
||||
'name': kwargs.get('question_name'),
|
||||
'content': kwargs.get('content'),
|
||||
}
|
||||
|
||||
@@ -119,6 +119,25 @@ class Forum(osv.Model):
|
||||
create_context = dict(context, mail_create_nolog=True)
|
||||
return super(Forum, self).create(cr, uid, values, context=create_context)
|
||||
|
||||
def _tag_to_write_vals(self, cr, uid, tags='', context=None):
|
||||
User = self.pool['res.users']
|
||||
Tag = self.pool['forum.tag']
|
||||
post_tags = []
|
||||
for tag in filter(None, tags.split(',')):
|
||||
if tag.startswith('_'): # it's a new tag
|
||||
# check that not arleady created meanwhile or maybe excluded by the limit on the search
|
||||
tag_ids = Tag.search(cr, uid, [('name', '=', tag[1:])], context=context)
|
||||
if tag_ids:
|
||||
post_tags.append((4, int(tag_ids[0])))
|
||||
else:
|
||||
# check if user have Karma needed to create need tag
|
||||
user = User.browse(cr, uid, uid, context=context)
|
||||
if user.exists() and user.karma >= self.karma_retag:
|
||||
post_tags.append((0, 0, {'name': tag[1:], 'forum_id': self.id}))
|
||||
else:
|
||||
post_tags.append((4, int(tag)))
|
||||
return post_tags
|
||||
|
||||
|
||||
class Post(osv.Model):
|
||||
_name = 'forum.post'
|
||||
|
||||
Reference in New Issue
Block a user