From 35c7f4814d08baa8772f0971051148398dab1e45 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Tue, 15 Apr 2014 15:48:09 +0200 Subject: [PATCH] Allow overwrite of the serialising method to exclude some categories in the challenge search bzr revid: mat@openerp.com-20140415134809-uconkvnp0z32jxjs --- addons/gamification/models/res_users.py | 15 ++++++++------- addons/website_forum/models/gamification.py | 1 + addons/website_forum/models/res_users.py | 8 ++++++++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/addons/gamification/models/res_users.py b/addons/gamification/models/res_users.py index 85cc18636f0..faca484dfb3 100644 --- a/addons/gamification/models/res_users.py +++ b/addons/gamification/models/res_users.py @@ -61,13 +61,12 @@ class res_users_gamification_group(osv.Model): challenge_obj.generate_goals_from_challenge(cr, SUPERUSER_ID, challenge_ids, context=context) return write_res - # def get_goals_todo_info(self, cr, uid, context=None): + def get_serialised_gamification_summary(self, cr, uid, excluded_categories=None, context=None): + return self._serialised_goals_summary(cr, uid, user_id=uid, excluded_categories=excluded_categories, context=context) - def get_serialised_gamification_summary(self, cr, uid, context=None): - return self._serialised_goals_summary(cr, uid, user_id=uid, context=context) - - def _serialised_goals_summary(self, cr, uid, user_id, context=None): + def _serialised_goals_summary(self, cr, uid, user_id, excluded_categories=None, context=None): """Return a serialised list of goals assigned to the user, grouped by challenge + :excluded_categories: list of challenge categories to exclude in search [ { @@ -81,9 +80,11 @@ class res_users_gamification_group(osv.Model): """ all_goals_info = [] challenge_obj = self.pool.get('gamification.challenge') - + domain = [('user_ids', 'in', uid), ('state', '=', 'inprogress')] + if excluded_categories and isinstance(excluded_categories, list): + domain.append(('category', 'not in', excluded_categories)) user = self.browse(cr, uid, uid, context=context) - challenge_ids = challenge_obj.search(cr, uid, [('user_ids', 'in', uid), ('state', '=', 'inprogress')], context=context) + challenge_ids = challenge_obj.search(cr, uid, domain, context=context) for challenge in challenge_obj.browse(cr, uid, challenge_ids, context=context): # serialize goals info to be able to use it in javascript lines = challenge_obj._get_serialized_challenge_lines(cr, uid, challenge, user_id, restrict_top=MAX_VISIBILITY_RANKING, context=context) diff --git a/addons/website_forum/models/gamification.py b/addons/website_forum/models/gamification.py index cffe52c4848..20eaca9851e 100644 --- a/addons/website_forum/models/gamification.py +++ b/addons/website_forum/models/gamification.py @@ -12,6 +12,7 @@ class gamification_challenge(osv.Model): return res + class Badge(osv.Model): _inherit = 'gamification.badge' _columns = { diff --git a/addons/website_forum/models/res_users.py b/addons/website_forum/models/res_users.py index 3170fedf50a..58d43a58191 100644 --- a/addons/website_forum/models/res_users.py +++ b/addons/website_forum/models/res_users.py @@ -37,3 +37,11 @@ class Users(osv.Model): for user in self.browse(cr, uid, ids, context=context): self.write(cr, uid, [user.id], {'karma': user.karma + karma}, context=context) return True + + def get_serialised_gamification_summary(self, cr, uid, excluded_categories=None, context=None): + if isinstance(excluded_categories, list): + if 'forum' not in excluded_categories: + excluded_categories.append('forum') + else: + excluded_categories = ['forum'] + return super(Users, self).get_serialised_gamification_summary(cr, uid, excluded_categories=excluded_categories, context=context) \ No newline at end of file