[IMP] gamification: improved code to send notification message when bedge assigned, website_forum: improved code to show notification when badge assigned to user.
bzr revid: tpa@tinyerp.com-20140319090735-zi01wzh8a8u5cfb7
This commit is contained in:
parent
603cc77da7
commit
9bb6139cd2
|
@ -34,7 +34,9 @@ class gamification_badge_user(osv.Model):
|
|||
|
||||
_name = 'gamification.badge.user'
|
||||
_description = 'Gamification user badge'
|
||||
_inherit = ['mail.thread']
|
||||
_order = "create_date desc"
|
||||
_rec_name = "badge_name"
|
||||
|
||||
_columns = {
|
||||
'user_id': fields.many2one('res.users', string="User", required=True),
|
||||
|
@ -57,16 +59,16 @@ class gamification_badge_user(osv.Model):
|
|||
"""
|
||||
res = True
|
||||
temp_obj = self.pool.get('email.template')
|
||||
user_obj = self.pool.get('res.users')
|
||||
template_id = self.pool['ir.model.data'].get_object(cr, uid, 'gamification', 'email_template_badge_received', context)
|
||||
for badge_user in self.browse(cr, uid, ids, context=context):
|
||||
body_html = temp_obj.render_template(cr, uid, template_id.body_html, 'gamification.badge.user', badge_user.id, context=context)
|
||||
res = user_obj.message_post(cr, uid, badge_user.user_id.id, body=body_html, context=context)
|
||||
res = self.message_post(cr, uid, badge_user.id, body=body_html, partner_ids=[badge_user.user_id.partner_id.id], context=context)
|
||||
return res
|
||||
|
||||
def create(self, cr, uid, vals, context=None):
|
||||
create_context = dict(context, mail_create_nolog=True)
|
||||
self.pool.get('gamification.badge').check_granting(cr, uid, badge_id=vals.get('badge_id'), context=context)
|
||||
return super(gamification_badge_user, self).create(cr, uid, vals, context=context)
|
||||
return super(gamification_badge_user, self).create(cr, uid, vals, context=create_context)
|
||||
|
||||
|
||||
class gamification_badge(osv.Model):
|
||||
|
|
|
@ -53,6 +53,15 @@ class website_forum(http.Controller):
|
|||
}, context=request.context)
|
||||
return request.redirect("/forum/%s" % forum_id)
|
||||
|
||||
def _get_notifications(self, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
Message = request.registry['mail.message']
|
||||
BadgeUser = request.registry['gamification.badge.user']
|
||||
#notification to user.
|
||||
badgeuser_ids = BadgeUser.search(cr, uid, [('user_id', '=', uid)], context=context)
|
||||
notification_ids = Message.search(cr, uid, [('res_id', 'in', badgeuser_ids), ('model', '=', 'gamification.badge.user'), ('to_read', '=', True)], context=context)
|
||||
return Message.browse(cr, uid, notification_ids, context=context)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>', '/forum/<model("website.forum"):forum>/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def questions(self, forum, page=1, filters='', sorting='', **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
@ -94,6 +103,7 @@ class website_forum(http.Controller):
|
|||
'uid': uid,
|
||||
'total_questions': question_count,
|
||||
'question_ids': question_ids,
|
||||
'notifications': self._get_notifications(),
|
||||
'forum': forum,
|
||||
'pager': pager,
|
||||
'filters': filters,
|
||||
|
@ -103,14 +113,27 @@ class website_forum(http.Controller):
|
|||
|
||||
return request.website.render("website_forum.index", values)
|
||||
|
||||
@http.route('/forum/notification_read/', type='json', auth="user", multilang=True, methods=['POST'], website=True)
|
||||
def notification_read(self, **kwarg):
|
||||
request.registry['mail.message'].set_message_read(request.cr, request.uid, [int(kwarg.get('notification_id'))], read=True, context=request.context)
|
||||
return True
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/faq'], type='http', auth="public", website=True, multilang=True)
|
||||
def faq(self, forum, **post):
|
||||
values = { 'searches': {}, 'forum':forum }
|
||||
values = {
|
||||
'searches': {},
|
||||
'forum':forum,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
return request.website.render("website_forum.faq", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/ask'], type='http', auth="public", website=True, multilang=True)
|
||||
def question_ask(self, forum, **post):
|
||||
values = { 'searches': {}, 'forum': forum }
|
||||
values = {
|
||||
'searches': {},
|
||||
'forum': forum,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
return request.website.render("website_forum.ask_question", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/question/<model("website.forum.post"):question>'], type='http', auth="public", website=True, multilang=True)
|
||||
|
@ -122,6 +145,7 @@ class website_forum(http.Controller):
|
|||
filters = 'question'
|
||||
values = {
|
||||
'question': question,
|
||||
'notifications': self._get_notifications(),
|
||||
'searches': post,
|
||||
'filters': filters,
|
||||
'answer_done': answer_done,
|
||||
|
@ -208,6 +232,7 @@ class website_forum(http.Controller):
|
|||
'activities': activities,
|
||||
'posts': posts,
|
||||
'vote_post':vote_ids,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
return request.website.render("website_forum.user_detail_full", values)
|
||||
|
||||
|
@ -252,6 +277,7 @@ class website_forum(http.Controller):
|
|||
values = {
|
||||
'post': post,
|
||||
'post_answer': post_answer,
|
||||
'notifications': self._get_notifications(),
|
||||
'forum': forum,
|
||||
'searches': kwargs
|
||||
}
|
||||
|
@ -278,6 +304,7 @@ class website_forum(http.Controller):
|
|||
|
||||
values = {
|
||||
'question_ids': question_ids,
|
||||
'notifications': self._get_notifications(),
|
||||
'pager': pager,
|
||||
'forum': forum,
|
||||
'searches': kwargs
|
||||
|
@ -292,6 +319,7 @@ class website_forum(http.Controller):
|
|||
tags = Tag.browse(cr, uid, obj_ids, context=context)
|
||||
values = {
|
||||
'tags': tags,
|
||||
'notifications': self._get_notifications(),
|
||||
'forum': forum,
|
||||
'searches': {'tags': True}
|
||||
}
|
||||
|
@ -305,6 +333,7 @@ class website_forum(http.Controller):
|
|||
badges = Badge.browse(cr, uid, badge_ids, context=context)
|
||||
values = {
|
||||
'badges': badges,
|
||||
'notifications': [],
|
||||
'forum': forum,
|
||||
'searches': {'badges': True}
|
||||
}
|
||||
|
@ -317,6 +346,7 @@ class website_forum(http.Controller):
|
|||
|
||||
values = {
|
||||
'badge': badge,
|
||||
'notifications': [],
|
||||
'users': users,
|
||||
'forum': forum,
|
||||
'searches': kwargs
|
||||
|
@ -338,6 +368,7 @@ class website_forum(http.Controller):
|
|||
|
||||
values = {
|
||||
'users': users,
|
||||
'notifications': self._get_notifications(),
|
||||
'pager': pager,
|
||||
'forum': forum,
|
||||
'searches': searches,
|
||||
|
@ -371,7 +402,8 @@ class website_forum(http.Controller):
|
|||
values = {
|
||||
'post': post,
|
||||
'forum': forum,
|
||||
'searches': kwarg
|
||||
'searches': kwarg,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
return request.website.render("website_forum.edit_question", values)
|
||||
|
||||
|
@ -389,7 +421,8 @@ class website_forum(http.Controller):
|
|||
'post': post,
|
||||
'post_answer': answer,
|
||||
'forum': forum,
|
||||
'searches': kwarg
|
||||
'searches': kwarg,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
return request.website.render("website_forum.edit_answer", values)
|
||||
|
||||
|
@ -422,6 +455,7 @@ class website_forum(http.Controller):
|
|||
'forum': forum,
|
||||
'searches': kwarg,
|
||||
'countries': countries,
|
||||
'notifications': self._get_notifications(),
|
||||
}
|
||||
return request.website.render("website_forum.edit_profile", values)
|
||||
|
||||
|
|
|
@ -90,7 +90,15 @@ $(document).ready(function () {
|
|||
.then(function (data) {
|
||||
$link.parents('#comment').remove();
|
||||
});
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
$('.notification_close').on('click', function (ev) {
|
||||
ev.preventDefault();
|
||||
var $link = $(ev.currentTarget);
|
||||
openerp.jsonRpc("/forum/notification_read/", 'call', {
|
||||
'notification_id': $link.attr("id")})
|
||||
return true;
|
||||
});
|
||||
|
||||
});
|
|
@ -111,13 +111,14 @@
|
|||
<div id="wrap" class="container">
|
||||
<div class="row">
|
||||
<div class="col-sm-9">
|
||||
<div class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
|
||||
<strong>Congratulation!</strong> You received the <em>New Author</em> badge!<br/>
|
||||
<div t-foreach="notifications" t-as="notification" class="alert alert-success alert-dismissable">
|
||||
<button type="button" class="close notification_close" t-att-id="notification.id" data-dismiss="alert" aria-hidden="true">&times;</button>
|
||||
<div t-field="notification.body"/>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/badge" class="fa fa-arrow-right">View Your Badges</a>
|
||||
</div>
|
||||
<t t-raw="0"/>
|
||||
</div><div class="col-sm-3" id="right-column">
|
||||
</div>
|
||||
<div class="col-sm-3" id="right-column">
|
||||
<a class="btn btn-primary btn-lg btn-block mb16" t-attf-href="/forum/#{ slug(forum) }/ask">Ask a Question</a>
|
||||
<div t-field="forum.right_column"/>
|
||||
</div>
|
||||
|
@ -418,11 +419,9 @@
|
|||
<div class="col-sm-10 col-sm-offset-2">
|
||||
<div t-foreach="reversed(object.website_message_ids)" t-as="message" id="comment" class="oe_grey" style="padding: 4px;">
|
||||
<small class="text-muted">
|
||||
<t t-if="uid == message.create_uid.id">
|
||||
<button type="button" t-att-id="message.id" class="close comment_delete">&times;</button>
|
||||
</t>
|
||||
<div t-field="message.body"/>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.create_uid.id }" t-field="message.create_uid"/>
|
||||
<button type="button" t-if="uid == message.create_uid.id" t-att-id="message.id" class="close comment_delete">&times;</button>
|
||||
<span t-field="message.body"/>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ message.create_uid.id }" t-field="message.create_uid"/>
|
||||
on <span t-field="message.date" t-field-options='{"format":"short"}'/>
|
||||
</small>
|
||||
</div>
|
||||
|
|
Loading…
Reference in New Issue