From 24f44d38c4f6d9e92ebb0fbfce70c37c20b03332 Mon Sep 17 00:00:00 2001 From: Martin Trigaux Date: Thu, 18 Apr 2013 10:24:02 +0200 Subject: [PATCH] [REF] remove automatic code for badges bzr revid: mat@openerp.com-20130418082402-3h89j54gdvwe3dwu --- addons/gamification/badge.py | 93 ------------------------------ addons/gamification/badge_data.xml | 3 - addons/gamification/badge_view.xml | 8 +-- addons/gamification/cron.xml | 11 ---- 4 files changed, 1 insertion(+), 114 deletions(-) diff --git a/addons/gamification/badge.py b/addons/gamification/badge.py index e4c100b0bb6..56dff256402 100644 --- a/addons/gamification/badge.py +++ b/addons/gamification/badge.py @@ -261,99 +261,6 @@ class gamification_badge(osv.Model): return res - def _cron_check(self, cr, uid, context=None): - """Run cron on all automatic goals""" - ids = self.search(cr, uid, [('rule_automatic', '!=', 'manual')], context=context) - self.check_automatic(cr, uid, ids, context=context) - - def check_automatic(self, cr, uid, ids, context=None): - """Check if the badges should be deserved to users - - Only badges with an automatic rule specified are checked to be - granted, other type of badge will be skipped. Send alert messages to - the one validating the condition. - :param ids: the list of id of the badges to check - - In case of python code to execute, the user should input the name of - the function that will be excuted through safe_eval. The globals - variables available are cr (database cursor), uid (current user id) - and context. - - To create new functions in different modules, create a class extending - the 'gamification.badge.execute' class and implementing this method. The result - of the function should be a list of res.users ids (int). A badge_user - linked to this badge will be created for each of these users and a - notification will be send. - Beware that the case of user already having this badge is NOT checked - and is the responsability of the python code. - - In case of list of goals to check, the case of a user already having - this badge is checked and the user will not receive badge at each run - of this method. - """ - - context = context or {} - badge_user_obj = self.pool.get('gamification.badge.user') - - for badge in self.browse(cr, uid, ids, context=context): - - if badge.rule_automatic == 'python': - values = {'cr': cr, 'uid': uid, 'context': context, 'self': self.pool.get('gamification.badge.execute')} - result = safe_eval(badge.compute_code, values, {}) - - # code_obj = compile(badge.compute_code, '', 'exec') - # code_globals = {} - # code_locals = {'cr': cr, 'uid': uid, 'context': context, 'result': []} - # exec code_obj in code_globals, code_locals - if type(result) == list: - user_badge_ids = [ - badge_user_obj.create(cr, uid, {'user_id': user_id, 'badge_id': badge.id}, context=context) - for user_id in result - ] - self.send_badge(cr, uid, badge.id, user_badge_ids, context=context) - else: - raise osv.except_osv(_('Error!'), _('Unvalid return content from the evaluation of %s' % str(badge.compute_code))) - - elif badge.rule_automatic == 'goals': - common_users = None - for goal_type in badge.goal_type_ids: - res = self.pool.get('gamification.goal').read_group(cr, uid, [ - ('type_id', '=', goal_type.id), - ('state', '=', 'reached'), - ], ['user_id', 'state', 'type_id'], ['user_id'], context=context) - - users = [goal['user_id'][0] for goal in res] - if common_users is None: - # first type, include all - common_users = users - else: - merged_list = [user_id for user_id in users if user_id in common_users] - common_users = merged_list - - if common_users is None: - # nobody succeeded the goals - continue - - # remove users having already this badge - badge_user_not_having = [] - for user_id in common_users: - badge_user_having = badge_user_obj.search(cr, uid, [ - ('user_id', '=', user_id), - ('badge_id', '=', badge.id)], context=context) - if len(badge_user_having) == 0: - badge_user_not_having.append(user_id) - - # create badge users for users deserving the badge - user_badge_ids = [ - badge_user_obj.create(cr, uid, {'user_id': user_id, 'badge_id': badge.id}, context=context) - for user_id in badge_user_not_having - ] - self.send_badge(cr, uid, badge.id, user_badge_ids, context=context) - - # else badge.rule_automatic == 'manual': - - return True - def check_granting(self, cr, uid, user_from_id, badge_id, context=None): """Check the user can grant a badge and raise the appropriate exception if not""" diff --git a/addons/gamification/badge_data.xml b/addons/gamification/badge_data.xml index 6351f3772c6..d77a409d711 100644 --- a/addons/gamification/badge_data.xml +++ b/addons/gamification/badge_data.xml @@ -5,7 +5,6 @@ Good Job You did great at your job. everyone - manual iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAxACcAA+BYKlhAAAACXBI WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCSITq3pssgAAIABJREFUeNrtvXmcXVWZ7/191h7O UPOUVOZKQmaSMAYIiDIIiIKCXqFRabyK2tfb9qA92Gq3b3uV621xbBC1VbRFEEUmgaDM8xCmEMhI @@ -223,7 +222,6 @@ Problem Solver No one can solve challenges like you do. everyone - manual iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAVgB7ADQ3APIQAAAACXBI WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCQASe88aBAAAIABJREFUeNrsvXeYZld15vtbe59z vlj1Va7OUa1Wq6UWykIJJBAKgEDkYMCAB2xsj8O1fa/TjO0Zj+1nDL4YX3DAeEyOJuNLECAJhFBA @@ -622,7 +620,6 @@ Brilliant With your brilliant ideas, you are an inspiration to others. everyone - manual iVBORw0KGgoAAAANSUhEUgAAAIAAAACACAYAAADDPmHLAAAABmJLR0QAvQBcABUZb0TlAAAACXBI WXMAAAsTAAALEwEAmpwYAAAAB3RJTUUH3QMdCTAQSodN2wAAIABJREFUeNrsvXmUbVd93/nZe5/x zlPN9eZRehqRkBACZGywmWwwNnjAcXDbTsftOEknbnevtnt5OXHshHjICrEhcRaJzdDGYIyZBEgI diff --git a/addons/gamification/badge_view.xml b/addons/gamification/badge_view.xml index f86f104e96f..6b7b4f2628b 100644 --- a/addons/gamification/badge_view.xml +++ b/addons/gamification/badge_view.xml @@ -103,13 +103,7 @@ - + diff --git a/addons/gamification/cron.xml b/addons/gamification/cron.xml index 084a878982d..52726176841 100644 --- a/addons/gamification/cron.xml +++ b/addons/gamification/cron.xml @@ -12,16 +12,5 @@ _cron_update () - - Run Bagde Checker - 1 - days - -1 - - gamification.badge - _cron_check - () - \ No newline at end of file