[IMP] improved code and view, fixed some issue to view commnet, show acceped answer in list,tag issue

bzr revid: tpa@tinyerp.com-20140404071043-n6x0wv6qyi1pdmav
This commit is contained in:
Turkesh Patel (Open ERP)
2014-04-04 12:40:43 +05:30
6 changed files with 59 additions and 46 deletions
+19 -18
View File
@@ -40,7 +40,7 @@ controllers = controllers()
class website_forum(http.Controller):
@http.route(['/forum/'], type='http', auth="public", website=True, multilang=True)
@http.route(['/forum'], type='http', auth="public", website=True, multilang=True)
def forum(self, **searches):
cr, uid, context = request.cr, request.uid, request.context
Forum = request.registry['website.forum']
@@ -48,7 +48,7 @@ class website_forum(http.Controller):
forums = Forum.browse(cr, uid, obj_ids, context=context)
return request.website.render("website_forum.forum_index", { 'forums': forums })
@http.route('/forum/add_forum/', type='http', auth="user", multilang=True, 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,
@@ -128,7 +128,7 @@ class website_forum(http.Controller):
user = request.registry['res.users'].browse(cr, uid, uid, context=context)
return {"user": user, "notifications": notifications}
@http.route('/forum/notification_read/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
@http.route('/forum/notification_read', type='json', auth="user", multilang=True, methods=['POST'], website=True)
def notification_read(self, **kwarg):
request.registry['mail.message'].set_message_read(request.cr, request.uid, [int(kwarg.get('notification_id'))], read=True, context=request.context)
return True
@@ -292,11 +292,12 @@ class website_forum(http.Controller):
'searches': {},
'forum': forum,
'user': user,
'ask_question': True,
'notifications': self._get_notifications(),
}
return request.website.render("website_forum.ask_question", values)
@http.route('/forum/<model("website.forum"):forum>/question/ask/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
@http.route('/forum/<model("website.forum"):forum>/question/ask', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def register_question(self, forum, **question):
cr, uid, context = request.cr, request.uid, request.context
create_context = dict(context)
@@ -305,7 +306,7 @@ class website_forum(http.Controller):
tags = question.get('question_tags').strip('[]').replace('"','').split(",")
question_tags = []
for tag in tags:
tag_ids = Tag.search(cr, uid, [('name', 'like', tag)], context=context)
tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context)
if tag_ids:
question_tags.append((4,tag_ids[0]))
else:
@@ -323,7 +324,7 @@ class website_forum(http.Controller):
}, context=create_context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),new_question_id))
@http.route('/forum/<model("website.forum"):forum>/question/postanswer/', type='http', auth="public", multilang=True, methods=['POST'], website=True)
@http.route('/forum/<model("website.forum"):forum>/question/postanswer', type='http', auth="public", multilang=True, methods=['POST'], website=True)
def post_answer(self, forum , post_id, **question):
if not request.session.uid:
return login_redirect()
@@ -395,12 +396,13 @@ class website_forum(http.Controller):
tags = post.get('question_tag').strip('[]').replace('"','').split(",")
question_tags = []
for tag in tags:
tag_ids = Tag.search(cr, uid, [('name', 'like', tag)], context=context)
tag_ids = Tag.search(cr, uid, [('name', '=', tag)], context=context)
if tag_ids:
question_tags.append((6, 0, tag_ids))
question_tags += tag_ids
else:
question_tags.append((0,0,{'name' : tag,'forum_id' : forum.id}))
vals.update({'tags': question_tags, 'name': post.get('question_name')})
new_tag = Tag.create(cr, uid, {'name' : tag,'forum_id' : forum.id}, context=context)
question_tags.append(new_tag)
vals.update({'tags': [(6, 0, question_tags)], 'name': post.get('question_name')})
post_id = post.get('answer_id') if post.get('answer_id') else post.get('question_id')
new_question_id = request.registry['website.forum.post'].write( cr, uid, [int(post_id)], vals, context=context)
@@ -471,7 +473,7 @@ class website_forum(http.Controller):
return request.website.render("website_forum.users", values)
@http.route('/forum/post_vote/', type='json', auth="public", multilang=True, methods=['POST'], website=True)
@http.route('/forum/post_vote', type='json', auth="public", multilang=True, methods=['POST'], website=True)
def post_vote(self, **post):
if not request.session.uid:
return {'error': 'anonymous_user'}
@@ -479,7 +481,7 @@ class website_forum(http.Controller):
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)
@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
@@ -499,7 +501,7 @@ class website_forum(http.Controller):
}, 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)
@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, SUPERUSER_ID, [int(kwarg.get('message_id'))], context=request.context)
return True
@@ -518,7 +520,7 @@ class website_forum(http.Controller):
}
return data
@http.route('/forum/correct_answer/', type='json', auth="public", multilang=True, methods=['POST'], website=True)
@http.route('/forum/correct_answer', type='json', auth="public", multilang=True, methods=['POST'], website=True)
def correct_answer(self, **kwarg):
cr, uid, context = request.cr, request.uid, request.context
if not request.session.uid:
@@ -556,7 +558,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)
@http.route('/forum/<model("website.forum"):forum>/question/close', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def close(self, forum, **post):
request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], {
'state': 'close',
@@ -588,7 +590,7 @@ class website_forum(http.Controller):
}
return request.website.render("website_forum.edit_profile", values)
@http.route('/forum/<model("website.forum"):forum>/save/profile/', type='http', auth="user", multilang=True, website=True)
@http.route('/forum/<model("website.forum"):forum>/save/profile', type='http', auth="user", multilang=True, website=True)
def save_edited_profile(self, forum, **post):
cr, uid, context = request.cr, request.uid, request.context
user = request.registry['res.users'].browse(cr, uid, int(post.get('user_id')),context=context)
@@ -605,7 +607,7 @@ class website_forum(http.Controller):
@http.route('/forum/<model("website.forum"):forum>/post/<model("website.forum.post"):post>/commet/<model("mail.message"):comment>/converttoanswer', type='http', auth="public", multilang=True, website=True)
def convert_to_answer(self, forum, post, comment, **kwarg):
values = {
'answer_content': comment.body,
'content': comment.body,
}
request.registry['mail.message'].unlink(request.cr, request.uid, [comment.id], context=request.context)
return self.post_answer(forum, post.parent_id and post.parent_id.id or post.id, **values)
@@ -644,4 +646,3 @@ class website_forum(http.Controller):
post_ids.append(post.id)
request.registry['website.forum.post'].message_unsubscribe( cr, uid, post_ids, [partner_id], context=context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.id))
@@ -1,5 +1,5 @@
<h1>Guidelines</h1>
<h2><a id="good_questions">What kinds of questions can I ask here?</a></h2>
<h2><a class="faq-question">What kinds of questions can I ask here?</a></h2>
<p>
This community is for professional and enthusiast users,
partners and programmers. You can ask questions about:
@@ -19,7 +19,7 @@
<b>Please avoid asking questions that are too subjective
and argumentative</b> or not relevant to this community.
</p>
<h2><a name="bad_questions">What should I avoid in my questions?</a></h2>
<h2><a class="faq-question">What should I avoid in my questions?</a></h2>
<p>
You should only ask practical, answerable questions based
on actual problems that you face. Chatty, open-ended
@@ -54,7 +54,7 @@
<li><b>Answers shouldn't just provide a link a solution</b>. Instead provide the solution description text in your answer, even if it's just a copy/paste. Links are welcome, but should complementary to answer, referring sources or additional reading.</li>
</ul>
<h2><a name="bad_answers">What should I avoid in my answers?</a></h2>
<h2><a class="faq-question">What should I avoid in my answers?</a></h2>
<p>
<b>Answers should not add or expand questions</b>. Instead
either edit the question or add a comment.
@@ -132,7 +132,7 @@
</tbody>
</table>
<h2><a name="community_edit">Why can other people edit my questions/answers?</a></h2>
<h2><a class="faq-question">Why can other people edit my questions/answers?</a></h2>
<p>
The goal of this site is create a relevant knowledge base that would answer
questions related to OpenERP.
+1 -1
View File
@@ -1,2 +1,2 @@
sass:
sass --compass --unix-newlines -t expanded website_forum.sass:website_forum.css
sass --compass --unix-newlines -t expanded website_forum.sass:website_forum.css
@@ -45,6 +45,25 @@
color: #999
}
.load_tags{
width: 845px !important;
}
.fa-thumbs-up, .fa-thumbs-down, .oe_answer_true, .oe_answer_false {
cursor:pointer;
}
.faq-question:hover {
text-decoration: none !important;
color: #428bca;
}
.oe_comment_grey {
-moz-box-shadow: 0px 4px 6px 2px #eeeeee;
-webkit-box-shadow: 0px 4px 6px 2px #eeeeee;
box-shadow: 0px 4px 6px 2px #eeeeee;
}
.tag_text .text-core .text-wrap textarea,
.tag_text .text-core .text-wrap input,
.tag_text .text-core .text-wrap .text-dropdown,
@@ -55,12 +74,4 @@
.tag_text .text-core .text-wrap .text-tags .text-tag .text-button {
height: 1.2em !important;
}
.load_tags{
width: 845px !important;
}
.fa-thumbs-up, .fa-thumbs-down, .oe_answer_true, .oe_answer_false {
cursor:pointer;
}
@@ -5,7 +5,7 @@ $(document).ready(function () {
var $link = $(ev.currentTarget);
var value = $link.attr("value")
openerp.jsonRpc("/forum/post_vote/", 'call', {
openerp.jsonRpc("/forum/post_vote", 'call', {
'post_id': $link.attr("id"),
'vote': value})
.then(function (data) {
@@ -52,7 +52,7 @@ $(document).ready(function () {
$('.delete').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc("/forum/post_delete/", 'call', {
openerp.jsonRpc("/forum/post_delete", 'call', {
'post_id': $link.attr("id")})
.then(function (data) {
$link.parents('#answer').remove();
@@ -60,10 +60,10 @@ $(document).ready(function () {
return false;
});
$('.fa-check').on('click', function (ev) {
$('.fa-check-circle').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc("/forum/correct_answer/", 'call', {
openerp.jsonRpc("/forum/correct_answer", 'call', {
'post_id': $link.attr("id")})
.then(function (data) {
if (data['error']) {
@@ -93,7 +93,7 @@ $(document).ready(function () {
$('.comment_delete').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc("/forum/message_delete/", 'call', {
openerp.jsonRpc("/forum/message_delete", 'call', {
'message_id': $link.attr("id")})
.then(function (data) {
$link.parents('#comment').remove();
@@ -104,7 +104,7 @@ $(document).ready(function () {
$('.notification_close').on('click', function (ev) {
ev.preventDefault();
var $link = $(ev.currentTarget);
openerp.jsonRpc("/forum/notification_read/", 'call', {
openerp.jsonRpc("/forum/notification_read", 'call', {
'notification_id': $link.attr("id")})
return true;
});
+10 -9
View File
@@ -28,6 +28,7 @@
<div class="pull-left text-center">
<div t-attf-class="box #{question.child_count and 'oe_green' or 'oe_grey'}">
<span t-esc="question.child_count"/>
<span t-if="question.correct" class="fa fa-2x fa-check-circle"/>
<div t-if="question.child_count&gt;1">Answers</div>
<div t-if="question.child_count&lt;=1">Answer</div>
</div>
@@ -124,7 +125,7 @@
<t t-raw="0"/>
</div>
<div class="col-sm-3" id="right-column">
<a class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ slug(forum) }/ask">Ask a Question</a>
<a t-if="not ask_question" class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ slug(forum) }/ask">Ask a Question</a>
<div t-field="forum.right_column"/>
<div t-if="question_data">
<div class="panel panel-default">
@@ -273,7 +274,7 @@
<li> provide enough details and, if possible, give an example </li>
<li> be clear and concise, avoid unnecessary introductions (Hi, ... Thanks...) </li>
</ul>
<form t-attf-action="/forum/#{ slug(forum) }/question/ask/" method="post" role="form" class="tag_text">
<form t-attf-action="/forum/#{ slug(forum) }/question/ask" method="post" role="form" class="tag_text">
<input type="text" name="question_name" required="True" t-attf-value="#{question_name}"
class="form-control" placeholder="Enter your Question"/>
<h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>
@@ -333,7 +334,7 @@
<template id="close_question">
<t t-call="website_forum.header">
<h3 class=""><b>Close question</b></h3><br/>
<form t-attf-action="/forum/#{ slug(forum) }/question/close/" method="post" role="form">
<form t-attf-action="/forum/#{ slug(forum) }/question/close" method="post" role="form">
<input name="post_id" t-att-value="post.id" type="hidden"/>
<span class="pull-left">Close the question:</span>
<a t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }" t-field="post.name"/>
@@ -362,7 +363,7 @@
- no need to answer the same question twice. Also, please <b>don't forget to vote</b>
- it really helps to select the best questions and answers!
</p>
<form t-attf-action="/forum/#{ slug(forum) }/question/postanswer/" method="post" role="form">
<form t-attf-action="/forum/#{ slug(forum) }/question/postanswer" method="post" role="form">
<input type="hidden" name="karma" t-attf-value="#{user.karma}" id="karma"/>
<textarea name="content" class="form-control load_editor" required="True"/>
<input name="post_id" t-att-value="question.id" type="hidden"/>
@@ -466,8 +467,8 @@
<t t-set="post" t-value="answer"/>
</t>
<div class="text-muted">
<a t-attf-id="#{answer.id}" t-if="answer.correct" class="fa fa-2x fa-check oe_answer_true"/>
<a t-attf-id="#{answer.id}" t-if="not answer.correct" class="fa fa-2x fa-check oe_answer_false"/>
<a t-attf-id="#{answer.id}" t-if="answer.correct" class="fa fa-2x fa-check-circle oe_answer_true"/>
<a t-attf-id="#{answer.id}" t-if="not answer.correct" class="fa fa-2x fa-check-circle oe_answer_false"/>
</div>
</div>
<div style="margin-left: 95px;" class="clearfix">
@@ -513,7 +514,7 @@
<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" id="comment" class="oe_grey" style="padding: 4px;">
<div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_comment_grey" style="padding: 4px;">
<small class="text-muted">
<button type="button" t-if="user.id == message.create_uid.id or user.karma&gt;=750" t-att-id="message.id" class="close comment_delete">&amp;times;</button>
<span t-field="message.body"/>
@@ -523,7 +524,7 @@
t-attf-href="/forum/#{ slug(forum) }/post/#{ object.id }/commet/#{ message.id }/converttoanswer">Convert as an answer</a>
</small>
</div>
<div class="css_editable_mode_hidden oe_grey">
<div class="css_editable_mode_hidden">
<form t-attf-id="comment#{ object._name.replace('.','') + '-' + str(object.id) }" class="collapse" t-attf-action="/forum/#{ slug(forum) }/comment" method="POST">
<input name="post_id" t-att-value="object.id" type="hidden"/>
<textarea name="comment" class="form-control" placeholder="Comment this post..."/>
@@ -639,7 +640,7 @@
<div class="col-md-2">
<span t-field="user.image" t-field-options='{"widget": "image", "class": "img img-responsive img-circle"}'/>
</div>
<form t-attf-action="/forum/#{ slug(forum) }/save/profile/" method="post" role="form" class="form-horizontal">
<form t-attf-action="/forum/#{ slug(forum) }/save/profile" method="post" role="form" class="form-horizontal">
<input name="user_id" t-att-value="user.id" type="hidden"/>
<label class="col-md-2 control-label mb16" for="user.name">Real name</label>
<div class="col-md-7 mb16">