Skip to content

Commit

Permalink
[FIX] website_forum: Forum, use old API in v8. forum was not a browse…
Browse files Browse the repository at this point in the history
… 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.
  • Loading branch information
JKE-be committed Nov 26, 2014
1 parent 2b0a836 commit 0313218
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 19 deletions.
10 changes: 6 additions & 4 deletions addons/website_forum/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,7 @@ def question_ask(self, forum, **post):
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
Expand All @@ -223,14 +224,14 @@ def question_create(self, forum, **post):
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))

Expand Down Expand Up @@ -400,6 +401,7 @@ def post_save(self, forum, post, **kwargs):
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('[]'):
Expand All @@ -413,10 +415,10 @@ def post_save(self, forum, post, **kwargs):
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'),
}
Expand Down
36 changes: 21 additions & 15 deletions addons/website_forum/models/forum.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,24 +119,30 @@ def create(self, cr, uid, values, context=None):
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']
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])))
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 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:
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 >= forum.karma_retag:
post_tags.append((0, 0, {'name': tag[1:], 'forum_id': forum.id}))
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
existing_keep.append(int(tag))
post_tags.insert(0, [6, 0, existing_keep])
result[forum.id] = post_tags

return result


class Post(osv.Model):
Expand Down

0 comments on commit 0313218

Please sign in to comment.