diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 68be85daf1b..ae581a3b4c6 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -334,3 +334,52 @@ class website_forum(http.Controller): cr, uid, context, post_id = request.cr, request.uid, request.context, int(post.get('post_id')) Vote = request.registry['website.forum.post.vote'] return Vote.vote(cr, uid, post_id, post.get('vote'), context) + + @http.route('/forum/post_delete/', type='json', auth="user", multilang=True, methods=['POST'], website=True) + def delete_answer(self, **kwarg): + request.registry['website.forum.post'].unlink(request.cr, request.uid, [int(kwarg.get('post_id'))], context=request.context) + return True + + @http.route('/forum//delete/question/', type='http', auth="user", multilang=True, website=True) + def delete_question(self, forum, post, **kwarg): + request.registry['website.forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context) + return werkzeug.utils.redirect("/forum/%s/" % (slug(forum))) + + @http.route('/forum//edit/question/', type='http', auth="user", multilang=True, website=True) + def edit_question(self, forum, post, **kwarg): + values = { + 'post': post, + 'forum': forum, + 'searches': kwarg + } + return request.website.render("website_forum.edit_question", values) + + @http.route('/forum//question/savequestion/', type='http', auth="user", multilang=True, methods=['POST'], website=True) + def save_edited_question(self, forum, **post): + request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], { + 'content': post.get('answer_content'), + 'name': post.get('question_name'), + }, context=request.context) + return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id'))) + + @http.route('/forum//answer//edit/', type='http', auth="user", multilang=True, website=True) + def edit_ans(self, forum, post, answer, **kwarg): + values = { + 'post': post, + 'post_answer': answer, + 'forum': forum, + 'searches': kwarg + } + return request.website.render("website_forum.edit_answer", values) + + @http.route('/forum/correct_answer/', type='json', auth="user", multilang=True, methods=['POST'], website=True) + def correct_answer(self, **kwarg): + cr, uid, context = request.cr, request.uid, request.context + Post = request.registry['website.forum.post'] + post = Post.browse(cr, uid, int(kwarg.get('post_id')), context=context) + if post.create_uid.id == uid: + correct = False if post.correct else True + Post.write( cr, uid, [int(kwarg.get('post_id'))], { + 'correct': correct, + }, context=context) + return correct diff --git a/addons/website_forum/models/website_forum.py b/addons/website_forum/models/website_forum.py index f7d58407090..95db9dbf125 100644 --- a/addons/website_forum/models/website_forum.py +++ b/addons/website_forum/models/website_forum.py @@ -118,7 +118,7 @@ class Post(osv.Model): 'active': fields.boolean('Active'), 'views': fields.integer('Page Views'), - 'parent_id': fields.many2one('website.forum.post', 'Question'), + 'parent_id': fields.many2one('website.forum.post', 'Question', ondelete='cascade'), 'child_ids': fields.one2many('website.forum.post', 'parent_id', 'Answers'), 'child_count':fields.function(_get_child_count, string="Answers", type='integer', store={ @@ -150,6 +150,7 @@ class Post(osv.Model): 'website.forum.post.vote': (_get_vote, [], 10), } ), + 'correct': fields.boolean('Correct Answer'), } _defaults = { 'state': 'active', @@ -173,10 +174,13 @@ class Post(osv.Model): if context is None: context = {} create_context = dict(context, mail_create_nolog=True) - post_id = super(Post, self).create(cr, uid, vals, context=create_context) body, subtype = "Asked a question", "website_forum.mt_question_create" if vals.get("parent_id"): body, subtype = "Answered a question", "website_forum.mt_answer_create" + #Note: because of no name it gives error on slug so set name of question in answer + question = self.browse(cr, uid, vals.get("parent_id"), context=context) + vals['name'] = question.name + post_id = super(Post, self).create(cr, uid, vals, context=create_context) #Note: just have to pass subtype in message post: gives error on installation time self.message_post(cr, uid, [post_id], body=_(body), context=context) return post_id diff --git a/addons/website_forum/static/src/css/website_forum.css b/addons/website_forum/static/src/css/website_forum.css index 26fee8e1f10..b88ab71619b 100644 --- a/addons/website_forum/static/src/css/website_forum.css +++ b/addons/website_forum/static/src/css/website_forum.css @@ -36,3 +36,11 @@ .badge-bronze { color: #eea91e; } + +.oe_answer_true { + color: #428bca; +} + +.oe_answer_false { + color: #999 +} diff --git a/addons/website_forum/static/src/js/website_forum.editor.js b/addons/website_forum/static/src/js/website_forum.editor.js index b79b0d4df37..d5e459cb8a3 100644 --- a/addons/website_forum/static/src/js/website_forum.editor.js +++ b/addons/website_forum/static/src/js/website_forum.editor.js @@ -55,4 +55,32 @@ $(document).ready(function () { }); return false; }); + + $('.delete').on('click', function (ev) { + ev.preventDefault(); + var $link = $(ev.currentTarget); + openerp.jsonRpc("/forum/post_delete/", 'call', { + 'post_id': $link.attr("id")}) + .then(function (data) { + $link.parents('#answer').remove(); + }); + return false; + }); + + $('.fa-check').on('click', function (ev) { + ev.preventDefault(); + var $link = $(ev.currentTarget); + openerp.jsonRpc("/forum/correct_answer/", 'call', { + 'post_id': $link.attr("id")}) + .then(function (data) { + if (data) { + $link.removeClass("oe_answer_false").addClass('oe_answer_true'); + } + else { + $link.removeClass("oe_answer_true").addClass('oe_answer_false'); + } + }); + return false; + }); + }); \ No newline at end of file diff --git a/addons/website_forum/views/website_forum.xml b/addons/website_forum/views/website_forum.xml index 7637374268e..7cf3c4febaa 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -285,6 +285,26 @@ + +