del split_dict[user]
else:
split_dict[user] = share / total
-
- for user, share in split_dict.iteritems():
- split_dict[user] = share / total
amounts_dict = dict()
winner = random.choice(amounts_dict.keys())
amounts_dict[winner] += Currency(1)
elif difference < 0:
- for i in xrange(difference):
+ for i in xrange(-difference):
winner = random.choice(amounts_dict.keys())
amounts_dict[winner] -= Currency(1)
for user, share in amounts_dict.iteritems():
s = Split(self, user, share)
- meta.Session.save(s)
+ meta.Session.add(s)
+
+ def involves(self, user):
+ "Returns True if ``user`` is involved in this expenditure."
+ return any((split.user == user) and (split.share != 0)
+ for split in self.splits)
+
+ def share(self, user):
+ "Return the share corresponding to ``user``."
+ shares = dict((split.user, split.share)
+ for split in self.splits)
+ return shares.get(user, Currency(0))
__all__ = ['Expenditure']