From: Scott Torborg Date: Wed, 4 Nov 2009 07:14:40 +0000 (-1000) Subject: default to an even split among residents again X-Git-Url: https://asedeno.scripts.mit.edu/gitweb/?a=commitdiff_plain;h=c419902fc831dc8077c74a8e8a88da081dbe4cf0;hp=2157c7842d2f8c5b01e3bad295dd276f505e99c4;p=bluechips.git default to an even split among residents again --- diff --git a/bluechips/controllers/spend.py b/bluechips/controllers/spend.py index 3d5f82a..57c07b8 100644 --- a/bluechips/controllers/spend.py +++ b/bluechips/controllers/spend.py @@ -47,6 +47,18 @@ class SpendController(BaseController): c.title = 'Add a New Expenditure' c.expenditure = model.Expenditure() c.expenditure.spender_id = request.environ['user'].id + + num_residents = meta.Session.query(model.User).\ + filter_by(resident=True).count() + # Pre-populate split percentages for an even split. + c.values = {} + for ii, user_row in enumerate(c.users): + user_id, user = user_row + if user.resident: + val = Decimal(100) / Decimal(num_residents) + else: + val = 0 + c.values['shares-%d.amount' % ii] = val else: c.title = 'Edit an Expenditure' c.expenditure = meta.Session.query(model.Expenditure).get(id) diff --git a/bluechips/templates/spend/index.mako b/bluechips/templates/spend/index.mako index 6198b0f..dc2f606 100644 --- a/bluechips/templates/spend/index.mako +++ b/bluechips/templates/spend/index.mako @@ -33,17 +33,11 @@ try: percent = c.values['shares-%d.amount' % ii] except TypeError: - if c.id != '': - try: - share = [s.share for s in c.expenditure.splits if s.user == user][0] - percent = (Decimal(100) * Decimal(int(share)) / Decimal(int(c.expenditure.amount))).quantize(Decimal("0.001")) - except IndexError: - percent = 0 - else: - if user == request.environ['user']: - percent = 1 - else: - percent = 0 + try: + share = [s.share for s in c.expenditure.splits if s.user == user][0] + percent = (Decimal(100) * Decimal(int(share)) / Decimal(int(c.expenditure.amount))).quantize(Decimal("0.001")) + except IndexError: + percent = 0 %>