[ADD] added code to apply tag on ask and edit question(still have to improve code for create tag) from db.

bzr revid: tpa@tinyerp.com-20140324132137-jx0b5rjjm9g93v0p
This commit is contained in:
Turkesh Patel (Open ERP) 2014-03-24 18:51:37 +05:30
parent 3b840a59d3
commit 9b06d9cae1
4 changed files with 60 additions and 8 deletions

View File

@ -243,13 +243,20 @@ class website_forum(http.Controller):
def register_question(self, forum, **question):
cr, uid, context = request.cr, request.uid, request.context
create_context = dict(context)
tags = question.get('question_tags').strip('[]').replace('"','').split(",")
tag_ids = request.registry['website.forum.tag'].search(cr, uid, [('name', 'in', tags)], context=context)
question_tags = []
for tag in tag_ids:
question_tags.append((4,tag))
new_question_id = request.registry['website.forum.post'].create(
request.cr, request.uid, {
'user_id': uid,
'forum_id': forum.id,
'name': question.get('question_name'),
'content': question.get('question_content'),
#'tags' : question.get('question_tags'),
'tags' : question_tags,
'state': 'active',
'active': True,
}, context=create_context)
@ -414,8 +421,13 @@ class website_forum(http.Controller):
@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):
tags = ""
for tag_name in post.tags:
tags += tag_name.name + ","
values = {
'post': post,
'tags': tags,
'forum': forum,
'searches': kwarg,
'notifications': self._get_notifications(),
@ -424,10 +436,16 @@ class website_forum(http.Controller):
@http.route('/forum/<model("website.forum"):forum>/question/savequestion/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
def save_edited_question(self, forum, **post):
request.registry['website.forum.post'].write( request.cr, request.uid, [int(post.get('post_id'))], {
cr, uid, context = request.cr, request.uid, request.context
tags = post.get('question_tag').strip('[]').replace('"','').split(",")
tag_ids = request.registry['website.forum.tag'].search(cr, uid, [('name', 'in', tags)], context=context)
question_tags = [(6, 0, tag_ids)]
request.registry['website.forum.post'].write(cr, uid, [int(post.get('post_id'))], {
'content': post.get('answer_content'),
'name': post.get('question_name'),
}, context=request.context)
'tags' : question_tags,
}, context=context)
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('post_id')))
@http.route('/forum/<model("website.forum"):forum>/answer/<model("website.forum.post"):post>/edit/<model("website.forum.post"):answer>', type='http', auth="user", multilang=True, website=True)
@ -539,3 +557,7 @@ class website_forum(http.Controller):
request.registry['website.forum.post'].unlink(request.cr, request.uid, [post.id], context=request.context)
return self.post_comment(forum, post.parent_id.id, **values)
@http.route('/forum/get_tags/', type='json', auth="public", multilang=True, methods=['POST'], website=True)
def tag_read(self, **kwarg):
tags = request.registry['website.forum.tag'].search_read(request.cr, request.uid, [],['name'], context=request.context)
return [ tag['name'] for tag in tags]

View File

@ -44,3 +44,15 @@
.oe_answer_false {
color: #999
}
.text-core .text-wrap textarea, .text-core .text-wrap input, .text-core .text-wrap .text-dropdown, .text-core .text-wrap .text-prompt, .text-core .text-wrap .text-tags .text-tag .text-button {
font: 1.2em "Helvetica Neue",Helvetica,Arial,sans-serif !important;
}
.text-core .text-wrap .text-tags .text-tag .text-button {
height: 1.2em !important;
}
#question_tag{
width: 825px !important;
}

View File

@ -111,4 +111,16 @@ $(document).ready(function () {
return true;
});
openerp.jsonRpc('/forum/get_tags/','call' ,{}).then(function(data){
var previous_tags = $("#question_tag").val();
$("#question_tag").val("");
var array_of_tags = previous_tags.split(",");
$('#question_tag').textext({
plugins : 'tags suggestions autocomplete',
tagsItems : array_of_tags,
suggestions :data,
});
return true;
});
});

View File

@ -14,6 +14,7 @@
-->
<script type="text/javascript"
src="/website_forum/static/src/js/website_forum.editor.js"></script>
<script type="text/javascript" src="/web/static/lib/jquery.textext/jquery.textext.js"/>
<script type="text/javascript">
CKEDITOR.config.toolbar = [['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList', 'Blockquote']
,['Outdent','Indent','Link','Unlink'],] ;
@ -68,6 +69,7 @@
<template id="header" name="Forum Index">
<t t-call="website.layout">
<t t-set="head">
<link rel='stylesheet' href="/web/static/lib/jquery.textext/jquery.textext.css"/>
<link rel='stylesheet' href='/website_forum/static/src/css/website_forum.css'/>
</t>
<div class="container mt16">
@ -243,8 +245,10 @@
<h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>
<textarea name="question_content" required="True" class="form-control"
t-attf-value="#{question_content or ''}" id="textarea_ckeditor"/>
<input type="text" name="question_tag" t-attf-value="#{question_tag or ''}"
class="form-control" style="margin-top: 10px" placeholder="Tags"/>
<br/>
<input type="text" name="question_tags" t-attf-value="#{question_tag or ''}"
placeholder="Tags" id="question_tag" class="form-control"/>
<br/>
<button class="btn btn-primary" id="btn_ask_your_question">Post Your Question</button>
</form>
<script type="text/javascript">
@ -299,8 +303,10 @@
<textarea name="answer_content" required="True" value="content" class="form-control" id="textarea_ckeditor">
<t t-esc="post.content"/>
</textarea>
<input type="text" name="question_tag" class="form-control" style="margin-top: 10px" placeholder="Tags"/>
<br/>
<input type="text" name="question_tag" id="question_tag" class="form-control" placeholder="Tags" t-attf-value="#{tags or ''}"/>
<input name="post_id" t-att-value="post.id" type="hidden"/>
<br/>
<button class="btn btn-primary btn-lg">Save</button>
</form>
<script type="text/javascript">
@ -378,9 +384,9 @@
</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'"
<li><a class="text-muted fa fa-undo" 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-undo"
<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>