diff options
| author | Turkesh Patel (Open ERP) <tpa@tinyerp.com> | 2014-03-18 14:31:54 +0530 |
|---|---|---|
| committer | Turkesh Patel (Open ERP) <tpa@tinyerp.com> | 2014-03-18 14:31:54 +0530 |
| commit | 3fc29404db9ec271eaae4db6b387672bfaee7b2b (patch) | |
| tree | 76d4d55976f03405fe9f33880b7eac4620cfb470 /addons | |
| parent | 63f18d4af9952609296aa5e35d86b50bd8e902f8 (diff) | |
[IMP] improved code to fix error on creating new form from contents, allow user to delete own comments, there should be only one correct answer per question.
bzr revid: tpa@tinyerp.com-20140318090154-m8e20wtosxdnqnfy
Diffstat (limited to 'addons')
| -rw-r--r-- | addons/website_forum/controllers/main.py | 20 | ||||
| -rw-r--r-- | addons/website_forum/models/website_forum.py | 7 | ||||
| -rw-r--r-- | addons/website_forum/static/src/js/website_forum.editor.js | 16 | ||||
| -rw-r--r-- | addons/website_forum/views/website_forum.xml | 7 |
4 files changed, 42 insertions, 8 deletions
diff --git a/addons/website_forum/controllers/main.py b/addons/website_forum/controllers/main.py index 64f36fc48c4..c6a828280a4 100644 --- a/addons/website_forum/controllers/main.py +++ b/addons/website_forum/controllers/main.py @@ -46,7 +46,7 @@ class website_forum(http.Controller): values = { 'forums': forums } return request.website.render("website_forum.forum_index", values) - @http.route('/forum/add_forum/', type='http', auth="user", multilang=True, methods=['POST'], website=True) + @http.route('/forum/add_forum/', type='http', auth="user", multilang=True, website=True) def add_forum(self, forum_name="New Forum", **kwargs): forum_id = request.registry['website.forum'].create(request.cr, request.uid, { 'name': forum_name, @@ -74,7 +74,9 @@ class website_forum(http.Controller): if filters == 'followed': domain += [ ('create_uid', '=', uid) ] - if sorting == 'date': + # Note: default sorting should be based on last activity + if not sorting or sorting == 'date': + sorting = 'date' order = 'write_date desc' if sorting == 'answered': order = 'child_count desc' @@ -89,6 +91,7 @@ class website_forum(http.Controller): question_ids = Forum.browse(cr, uid, obj_ids, context=context) values = { + 'uid': uid, 'total_questions': question_count, 'question_ids': question_ids, 'forum': forum, @@ -344,12 +347,17 @@ class website_forum(http.Controller): 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/<model("website.forum"):forum>/delete/question/<model("website.forum.post"):post>', 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/message_delete/', type='json', auth="user", multilang=True, methods=['POST'], website=True) + def delete_comment(self, **kwarg): + request.registry['mail.message'].unlink(request.cr, request.uid, [int(kwarg.get('message_id'))], context=request.context) + return True + @http.route('/forum/<model("website.forum"):forum>/edit/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True) def edit_question(self, forum, post, **kwarg): values = { @@ -384,6 +392,12 @@ class website_forum(http.Controller): 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 + #Note: only one answer can be right. + for child in post.parent_id.child_ids: + if child.correct: + Post.write( cr, uid, [child.id], { + 'correct': False, + }, context=context) Post.write( cr, uid, [int(kwarg.get('post_id'))], { 'correct': correct, }, context=context) diff --git a/addons/website_forum/models/website_forum.py b/addons/website_forum/models/website_forum.py index 95db9dbf125..6703a4032c7 100644 --- a/addons/website_forum/models/website_forum.py +++ b/addons/website_forum/models/website_forum.py @@ -284,6 +284,13 @@ class Badge(osv.Model): 'level': fields.selection([('bronze', 'bronze'), ('silver', 'silver'), ('gold', 'gold')], 'Forum Badge Level'), } +class MailMessage(osv.Model): + _inherit = 'mail.message' + _columns = { + 'create_uid': fields.many2one('res.users', 'Created by', readonly=True ), + } + + class Tags(osv.Model): _name = "website.forum.tag" _description = "Tag" 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 d5e459cb8a3..af006df9240 100644 --- a/addons/website_forum/static/src/js/website_forum.editor.js +++ b/addons/website_forum/static/src/js/website_forum.editor.js @@ -73,14 +73,24 @@ $(document).ready(function () { openerp.jsonRpc("/forum/correct_answer/", 'call', { 'post_id': $link.attr("id")}) .then(function (data) { + par = $link.parents().find(".oe_answer_true") + $link.parents().find(".oe_answer_true").removeClass("oe_answer_true").addClass('oe_answer_false') if (data) { $link.removeClass("oe_answer_false").addClass('oe_answer_true'); } - else { - $link.removeClass("oe_answer_true").addClass('oe_answer_false'); - } }); return false; }); + $('.comment_delete').on('click', function (ev) { + ev.preventDefault(); + var $link = $(ev.currentTarget); + openerp.jsonRpc("/forum/message_delete/", 'call', { + 'message_id': $link.attr("id")}) + .then(function (data) { + $link.parents('#comment').remove(); + }); + 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 1b802de9aba..b568bbc087f 100644 --- a/addons/website_forum/views/website_forum.xml +++ b/addons/website_forum/views/website_forum.xml @@ -416,10 +416,13 @@ <template id="comments"> <div class="row clearfix"> <div class="col-sm-10 col-sm-offset-2"> - <div t-foreach="reversed(object.website_message_ids)" t-as="message" class="oe_grey" style="padding: 4px;"> + <div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_grey" style="padding: 4px;"> <small class="text-muted"> + <t t-if="uid == message.create_uid.id"> + <button type="button" t-att-id="message.id" class="close comment_delete">&times;</button> + </t> <div t-field="message.body"/> - <a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.author_id.id }" t-field="message.author_id"/> + <a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.create_uid.id }" t-field="message.create_uid"/> on <span t-field="message.date" t-field-options='{"format":"short"}'/> </small> </div> |
