[MERGE] [FIX] website_forum: batch of fixes :

- fixed reopen link that was broken (python code appearing)
- fixed close link that was leading to a 500 error due to post -> question
- fixed link to question author, was redirecting to the current user
- fixed displayed number of questions in the forum, now displaying actual question
number, not number of displayed questions in the page
- improved guidelines: added link back to the forum
- fixed tags display: now by posts_count desc, unused tags are not shown
- users are now displayed by desc karma
- converting a comment as an answer does not allow to create a new answer if another
one by uid is already present, it just moves the comment
- display tag name in 'filter' bar when filtering on a tag
- display active tag in a blue color
- order answers: correct first, then most upvoted

bzr revid: tde@openerp.com-20140506150145-c1uvlaqtyvkjcwea
This commit is contained in:
Thibault Delavallée 2014-05-06 17:01:45 +02:00
commit 0295b34c9b
5 changed files with 29 additions and 17 deletions

View File

@ -124,6 +124,7 @@ class WebsiteForum(http.Controller):
values.update({
'main_object': tag or forum,
'question_ids': question_ids,
'question_count': question_count,
'pager': pager,
'tag': tag,
'filters': filters,
@ -134,7 +135,7 @@ class WebsiteForum(http.Controller):
@http.route(['/forum/<model("forum.forum"):forum>/faq'], type='http', auth="public", website=True, multilang=True)
def forum_faq(self, forum, **post):
values = self._prepare_forum_values(forum=forum, searches=dict(), **post)
values = self._prepare_forum_values(forum=forum, searches=dict(), header={'is_guidelines': True}, **post)
return request.website.render("website_forum.faq", values)
@http.route('/forum/get_tags', type='http', auth="public", multilang=True, methods=['GET'], website=True)
@ -147,7 +148,7 @@ class WebsiteForum(http.Controller):
def tags(self, forum, page=1, **post):
cr, uid, context = request.cr, request.uid, request.context
Tag = request.registry['forum.tag']
obj_ids = Tag.search(cr, uid, [('forum_id', '=', forum.id)], limit=None, context=context)
obj_ids = Tag.search(cr, uid, [('forum_id', '=', forum.id), ('posts_count', '>', 0)], limit=None, order='posts_count DESC', context=context)
tags = Tag.browse(cr, uid, obj_ids, context=context)
values = self._prepare_forum_values(forum=forum, searches={'tags': True}, **post)
values.update({
@ -426,7 +427,7 @@ class WebsiteForum(http.Controller):
tag_count = User.search(cr, SUPERUSER_ID, [('karma', '>', 1)], count=True, context=context)
pager = request.website.pager(url="/forum/users", total=tag_count, page=page, step=step, scope=30)
obj_ids = User.search(cr, SUPERUSER_ID, [('karma', '>', 1)], limit=step, offset=pager['offset'], context=context)
obj_ids = User.search(cr, SUPERUSER_ID, [('karma', '>', 1)], limit=step, offset=pager['offset'], order='karma DESC', context=context)
users = User.browse(cr, SUPERUSER_ID, obj_ids, context=context)
searches['users'] = 'True'
@ -590,12 +591,13 @@ class WebsiteForum(http.Controller):
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/comment/<model("mail.message"):comment>/convert_to_answer', type='http', auth="public", multilang=True, website=True)
def convert_comment_to_answer(self, forum, post, comment, **kwarg):
values = {
'content': comment.body,
}
body = comment.body
request.registry['mail.message'].unlink(request.cr, request.uid, [comment.id], context=request.context)
question = post.parent_id if post.parent_id else post
return self.post_new(forum, question, **values)
for answer in question.child_ids:
if answer.create_uid.id == request.uid:
return self.post_comment(forum, answer, comment=html2plaintext(body))
return self.post_new(forum, question, content=body)
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/convert_to_comment', type='http', auth="user", multilang=True, website=True)
def convert_answer_to_comment(self, forum, post, **kwarg):

View File

@ -70,6 +70,7 @@ class Post(osv.Model):
_name = 'forum.post'
_description = 'Forum Post'
_inherit = ['mail.thread', 'website.seo.metadata']
_order = "is_correct DESC, vote_count DESC"
def _get_user_vote(self, cr, uid, ids, field_name, arg, context):
res = dict.fromkeys(ids, 0)

View File

@ -21,6 +21,9 @@
background-color: #cccccc;
margin-left: 4px;
}
.question .badge-active {
background-color: #428bca;
}
.oe_grey {
background-color: #eeeeee;

View File

@ -17,6 +17,8 @@
.badge
background-color: #ccc
margin-left: 4px
.badge-active
background-color: #428bca
.oe_grey
background-color: #eeeeee

View File

@ -92,7 +92,8 @@
</div>
<div class="panel-body">
<t t-raw="forum.description"/><br/>
<a t-attf-href="/forum/#{slug(forum)}/faq" class="fa fa-arrow-right"> Read Guidelines</a>
<a t-if="not header.get('is_guidelines')" t-attf-href="/forum/#{slug(forum)}/faq" class="fa fa-arrow-right"> Read Guidelines</a>
<a t-if="header.get('is_guidelines')" t-attf-href="/forum/#{slug(forum)}" class="fa fa-arrow-right"> Back to <span t-field="forum.name"/></a>
</div>
</div>
<div t-if="header.get('question_data')">
@ -144,8 +145,11 @@
<span t-if="not question.active"><b> [Deleted]</b></span>
<span t-if="question.state == 'close'"><b> [Closed]</b></span>
</div>
<t t-foreach="question.tag_ids" t-as="tag">
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{ tag.id }/questions" class="badge pull-right" t-field="tag.name"/>
<t t-foreach="question.tag_ids" t-as="question_tag">
<a t-attf-href="/forum/#{ slug(forum) }/tag/#{slug(question_tag)}/questions">
<span t-attf-class="pull-right badge #{tag and tag.name == question_tag.name and 'badge-active' ''}" t-field="question_tag.name"
style="margin-right: 4px;"/>
</a>
</t>
<div class="text-muted">
by <a t-attf-href="/forum/#{ slug(forum) }/user/#{ question.create_uid.id }"
@ -208,14 +212,14 @@
<template id="forum_index" name="Forum">
<t t-call="website_forum.header">
<h1 class="page-header mt0">
<t t-esc="len(question_ids)"/> <span>Questions</span>
<t t-esc="question_count"/> <span>Questions</span>
<t t-esc="search"/>
<small class="dropdown" t-if="filters in ('all', 'unanswered','followed', 'tag')">
<a href="#" class="dropdown-toggle" data-toggle="dropdown">
<t t-if="filters == 'all'">All</t>
<t t-if="filters == 'unanswered'">Unanswered</t>
<t t-if="filters == 'followed'">Followed</t>
<t t-if="filters == 'tag'">Tag</t>
<t t-if="tag"><span t-field="tag.name"/></t>
<t t-if="sorting == 'date'"> by activity date</t>
<t t-if="sorting == 'answered'"> by most answered</t>
<t t-if="sorting == 'vote'"> by most voted</t>
@ -332,12 +336,12 @@
users having a high karma can see closed questions to moderate
them.
</p>
<form t-attf-action="/forum/#{ slug(forum) }/question/#{slug(post)}/close" method="post" role="form" class="form-horizontal mt32 mb64">
<form t-attf-action="/forum/#{ slug(forum) }/question/#{slug(question)}/close" method="post" role="form" class="form-horizontal mt32 mb64">
<input name="post_id" t-att-value="question.id" type="hidden"/>
<div class="form-group">
<label class="col-md-3 control-label" for="reason">Question:</label>
<div class="col-md-8 mt8">
<span t-field="post.name"/>
<span t-field="question.name"/>
</div>
</div>
<div class="form-group">
@ -354,7 +358,7 @@
<div class="col-md-offset-3 col-md-8">
<button class="btn btn-primary">Close question</button>
<span class="text-muted">or</span>
<a class="btn btn-link" t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(post) }">back to question</a>
<a class="btn btn-link" t-attf-href="/forum/#{ slug(forum) }/question/#{ slug(question) }">back to question</a>
</div>
</div>
</form>
@ -451,7 +455,7 @@
<a class="text-muted fa fa-times" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/ask_for_close"> Close</a>
</li>
<li t-if="question.state == 'close' and ((user.id == question.create_uid.id and can_close_own) or can_close_all)">
<a class="text-muted fa fa-undo" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)/reopen">reopen</a>
<a class="text-muted fa fa-undo" t-attf-href="/forum/#{ slug(forum) }/question/#{slug(question)}/reopen"> Reopen</a>
</li>
<li t-if="(user.id == question.create_uid.id and can_edit_own) or can_edit_all">
<a class="text-muted fa fa-edit" t-attf-href="/forum/#{ slug(forum) }/post/#{slug(question)}/edit"> Edit</a>
@ -467,7 +471,7 @@
<div>
<span t-field="question.create_uid.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/>
<div>
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ user.id }"
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ question.create_uid.id }"
t-field="question.create_uid"
t-field-options='{"widget": "contact", "country_image": true, "fields": ["name", "country_id"]}'
style="display: inline-block;"/>