[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
This commit is contained in:
parent
63f18d4af9
commit
3fc29404db
|
@ -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)
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
|
||||
});
|
|
@ -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>
|
||||
|
|
Loading…
Reference in New Issue