[ADD] added code to chek user have enough karma of not to add image or link.

bzr revid: tpa@tinyerp.com-20140401084631-41ezq2jy9r7ln6sx
This commit is contained in:
Turkesh Patel (Open ERP) 2014-04-01 14:16:31 +05:30
parent 5864add053
commit c4b54541b4
3 changed files with 64 additions and 33 deletions

View File

@ -287,9 +287,11 @@ class website_forum(http.Controller):
def question_ask(self, forum, **post):
if not request.session.uid:
return login_redirect()
user = request.registry['res.users'].browse(request.cr, request.uid, request.uid, context=request.context)
values = {
'searches': {},
'forum': forum,
'user': user,
'notifications': self._get_notifications(),
}
return request.website.render("website_forum.ask_question", values)
@ -314,7 +316,7 @@ class website_forum(http.Controller):
'user_id': uid,
'forum_id': forum.id,
'name': question.get('question_name'),
'content': question.get('question_content'),
'content': question.get('content'),
'tags' : question_tags,
'state': 'active',
'active': True,
@ -335,7 +337,7 @@ class website_forum(http.Controller):
'forum_id': forum.id,
'user_id': uid,
'parent_id': post_id,
'content': question.get('answer_content'),
'content': question.get('content'),
'state': 'active',
'active': True,
}, context=create_context)
@ -347,6 +349,7 @@ class website_forum(http.Controller):
def edit_answer(self, forum, post, answer='', **kwargs):
cr, uid, context = request.cr, request.uid, request.context
request.registry['res.users'].write(cr, SUPERUSER_ID, uid, {'forum': True}, context=context)
user = request.registry['res.users'].browse(cr, uid, uid, context=context)
for record in post.child_ids:
if record.user_id.id == request.uid and not answer:
answer = record
@ -357,6 +360,7 @@ class website_forum(http.Controller):
values = {
'post': post,
'user': user,
'post_answer': answer,
'notifications': self._get_notifications(),
'forum': forum,
@ -473,27 +477,6 @@ class website_forum(http.Controller):
request.registry['mail.message'].unlink(request.cr, SUPERUSER_ID, [int(kwarg.get('message_id'))], context=request.context)
return True
@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):
cr, uid, context = request.cr, request.uid, request.context
history_obj = request.registry['website.forum.post.history']
history_ids = history_obj.search(cr, uid, [('post_id','=', post.id)], order = "id desc", context=context)
post_history = history_obj.browse(cr, uid, history_ids, context=context)
tags = ""
for tag_name in post.tags:
tags += tag_name.name + ","
values = {
'post': post,
'tags': tags,
'forum': forum,
'searches': kwarg,
'notifications': self._get_notifications(),
'post_history': post_history,
}
return request.website.render("website_forum.edit_question", values)
@http.route('/forum/selecthistory', type='json', auth="user", multilang=True, methods=['POST'], website=True)
def post_history(self, **kwarg):
cr, uid, context = request.cr, request.uid, request.context
@ -508,6 +491,29 @@ class website_forum(http.Controller):
}
return data
@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):
cr, uid, context = request.cr, request.uid, request.context
user = request.registry['res.users'].browse(cr, uid, uid, context=context)
history_obj = request.registry['website.forum.post.history']
history_ids = history_obj.search(cr, uid, [('post_id','=', post.id)], order = "id desc", context=context)
post_history = history_obj.browse(cr, uid, history_ids, context=context)
tags = ""
for tag_name in post.tags:
tags += tag_name.name + ","
values = {
'post': post,
'user': user,
'tags': tags,
'forum': forum,
'searches': kwarg,
'notifications': self._get_notifications(),
'post_history': post_history,
}
return request.website.render("website_forum.edit_question", values)
@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):
cr, uid, context = request.cr, request.uid, request.context

View File

@ -134,4 +134,25 @@ $(document).ready(function () {
return true;
});
});
if ($('textarea.load_editor').length) {
var editor = CKEDITOR.instances['content'];
editor.on('instanceReady', CKEDITORLoadComplete);
}
});
function IsKarmaValid(eventNumber,minKarma){
"use strict";
if(parseInt($("#karma").val()) >= minKarma){
CKEDITOR.tools.callFunction(eventNumber,this);
return false;
} else {
alert("Sorry you need more than 30 Karma.");
}
}
function CKEDITORLoadComplete(){
"use strict";
$('.cke_button__link').attr('onclick','IsKarmaValid(33,30)');
$('.cke_button__unlink').attr('onclick','IsKarmaValid(37,30)');
$('.cke_button__image').attr('onclick','IsKarmaValid(41,30)');
}

View File

@ -70,7 +70,7 @@
<script type="text/javascript" src="/web/static/lib/ckeditor/ckeditor.js"/>
<script type="text/javascript">
CKEDITOR.config.toolbar = [['Bold','Italic','Underline','Strike'],['NumberedList','BulletedList', 'Blockquote']
,['Outdent','Indent','Link','Unlink'],] ;
,['Outdent','Indent','Link','Unlink','Image'],] ;
</script>
</t>
<div class="container mt16">
@ -277,8 +277,10 @@
<input type="text" name="question_name" required="True" t-attf-value="#{question_name or ''}"
class="form-control" placeholder="Enter your Question"/>
<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 ''}"/>
<input type="hidden" name="karma" t-attf-value="#{user.karma or ''}" id="karma"/>
<textarea name="content" required="True" class="form-control load_editor">
<t t-esc="question_content"/>
</textarea>
<br/>
<input type="text" name="question_tags" t-attf-value="#{question_tag or ''}"
placeholder="Tags" class="form-control load_tags"/>
@ -286,7 +288,7 @@
<button class="btn btn-primary" id="btn_ask_your_question">Post Your Question</button>
</form>
<script type="text/javascript">
CKEDITOR.replace("question_content");
CKEDITOR.replace("content");
</script>
</t>
</template>
@ -303,7 +305,8 @@
<input type="text" name="question_name" id="question_name" required="True" t-attf-value="#{post.name or ''}"
class="form-control" placeholder="Edit your Question"/>
<h5 class="mt20">Please enter a descriptive question (should finish by a '?')</h5>
<textarea name="content" required="True" class="form-control">
<input type="hidden" name="karma" t-attf-value="#{user.karma or ''}" id="karma"/>
<textarea name="content" required="True" class="form-control load_editor">
<t t-esc="post.content"/>
</textarea>
<br/>
@ -351,13 +354,13 @@
- it really helps to select the best questions and answers!
</p>
<form t-attf-action="/forum/#{ slug(forum) }/question/postanswer/" method="post" role="form">
<textarea name="answer_content" t-attf-value="#{answer_content or ''}"
class="form-control" required="True"/>
<input type="hidden" name="karma" t-attf-value="#{user.karma or ''}" id="karma"/>
<textarea name="content" class="form-control load_editor" required="True"/>
<input name="post_id" t-att-value="question.id" type="hidden"/>
<button class="btn btn-primary" id="btn_ask_your_question">Post Your Answer</button>
</form>
<script type="text/javascript">
CKEDITOR.replace("answer_content");
CKEDITOR.replace("content");
</script>
</template>
@ -370,7 +373,8 @@
<option t-att-value="history.id"><t t-esc="history.name"/></option>
</t>
</select>
<textarea name="content" required="True" value="content" class="form-control">
<input type="hidden" name="karma" t-attf-value="#{user.karma or ''}" id="karma"/>
<textarea name="content" required="true" class="form-control load_editor">
<t t-esc="post_answer.content"/>
</textarea>
<input name="post_id" t-att-value="post.id" type="hidden"/>