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)
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
%>
<tr>
<th>