[ADD] add code to edit answer and dont show template to post answer if user allready given answer just show button to edit answer.
bzr revid: tpa@tinyerp.com-20140227125701-90m6mpigjq1npvub
This commit is contained in:
parent
081a1c0925
commit
801d9d429b
|
@ -84,11 +84,15 @@ class website_forum(http.Controller):
|
|||
|
||||
@http.route(['/forum/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
||||
def open_question(self, question, **post):
|
||||
answer_done = False
|
||||
for answer in question.child_ids:
|
||||
if answer.create_uid.id == request.uid:
|
||||
answer_done = True
|
||||
values = {
|
||||
'question': question,
|
||||
'main_object': question,
|
||||
'range': range,
|
||||
'searches': post
|
||||
'searches': post,
|
||||
'answer_done': answer_done
|
||||
}
|
||||
return request.website.render("website_forum.post_description_full", values)
|
||||
|
||||
|
@ -130,6 +134,30 @@ class website_forum(http.Controller):
|
|||
}, context=create_context)
|
||||
return werkzeug.utils.redirect("/forum/question/%s" % post_id)
|
||||
|
||||
@http.route(['/forum/question/editanswer'], type='http', auth="user", website=True, multilang=True)
|
||||
def edit_answer(self, post_id, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
post = request.registry['website.forum.post'].browse(cr, uid, int(post_id), context=context)
|
||||
for answer in post.child_ids:
|
||||
if answer.create_uid.id == request.uid:
|
||||
post_answer = answer
|
||||
values = {
|
||||
'post': post,
|
||||
'post_answer': post_answer,
|
||||
'searches': kwargs
|
||||
}
|
||||
return request.website.render("website_forum.edit_answer", values)
|
||||
|
||||
@http.route('/forum/question/saveanswer/', type='http', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def save_edited_answer(self, forum_id=1, **post):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
answer_id = int(post.get('answer_id'))
|
||||
|
||||
new_question_id = request.registry['website.forum.post'].write( cr, uid, [answer_id], {
|
||||
'content': post.get('answer_content'),
|
||||
}, context=context)
|
||||
return werkzeug.utils.redirect("/forum/question/%s" % post.get('post_id'))
|
||||
|
||||
@http.route(['/forum/tag/<model("website.forum.tag"):tag>'], type='http', auth="public", website=True, multilang=True)
|
||||
def tag_questions(self, tag, page=1, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
|
|
@ -9,6 +9,10 @@
|
|||
src="/website_forum/static/src/js/website_forum.editor.js"></script>
|
||||
<script type="text/javascript"
|
||||
src="/website_forum/static/src/js/website.tour.forum.js"></script>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.config.toolbar = [['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList']
|
||||
,['Outdent','Indent','Link','Unlink'],] ;
|
||||
</script>
|
||||
</xpath>
|
||||
</template>
|
||||
|
||||
|
@ -450,9 +454,6 @@
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.replace("textarea_ckeditor");
|
||||
CKEDITOR.config.toolbar =
|
||||
[['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList']
|
||||
,['Outdent','Indent','Link','Unlink'],] ;
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -503,13 +504,44 @@
|
|||
</div>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.replace("textarea_ckeditor");
|
||||
CKEDITOR.config.toolbar =
|
||||
[['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList']
|
||||
,['Outdent','Indent','Link','Unlink'],] ;
|
||||
</script>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template id="edit_answer">
|
||||
<t t-call="website.layout">
|
||||
<div class="container">
|
||||
<div class="col-md-9 col-xs-11">
|
||||
<div class="row">
|
||||
<h3>Edit answer</h3>
|
||||
</div>
|
||||
<div class="row">
|
||||
<form action="/forum/question/saveanswer/" method="post" role="form">
|
||||
<div >
|
||||
<div class="row">
|
||||
<div class="col-xs-12">
|
||||
<textarea name="answer_content" required="True" value="content" class="form-control"
|
||||
id="textarea_ckeditor" rows="10" style="width : 100%" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<input name="post_id" t-att-value="post.id" type="hidden"/>
|
||||
<input name="answer_id" t-att-value="post_answer.id" type="hidden"/>
|
||||
<div>
|
||||
<button class="btn btn-default btn-lg">
|
||||
Save edit
|
||||
</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<script type="text/javascript">
|
||||
CKEDITOR.replace("textarea_ckeditor");
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="post_description_full">
|
||||
<t t-call="website.layout">
|
||||
<div class="container MainBody">
|
||||
|
@ -535,8 +567,19 @@
|
|||
</div>
|
||||
<t t-call="website_forum.shorting_answer" />
|
||||
</div>
|
||||
<t t-call="website_forum.answer" />
|
||||
<t t-call="website_forum.post_answer" />
|
||||
<t t-call="website_forum.answer"/>
|
||||
<div t-if="not answer_done">
|
||||
<t t-call="website_forum.post_answer"/>
|
||||
</div>
|
||||
<div t-if="answer_done">
|
||||
<form action="/forum/question/editanswer/" method="post" role="form">
|
||||
<input name="post_id" t-att-value="question.id" type="hidden" />
|
||||
<button class="btn btn-default btn-lg" id="btn_edit_your_question">
|
||||
Edit Your Answer
|
||||
</button>
|
||||
<span> (only one answer per question is allowed) </span>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
|
Loading…
Reference in New Issue