diff --git a/gratipay/models/_mixin_team.py b/gratipay/models/_mixin_team.py index 9a2167a625..d3aa23caf3 100644 --- a/gratipay/models/_mixin_team.py +++ b/gratipay/models/_mixin_team.py @@ -106,7 +106,7 @@ def compute_max_this_week(self, last_week): """ return max(last_week * Decimal('2'), Decimal('1.00')) - def set_take_for(self, member, take, recorder): + def set_take_for(self, member, take, recorder, cursor=None): """Sets member's take from the team pool. """ assert self.IS_PLURAL @@ -125,13 +125,13 @@ def set_take_for(self, member, take, recorder): if take > max_this_week: take = max_this_week - self.__set_take_for(member, take, recorder) + self.__set_take_for(member, take, recorder, cursor) return take - def __set_take_for(self, member, amount, recorder): + def __set_take_for(self, member, amount, recorder, cursor=None): assert self.IS_PLURAL # XXX Factored out for testing purposes only! :O Use .set_take_for. - with self.db.get_cursor() as cursor: + with self.db.get_cursor(cursor) as cursor: # Lock to avoid race conditions cursor.run("LOCK TABLE takes IN EXCLUSIVE MODE") # Compute the current takes diff --git a/gratipay/models/participant.py b/gratipay/models/participant.py index f73b1c0e70..8514e1ee4b 100644 --- a/gratipay/models/participant.py +++ b/gratipay/models/participant.py @@ -397,11 +397,20 @@ def clear_tips_receiving(self, cursor): tipper.set_tip_to(self, '0.00', update_tippee=False, cursor=cursor) + def clear_takes(self, cursor): + """Leave all teams by zeroing all takes. + """ + for team, nmembers in self.get_teams(): + t = Participant.from_username(team) + t.set_take_for(self, Decimal(0), self, cursor) + + def clear_personal_information(self, cursor): """Clear personal information such as statement and goal. """ if self.IS_PLURAL: self.remove_all_members(cursor) + self.clear_takes(cursor) r = cursor.one(""" INSERT INTO community_members (slug, participant, ctime, name, is_member) ( @@ -411,13 +420,6 @@ def clear_personal_information(self, cursor): AND is_member IS true ); - INSERT INTO takes (ctime, member, team, amount, recorder) ( - SELECT ctime, %(username)s, team, 0.00, %(username)s - FROM current_takes - WHERE member=%(username)s - AND amount > 0 - ); - UPDATE participants SET statement='' , goal=NULL @@ -1252,6 +1254,8 @@ def take_over(self, account, have_confirmation=False): if this_is_others_last_login_account: + other.clear_takes(cursor) + # Take over tips. # ===============