[IMP] website_forum: karma management for vote
bzr revid: tde@openerp.com-20140411182254-0wyvzpcqxk4jyqev
This commit is contained in:
parent
2ec3a40334
commit
06776da4a9
|
@ -285,9 +285,9 @@ class WebsiteForum(http.Controller):
|
|||
cr, uid, context = request.cr, request.uid, request.context
|
||||
if not request.session.uid:
|
||||
return {'error': 'anonymous_user'}
|
||||
# # if user have not access to accept answer then reise warning
|
||||
# if user have not access to accept answer then reise warning
|
||||
if post.parent_id is False or post.parent_id.create_uid.id != uid:
|
||||
return {'error': 'user'}
|
||||
return {'error': 'own_post'}
|
||||
|
||||
# set all answers to False, only one can be accepted
|
||||
request.registry['forum.post'].write(cr, uid, [c.id for c in post.parent_id.child_ids], {'is_correct': False}, context=context)
|
||||
|
@ -344,13 +344,22 @@ class WebsiteForum(http.Controller):
|
|||
# check for karma and not self vote
|
||||
if not request.session.uid:
|
||||
return {'error': 'anonymous_user'}
|
||||
if request.uid == post.create_uid.id:
|
||||
return {'error': 'own_post'}
|
||||
user = request.registry['res.users'].browse(request.cr, SUPERUSER_ID, request.uid, context=request.context)
|
||||
if user.karma <= 5:
|
||||
return {'error': 'not_enough_karma', 'karma': 5}
|
||||
return request.registry['forum.post'].vote(request.cr, request.uid, [post.id], upvote=True, context=request.context)
|
||||
|
||||
@http.route('/forum/<model("forum.forum"):forum>/post/<model("forum.post"):post>/downvote', type='json', auth="public", multilang=True, website=True)
|
||||
def post_downvote(self, forum, post, **kwargs):
|
||||
# check for karma and not self vote
|
||||
if not request.session.uid:
|
||||
return {'error': 'anonymous_user'}
|
||||
if request.uid == post.create_uid.id:
|
||||
return {'error': 'own_post'}
|
||||
user = request.registry['res.users'].browse(request.cr, SUPERUSER_ID, request.uid, context=request.context)
|
||||
if user.karma <= 50:
|
||||
return {'error': 'not_enough_karma', 'karma': 50}
|
||||
return request.registry['forum.post'].vote(request.cr, request.uid, [post.id], upvote=False, context=request.context)
|
||||
|
||||
# User
|
||||
|
@ -464,18 +473,15 @@ class WebsiteForum(http.Controller):
|
|||
return request.website.render("website_forum.user_detail_full", values)
|
||||
|
||||
@http.route('/forum/<model("forum.forum"):forum>/user/<model("res.users"):user>/edit', type='http', auth="user", multilang=True, website=True)
|
||||
def edit_profile(self, forum, user, **kwarg):
|
||||
cr, context = request.cr, request.context
|
||||
def edit_profile(self, forum, user, **kwargs):
|
||||
country = request.registry['res.country']
|
||||
country_ids = country.search(cr, SUPERUSER_ID, [], context=context)
|
||||
countries = country.browse(cr, SUPERUSER_ID, country_ids, context)
|
||||
values = {
|
||||
'user': user,
|
||||
'forum': forum,
|
||||
'searches': kwarg,
|
||||
country_ids = country.search(request.cr, SUPERUSER_ID, [], context=request.context)
|
||||
countries = country.browse(request.cr, SUPERUSER_ID, country_ids, context=request.context)
|
||||
values = self._prepare_forum_values(forum=forum, searches=kwargs)
|
||||
values.update({
|
||||
'countries': countries,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
})
|
||||
return request.website.render("website_forum.edit_profile", values)
|
||||
|
||||
@http.route('/forum/<model("forum.forum"):forum>/user/<model("res.users"):user>/save', type='http', auth="user", multilang=True, website=True)
|
||||
|
@ -488,8 +494,7 @@ class WebsiteForum(http.Controller):
|
|||
'country_id': kwargs.get('country'),
|
||||
'website_description': kwargs.get('description'),
|
||||
}, context=request.context)
|
||||
user.refresh()
|
||||
return werkzeug.utils.redirect("/forum/%s/user/%s" % (slug(forum), slug(user)))
|
||||
return werkzeug.utils.redirect("/forum/%s/user/%d" % (slug(forum), user.id))
|
||||
|
||||
# Badges
|
||||
# --------------------------------------------------
|
||||
|
|
|
@ -17,11 +17,10 @@ $(document).ready(function () {
|
|||
'Sorry you must be logged to vote'+
|
||||
'</div>');
|
||||
}
|
||||
else if (data['error'] == 'lessthen_10_karma')
|
||||
{
|
||||
else if (data['error'] == 'not_enough_karma') {
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" id="vote_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'10 karma required to downvote'+
|
||||
'Sorry, at least ' + data['karma'] + ' karma is required to vote'+
|
||||
'</div>');
|
||||
}
|
||||
vote_alert = $link.parent().find("#vote_alert");
|
||||
|
@ -55,7 +54,7 @@ $(document).ready(function () {
|
|||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'Sorry, anonymous users cannot choose correct answer.'+
|
||||
'</div>');
|
||||
} else if (data['error'] == 'user'){
|
||||
} else if (data['error'] == 'own_post'){
|
||||
var $warning = $('<div class="alert alert-danger alert-dismissable" id="correct_answer_alert" style="position:absolute; margin-top: -30px; margin-left: 90px;">'+
|
||||
'<button type="button" class="close notification_close" data-dismiss="alert" aria-hidden="true">×</button>'+
|
||||
'Sorry, the user who asked this question can only accept the answer as correct.'+
|
||||
|
|
|
@ -759,7 +759,7 @@
|
|||
<span t-field="user.city"/>
|
||||
<span t-if="user.city and user.country_id">, </span>
|
||||
<span t-field="user.country_id"/>
|
||||
<t t-if="user.country_id"> <span t-field="user.country_id.image" t-field-options='{"widget": "image", "class":"forum_user_flag"}'/></t>
|
||||
<t t-if="user.country_id"> <span t-field="user.country_id.image" t-field-options='{"widget": "image", "class": "country_flag"}'/></t>
|
||||
|
||||
</td>
|
||||
</tr>
|
||||
|
|
Loading…
Reference in New Issue