diff --git a/gratipay/models/team/mixins/membership.py b/gratipay/models/team/mixins/membership.py index c452232941..1379f23f48 100644 --- a/gratipay/models/team/mixins/membership.py +++ b/gratipay/models/team/mixins/membership.py @@ -1,6 +1,6 @@ from __future__ import absolute_import, division, print_function, unicode_literals -from decimal import Decimal +from .takes import ZERO, PENNY class StubParticipantAdded(Exception): pass @@ -14,13 +14,13 @@ def add_member(self, member): """ if not member.is_claimed: raise StubParticipantAdded - self.set_take_for(member, Decimal('0.01'), self) + self.set_take_for(member, PENNY, self) def remove_member(self, member): """Remove a member from this team. """ - self.set_take_for(member, Decimal('0.00'), self) + self.set_take_for(member, ZERO, self) def remove_all_members(self, cursor=None): diff --git a/gratipay/models/team/mixins/takes.py b/gratipay/models/team/mixins/takes.py index 78b5a4b1ea..0eb90f5d97 100644 --- a/gratipay/models/team/mixins/takes.py +++ b/gratipay/models/team/mixins/takes.py @@ -1,7 +1,11 @@ from __future__ import absolute_import, division, print_function, unicode_literals from collections import OrderedDict -from decimal import Decimal +from decimal import Decimal as D + + +ZERO = D('0.00') +PENNY = D('0.01') class TakesMixin(object): @@ -26,7 +30,7 @@ def get_take_last_week_for(self, member): ) ORDER BY mtime DESC LIMIT 1 - """, (self.username, membername), default=Decimal('0.00')) + """, (self.username, membername), default=ZERO) def get_take_for(self, member): @@ -35,7 +39,7 @@ def get_take_for(self, member): return self.db.one( "SELECT amount FROM current_takes " "WHERE member=%s AND team=%s" , (member.username, self.username) - , default=Decimal('0.00') + , default=ZERO ) @@ -80,8 +84,8 @@ def update_taking(self, old_takes, new_takes, cursor=None, member=None): for username in set(old_takes.keys()).union(new_takes.keys()): if username == self.username: continue - old = old_takes.get(username, {}).get('actual_amount', Decimal(0)) - new = new_takes.get(username, {}).get('actual_amount', Decimal(0)) + old = old_takes.get(username, {}).get('actual_amount', ZERO) + new = new_takes.get(username, {}).get('actual_amount', ZERO) diff = new - old if diff != 0: r = (cursor or self.db).one(""" diff --git a/www/%team/distributing/%member_id.json.spt b/www/%team/distributing/%member_id.json.spt index a8eaeb8f2d..fab1cedd10 100644 --- a/www/%team/distributing/%member_id.json.spt +++ b/www/%team/distributing/%member_id.json.spt @@ -1,14 +1,12 @@ """Endpoint to record team memberships. """ -from decimal import Decimal, InvalidOperation +from decimal import InvalidOperation from aspen import Response from babel.numbers import NumberFormatError from gratipay.utils import get_team from gratipay.models.participant import Participant - -ZERO = Decimal('0.00') -A_PENNY = Decimal('0.01') +from gratipay.models.team.mixins.takes import ZERO, PENNY [--------------------] request.allow('GET', 'POST') @@ -44,7 +42,7 @@ if request.method == 'POST': # Only members themselves can set their take to something greater than # a penny. - if take not in (ZERO, A_PENNY): + if take not in (ZERO, PENNY): raise Response(400, _("You're only allowed to add or remove members, " "you can't set their takes to specific amounts.")) if take == ZERO: @@ -61,7 +59,7 @@ if request.method == 'POST': # Attempted to add a stub participant raise Response(403) - if take == A_PENNY: + if take == PENNY: if is_member: msg = _("{0} is already a member of this team.", member.username) else: