Skip to content
This repository has been archived by the owner on Feb 8, 2018. It is now read-only.

Commit

Permalink
add a clear_takes() method to Participant
Browse files Browse the repository at this point in the history
also fixes the 4th item of #2630 (was #1920)
  • Loading branch information
Changaco committed Sep 3, 2014
1 parent f67478e commit 45d90c1
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
8 changes: 4 additions & 4 deletions gratipay/models/_mixin_team.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
18 changes: 11 additions & 7 deletions gratipay/models/participant.py
Original file line number Diff line number Diff line change
Expand Up @@ -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) (
Expand All @@ -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
Expand Down Expand Up @@ -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.
# ===============

Expand Down

0 comments on commit 45d90c1

Please sign in to comment.