[ADD] added dependancy of gamification mudule, add badge functionality.
bzr revid: tpa@tinyerp.com-20140307093430-psyu9zcjox172ctp
This commit is contained in:
parent
d36175eba0
commit
f5b14f1122
|
@ -29,7 +29,7 @@
|
|||
Ask questions, get answers, no distractions
|
||||
""",
|
||||
'author': 'OpenERP SA',
|
||||
'depends': ['website', 'website_mail'],
|
||||
'depends': ['website', 'website_mail', 'gamification'],
|
||||
'data': [
|
||||
'data/forum_data.xml',
|
||||
'views/website_forum.xml',
|
||||
|
|
|
@ -241,7 +241,7 @@ class website_forum(http.Controller):
|
|||
def tag_questions(self, forum, tag, page=1, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
step = 10
|
||||
pager = request.website.pager(url="/forum/", total=len(tag.post_ids), page=page, step=step, scope=10)
|
||||
pager = request.website.pager(url="/forum/%s/tag" % slug(forum), total=len(tag.post_ids), page=page, step=step, scope=10)
|
||||
|
||||
values = {
|
||||
'question_ids': tag.post_ids,
|
||||
|
@ -265,6 +265,37 @@ class website_forum(http.Controller):
|
|||
}
|
||||
return request.website.render("website_forum.tag", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/badges'], type='http', auth="public", website=True, multilang=True)
|
||||
def badges(self, forum, **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
Badge = request.registry['gamification.badge']
|
||||
badge_ids = Badge.search(cr, uid, [('forum', '=', True)], context=context)
|
||||
badges = Badge.browse(cr, uid, badge_ids, context=context)
|
||||
values = {
|
||||
'badges': badges,
|
||||
'forum': forum,
|
||||
'searches': {'badges': True}
|
||||
}
|
||||
return request.website.render("website_forum.badge", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/badge/<model("gamification.badge"):badge>'], type='http', auth="public", website=True, multilang=True)
|
||||
def badge_users(self, forum, badge, page=1, **kwargs):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
step = 10
|
||||
pager = request.website.pager(url="/forum/%s/badge" % slug(forum), total=len(badge.owner_ids), page=page, step=step, scope=10)
|
||||
|
||||
users = [badge_user.user_id for badge_user in badge.owner_ids]
|
||||
print users
|
||||
values = {
|
||||
'badge': badge,
|
||||
'users': users,
|
||||
'pager': pager,
|
||||
'forum': forum,
|
||||
'searches': kwargs
|
||||
}
|
||||
|
||||
return request.website.render("website_forum.badge_user", values)
|
||||
|
||||
@http.route(['/forum/<model("website.forum"):forum>/users', '/forum/users/page/<int:page>'], type='http', auth="public", website=True, multilang=True)
|
||||
def users(self, forum, page=1, **searches):
|
||||
cr, uid, context = request.cr, request.uid, request.context
|
||||
|
@ -297,9 +328,9 @@ class website_forum(http.Controller):
|
|||
Vote.unlink(cr, uid, vote_ids, context=context)
|
||||
else:
|
||||
Vote.create(cr, uid, {
|
||||
'post_id': post_id,
|
||||
'user_id': uid,
|
||||
'vote': post.get('vote'),
|
||||
}, context=context)
|
||||
'post_id': post_id,
|
||||
'user_id': uid,
|
||||
'vote': post.get('vote'),
|
||||
}, context=context)
|
||||
|
||||
return werkzeug.utils.redirect("/forum/%s/question/%s" % (slug(forum),post.get('question_id')))
|
||||
|
|
|
@ -174,6 +174,18 @@ class Post(osv.Model):
|
|||
|
||||
class Users(osv.Model):
|
||||
_inherit = 'res.users'
|
||||
|
||||
def _get_user_badge_level(self, cr, uid, ids, name, args, context=None):
|
||||
"""Return total badge per level of users"""
|
||||
result = dict.fromkeys(ids, False)
|
||||
badge_user_obj = self.pool.get('gamification.badge.user')
|
||||
for id in ids:
|
||||
result[id] = {
|
||||
'gold_badge': badge_user_obj.search(cr, uid, [('badge_id.level', '=', 'gold'), ('user_id', '=', id)], context=context, count=True),
|
||||
'silver_badge': badge_user_obj.search(cr, uid, [('badge_id.level', '=', 'silver'), ('user_id', '=', id)], context=context, count=True),
|
||||
'bronze_badge': badge_user_obj.search(cr, uid, [('badge_id.level', '=', 'bronze'), ('user_id', '=', id)], context=context, count=True),
|
||||
}
|
||||
return result
|
||||
_columns = {
|
||||
# TODO: Remove these 3 field and compute number in /user controller
|
||||
'question_ids':fields.one2many('website.forum.post', 'create_uid', 'Questions', domain=[('parent_id', '=', False)]),
|
||||
|
@ -186,10 +198,12 @@ class Users(osv.Model):
|
|||
|
||||
'create_date': fields.datetime('Create Date', select=True, readonly=True),
|
||||
'karma': fields.integer('Karma'), # Use Gamification for this
|
||||
'forum': fields.boolean('Is Forum Member')
|
||||
'forum': fields.boolean('Is Forum Member'),
|
||||
|
||||
# TODO: 'tag_ids':fields.function()
|
||||
# Badges : use the gamification module
|
||||
'badges': fields.one2many('gamification.badge.user', 'user_id', 'Badges'),
|
||||
'gold_badge':fields.function(_get_user_badge_level, string="Number of gold badges", type='integer', multi='badge_level'),
|
||||
'silver_badge':fields.function(_get_user_badge_level, string="Number of silver badges", type='integer', multi='badge_level'),
|
||||
'bronze_badge':fields.function(_get_user_badge_level, string="Number of bronze badges", type='integer', multi='badge_level'),
|
||||
}
|
||||
_defaults = {
|
||||
'forum': False
|
||||
|
@ -223,6 +237,17 @@ class Vote(osv.Model):
|
|||
self.pool['website.forum.post'].create_activity(cr, uid, [int(vals.get('post_id'))], method='vote', context=context)
|
||||
return vote_id
|
||||
|
||||
class Badge(osv.Model):
|
||||
_inherit = 'gamification.badge'
|
||||
_columns = {
|
||||
'forum': fields.boolean('Is Forum Badge'),
|
||||
#NOTE: we can create new BadgeLevel object instead of selection
|
||||
'level': fields.selection([('gold', 'gold'), ('silver', 'silver'), ('bronze', 'bronze')], 'Badge Level'),
|
||||
}
|
||||
_defaults = {
|
||||
'forum': False
|
||||
}
|
||||
|
||||
class ForumActivity(osv.Model):
|
||||
_name = "website.forum.activity"
|
||||
_description = "Activity"
|
||||
|
|
|
@ -95,8 +95,8 @@
|
|||
<li t-att-class="searches.get('tags') and 'active' or '' ">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/tags">Tags</a>
|
||||
</li>
|
||||
<li t-att-class="searches.get('badge') and 'active' or '' ">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/badge">Badges</a>
|
||||
<li t-att-class="searches.get('badges') and 'active' or '' ">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/badges">Badges</a>
|
||||
</li>
|
||||
</ul>
|
||||
<form class="navbar-form navbar-right" role="search" t-attf-action="/forum/#{ slug(forum) }" method="get">
|
||||
|
@ -229,17 +229,17 @@
|
|||
|
||||
<template id="user_detail">
|
||||
<div>
|
||||
<span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}' />
|
||||
<span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/>
|
||||
<div>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(user) }" t-field="user.name"/>
|
||||
<t t-raw="separator or ', '"/>
|
||||
<b>11 badges:</b>
|
||||
<span class="fa fa-certificate badge-gold"></span>
|
||||
1
|
||||
<span class="fa fa-certificate badge-silver"></span>
|
||||
10
|
||||
<span class="fa fa-certificate badge-bronze"></span>
|
||||
5
|
||||
<b><t t-esc="len(user.badges)"/> badges:</b>
|
||||
<span class="fa fa-certificate badge-gold"/>
|
||||
<t t-esc="user.gold_badge"/>
|
||||
<span class="fa fa-certificate badge-silver"/>
|
||||
<t t-esc="user.silver_badge"/>
|
||||
<span class="fa fa-certificate badge-bronze"/>
|
||||
<t t-esc="user.bronze_badge"/>
|
||||
<br/>
|
||||
<t t-raw="0"/>
|
||||
</div>
|
||||
|
@ -464,6 +464,49 @@
|
|||
</t>
|
||||
</template>
|
||||
|
||||
<template id="badge">
|
||||
<t t-call="website_forum.header">
|
||||
<h1 class="mt0">
|
||||
Users with Badges
|
||||
</h1>
|
||||
<div class="mt16" t-foreach="badges" t-as="badge">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge) }" class="badge pull-left">
|
||||
<span t-field="badge.name" />
|
||||
</a>
|
||||
<span style="margin-left:5px">
|
||||
X <t t-esc="len(badge.owner_ids)"/>
|
||||
</span>
|
||||
<span t-field="badge.description" style="margin-left:20px"/>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="badge_user">
|
||||
<t t-call="website_forum.header">
|
||||
<h3 class="mt32 mb32">
|
||||
<b>Badge "<span t-field="badge.name"/>"</b>
|
||||
</h3>
|
||||
<div>
|
||||
<span class="pull-left badge" t-field="badge.name"/>
|
||||
<span t-field="badge.description" style="margin-left:20px"/>
|
||||
</div>
|
||||
<h4 class="mt32">
|
||||
<t class="pull-left" t-esc="len(badge.owner_ids)"/>
|
||||
<span t-if="len(badge.owner_ids)>1">users</span>
|
||||
<span t-if="len(badge.owner_ids)<=1">user</span>
|
||||
received this badge:
|
||||
</h4>
|
||||
<div class="row">
|
||||
<div class="col-sm-3 mt16" t-foreach="users" t-as="user">
|
||||
<span t-field="user.image" t-field-options='{"widget": "image", "class":"pull-left img img-circle img-avatar"}'/>
|
||||
<div>
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/user/#{ slug(user) }" t-field="user.name"/>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</t>
|
||||
</template>
|
||||
|
||||
<template id="users">
|
||||
<t t-call="website_forum.header">
|
||||
<div class="row">
|
||||
|
@ -542,6 +585,9 @@
|
|||
<li>
|
||||
<a href="#activity" data-toggle="tab">Activity</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#badges" data-toggle="tab">Badges</a>
|
||||
</li>
|
||||
<li>
|
||||
<a href="#followed_question" data-toggle="tab">Followed Question</a>
|
||||
</li>
|
||||
|
@ -559,6 +605,9 @@
|
|||
<div class="tab-pane" id="karma">
|
||||
<h1>Karma</h1>
|
||||
</div>
|
||||
<div class="tab-pane" id="badges">
|
||||
<t t-call="website_forum.user_badges" />
|
||||
</div>
|
||||
<div class="tab-pane" id="followed_question">
|
||||
<h1>Followed Questions</h1>
|
||||
</div>
|
||||
|
@ -587,5 +636,16 @@
|
|||
</ul>
|
||||
</template>
|
||||
|
||||
<template id="user_badges">
|
||||
<div class="col-sm-3 mt16" t-foreach="user.badges" t-as="badge">
|
||||
<a t-attf-href="/forum/#{ slug(forum) }/badge/#{ slug(badge.badge_id) }" class="badge">
|
||||
<span t-field="badge.badge_id.name" />
|
||||
</a>
|
||||
<span>
|
||||
X <t t-esc="len(badge.badge_id.owner_ids)"/>
|
||||
</span>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
|
Loading…
Reference in New Issue