[IMP] improved code for delete question: instead of unlink just update active so user can undelete it.
bzr revid: tpa@tinyerp.com-20140324060650-q8xtujw35i7933ba
This commit is contained in:
parent
224bc24310
commit
546ad55636
|
@ -187,7 +187,8 @@ class website_forum(http.Controller):
|
|||
Data = request.registry["ir.model.data"]
|
||||
|
||||
#questions asked by user.
|
||||
question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id), ('parent_id', '=', False)], context=context)
|
||||
question_ids = Post.search(cr, uid, [('forum_id', '=', forum.id), ('user_id', '=', user.id), ('parent_id', '=', False),
|
||||
'|', ('active', '=', False), ('active', '=', True)], context=context)
|
||||
user_questions = Post.browse(cr, uid, question_ids, context=context)
|
||||
|
||||
#showing questions in which user answered
|
||||
|
@ -391,8 +392,18 @@ class website_forum(http.Controller):
|
|||
|
||||
@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)))
|
||||
#instead of unlink record just change 'active' to false so user can undelete it.
|
||||
request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], {
|
||||
'active': False,
|
||||
}, context=request.context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/undelete/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
||||
def undelete_question(self, forum, post, **kwarg):
|
||||
request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], {
|
||||
'active': True,
|
||||
}, context=request.context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
||||
|
||||
@http.route('/forum/message_delete/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def delete_comment(self, **kwarg):
|
||||
|
@ -441,7 +452,7 @@ class website_forum(http.Controller):
|
|||
Post.write( cr, uid, [child.id], {
|
||||
'correct': False,
|
||||
}, context=context)
|
||||
Post.write( cr, uid, [int(kwarg.get('post_id'))], {
|
||||
Post.write( cr, uid, [post.id, post.parent_id.id], {
|
||||
'correct': correct,
|
||||
}, context=context)
|
||||
return correct
|
||||
|
@ -470,7 +481,7 @@ class website_forum(http.Controller):
|
|||
return request.website.render("website_forum.close_question", values)
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/question/close/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def save_edited_question(self, forum, **post):
|
||||
def close(self, forum, **post):
|
||||
request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], {
|
||||
'state': 'close',
|
||||
'closed_by': request.uid,
|
||||
|
@ -479,6 +490,13 @@ class website_forum(http.Controller):
|
|||
}, context=request.context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id')))
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/reopen/question/<model("website.forum.post"):post>', type='http', auth="user", multilang=True, website=True)
|
||||
def reopen(self, forum, post, **kwarg):
|
||||
request.registry['website.forum.post'].write( request.cr, request.uid, [post.id], {
|
||||
'state': 'active',
|
||||
}, context=request.context)
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
|
||||
|
||||
@http.route('/forum/<model("website.forum"):forum>/edit/profile/<model("res.users"):user>', type='http', auth="user", multilang=True, website=True)
|
||||
def edit_profile(self, forum, user, **kwarg):
|
||||
cr,context = request.cr, request.context
|
||||
|
|
|
@ -145,16 +145,13 @@
|
|||
<field name="level">gold</field>
|
||||
</record>
|
||||
|
||||
<!--TODO: need to some what on post that on delete it should not delete from db,
|
||||
it should shange boolean field?. at this time we are showing post with 3 vote(not deleted)
|
||||
-->
|
||||
<record model="gamification.goal.definition" id="definition_disciplined">
|
||||
<field name="name">Discipline</field>
|
||||
<field name="description">Delete own post with 3 or more upvotes</field>
|
||||
<field name="computation_mode">count</field>
|
||||
<field name="display_mode">boolean</field>
|
||||
<field name="model_id" eval="ref('website_forum.model_website_forum_post')" />
|
||||
<field name="domain">[('user_id','=',user.id), ('vote_count', '>=', 3)]</field>
|
||||
<field name="domain">[('user_id','=',user.id), ('vote_count', '>=', 3), ('active', '=', False)]</field>
|
||||
<field name="condition">higher</field>
|
||||
</record>
|
||||
|
||||
|
@ -364,7 +361,6 @@ result = get_counter(cr, uid, context=context)
|
|||
<field name="level">silver</field>
|
||||
</record>
|
||||
|
||||
<!--NOTE: passing default value 1 for res forumwise it gives error in gamification, will improve in gamification -->
|
||||
<record model="gamification.goal.definition" id="definition_favorite_question">
|
||||
<field name="name">Favorite Question</field>
|
||||
<field name="description">Ask a question which can be favorited by minimum 5 users</field>
|
||||
|
@ -747,16 +743,13 @@ result = get_posts(cr, uid, context=context)
|
|||
<field name="level">gold</field>
|
||||
</record>
|
||||
|
||||
<!--TODO: need to some what on post that on delete it should not delete from db,
|
||||
it should shange boolean field?. at this time we are showing post with 3 down vote(not deleted)
|
||||
-->
|
||||
<record model="gamification.goal.definition" id="definition_peer_pressure">
|
||||
<field name="name">Peer Pressure</field>
|
||||
<field name="description">Delete own post with 3 or more down votes</field>
|
||||
<field name="computation_mode">count</field>
|
||||
<field name="display_mode">boolean</field>
|
||||
<field name="model_id" eval="ref('website_forum.model_website_forum_post')" />
|
||||
<field name="domain">[('user_id','=',user.id), ('vote_count', '<=', -3)]</field>
|
||||
<field name="domain">[('user_id','=',user.id), ('vote_count', '<=', -3), ('active', '=', False)]</field>
|
||||
<field name="condition">higher</field>
|
||||
</record>
|
||||
|
||||
|
@ -861,7 +854,6 @@ result = get_count(cr, uid, context=context)
|
|||
<field name="level">gold</field>
|
||||
</record>
|
||||
|
||||
<!--TODO: add field to show closed state of question or update correct on quetion when any answer accepted.-->
|
||||
<record model="gamification.goal.definition" id="definition_scholar">
|
||||
<field name="name">Scholar</field>
|
||||
<field name="description">Ask a question and accept an answer</field>
|
||||
|
@ -932,7 +924,6 @@ result = get_count(cr, uid, context=context)
|
|||
<field name="level">bronze</field>
|
||||
</record>
|
||||
|
||||
<!--NOTE: passing default value 1 for res forumwise it gives error in gamification, will improve in gamification -->
|
||||
<record model="gamification.goal.definition" id="definition_stellar_question">
|
||||
<field name="name">Stellar Question</field>
|
||||
<field name="description">Ask a question which can be favorited by minimum 25 users</field>
|
||||
|
|
|
@ -151,7 +151,7 @@ class Post(osv.Model):
|
|||
}
|
||||
),
|
||||
|
||||
'correct': fields.boolean('Correct Answer'),
|
||||
'correct': fields.boolean('Correct Answer/ Answer on this question accepted.'),
|
||||
'reason': fields.selection([
|
||||
('duplicate', 'duplicate question'),
|
||||
('off_topic', 'question is off-topic or not relevant'),
|
||||
|
|
|
@ -47,6 +47,8 @@
|
|||
<div style="margin-left: 95px;">
|
||||
<div class="question-name">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(question) }" t-field="question.name"/>
|
||||
<span t-if="not question.active"><b> [Deleted]</b></span>
|
||||
<span t-if="question.state == 'close'"><b> [Closed]</b></span>
|
||||
</div>
|
||||
<div class="text-muted">
|
||||
by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ question.user_id.id }" t-field="question.user_id"/>,
|
||||
|
@ -335,7 +337,7 @@
|
|||
<template id="post_description_full" name="Question Navigation">
|
||||
<t t-call="website_forum.header">
|
||||
|
||||
<div class="question">
|
||||
<div t-attf-class="question #{not question.active and 'alert alert-danger' or ''}">
|
||||
<div class="text-center pull-left" id="post_vote">
|
||||
<div t-attf-class="box oe_grey">
|
||||
<a t-attf-class="fa fa-thumbs-up #{question.user_vote == 1 and 'text-success' or ''}"
|
||||
|
@ -354,7 +356,11 @@
|
|||
</div>
|
||||
</div>
|
||||
<div style="margin-left: 95px;">
|
||||
<h1 t-field="question.name" class="mt0"/>
|
||||
<h1 class="mt0">
|
||||
<span t-field="question.name"/>
|
||||
<span t-if="not question.active"><b> [Deleted]</b></span>
|
||||
<span t-if="question.state == 'close'"><b> [Closed]</b></span>
|
||||
</h1>
|
||||
<t t-raw="question.content"/>
|
||||
|
||||
<div class="mt16 clearfix">
|
||||
|
@ -371,9 +377,16 @@
|
|||
comment
|
||||
</a>
|
||||
</li>
|
||||
<li><a class="text-muted fa fa-times" t-attf-href="/forum/#{ slug(forum) }/close/question/#{ question.id }">close</a></li>
|
||||
<li><a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/edit/question/#{ question.id }">edit</a></li>
|
||||
<li><a class="text-muted fa fa-trash-o" t-attf-href="/forum/#{ slug(forum) }/delete/question/#{ question.id }">delete</a></li>
|
||||
<li><a class="text-muted fa fa-times" t-if="question.state != 'close'"
|
||||
t-attf-href="/forum/#{ slug(forum) }/close/question/#{ question.id }">close</a></li>
|
||||
<li><a class="text-muted fa fa-times" t-if="question.state == 'close'"
|
||||
t-attf-href="/forum/#{ slug(forum) }/reopen/question/#{ question.id }">reopen</a></li>
|
||||
<li><a class="text-muted fa fa-edit"
|
||||
t-attf-href="/forum/#{ slug(forum) }/edit/question/#{ question.id }">edit</a></li>
|
||||
<li><a class="text-muted fa fa-trash-o" t-if="question.active"
|
||||
t-attf-href="/forum/#{ slug(forum) }/delete/question/#{ question.id }">delete</a></li>
|
||||
<li><a class="text-muted fa fa-trash-o" t-if="not question.active"
|
||||
t-attf-href="/forum/#{ slug(forum) }/undelete/question/#{ question.id }">undelete</a></li>
|
||||
<li><a class="text-muted fa fa-share" href="">share</a></li>
|
||||
</ul>
|
||||
</div>
|
||||
|
@ -382,7 +395,7 @@
|
|||
<span class="text-muted">Asked on <span t-field="question.write_date"/></span>
|
||||
</t>
|
||||
<div class="alert alert-info" t-if="question.state == 'close'">
|
||||
<p class="mt32 mb32" style="text-align: center;">
|
||||
<p class="mt32 mb32 text-center">
|
||||
<b>The question has been closed for the following reason "<span t-field="question.reason"/>"
|
||||
<i>by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(question.closed_by) }" t-field="question.closed_by.name"/> </i>
|
||||
<br/>close date <span t-field="question.closed_date"/></b>
|
||||
|
|
Loading…
Reference in New Issue