From c419902fc831dc8077c74a8e8a88da081dbe4cf0 Mon Sep 17 00:00:00 2001 From: Scott Torborg Date: Tue, 3 Nov 2009 21:14:40 -1000 Subject: [PATCH] default to an even split among residents again --- bluechips/controllers/spend.py | 12 ++++++++++++ bluechips/templates/spend/index.mako | 16 +++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) 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 %> -- 2.45.2