[FIX] website_forum: Forum, use old API in v8. forum was not a browse record, so we need to re-browse. Tags: Force to delete tag. Before old tag deleted was not removed from relation, Now we use a 6 to force the update, followed by 0 to create.
This commit is contained in:
parent
2b0a8363d9
commit
0313218123
|
@ -211,6 +211,7 @@ class WebsiteForum(http.Controller):
|
|||
def question_create(self, forum, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
Tag = request.registry['forum.tag']
|
||||
Forum = request.registry['forum.forum']
|
||||
question_tag_ids = []
|
||||
tag_version = post.get('tag_type', 'texttext')
|
||||
if tag_version == "texttext": # TODO Remove in master
|
||||
|
@ -223,14 +224,14 @@ class WebsiteForum(http.Controller):
|
|||
else:
|
||||
question_tag_ids.append((0, 0, {'name': tag, 'forum_id': forum.id}))
|
||||
elif tag_version == "select2":
|
||||
question_tag_ids = forum._tag_to_write_vals(post.get('question_tags', ''))
|
||||
question_tag_ids = Forum._tag_to_write_vals(cr, uid, [forum.id], post.get('question_tags', ''), context)
|
||||
|
||||
new_question_id = request.registry['forum.post'].create(
|
||||
request.cr, request.uid, {
|
||||
'forum_id': forum.id,
|
||||
'name': post.get('question_name'),
|
||||
'content': post.get('content'),
|
||||
'tag_ids': question_tag_ids,
|
||||
'tag_ids': question_tag_ids[forum.id],
|
||||
}, context=context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum), new_question_id))
|
||||
|
||||
|
@ -400,6 +401,7 @@ class WebsiteForum(http.Controller):
|
|||
cr, uid, context = request.cr, request.uid, request.context
|
||||
question_tags = []
|
||||
Tag = request.registry['forum.tag']
|
||||
Forum = request.registry['forum.forum']
|
||||
tag_version = kwargs.get('tag_type', 'texttext')
|
||||
if tag_version == "texttext": # old version - retro v8 - #TODO Remove in master
|
||||
if kwargs.get('question_tag') and kwargs.get('question_tag').strip('[]'):
|
||||
|
@ -413,10 +415,10 @@ class WebsiteForum(http.Controller):
|
|||
question_tags.append(new_tag)
|
||||
tags_val = [(6, 0, question_tags)]
|
||||
elif tag_version == "select2": # new version
|
||||
tags_val = forum._tag_to_write_vals(kwargs.get('question_tag', ''))
|
||||
tags_val = Forum._tag_to_write_vals(cr, uid, [forum.id], kwargs.get('question_tag', ''), context)
|
||||
|
||||
vals = {
|
||||
'tag_ids': tags_val,
|
||||
'tag_ids': tags_val[forum.id],
|
||||
'name': kwargs.get('question_name'),
|
||||
'content': kwargs.get('content'),
|
||||
}
|
||||
|
|
|
@ -119,24 +119,30 @@ 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):
|
||||
def _tag_to_write_vals(self, cr, uid, ids, tags='', context=None):
|
||||
User = self.pool['res.users']
|
||||
Tag = self.pool['forum.tag']
|
||||
result = {}
|
||||
for forum in self.browse(cr, uid, ids, context=context):
|
||||
post_tags = []
|
||||
existing_keep = []
|
||||
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
|
||||
# check that not already 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])))
|
||||
existing_keep.append(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}))
|
||||
if user.exists() and user.karma >= forum.karma_retag:
|
||||
post_tags.append((0, 0, {'name': tag[1:], 'forum_id': forum.id}))
|
||||
else:
|
||||
post_tags.append((4, int(tag)))
|
||||
return post_tags
|
||||
existing_keep.append(int(tag))
|
||||
post_tags.insert(0, [6, 0, existing_keep])
|
||||
result[forum.id] = post_tags
|
||||
|
||||
return result
|
||||
|
||||
|
||||
class Post(osv.Model):
|
||||
|
|
Loading…
Reference in New Issue