]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/templates/spend/split.mako
41568e5e2e886ef1c362b6a63da207a23ec79547
[bluechips.git] / bluechips / templates / spend / split.mako
1 <%inherit file="/base.mako"/>
2
3 <%!
4 import itertools
5 from decimal import Decimal
6 %>
7
8 <%
9 form_cycle = itertools.cycle(['even', 'odd'])
10 %>
11
12 ## ToscaWidgets doesn't support dynamically generating the form fields
13 ## themselves, so I'm mimicing its style but generating the form by
14 ## hand
15
16 <p>Change how an expenditure is split up. Enter a percentage, or
17 something like a percentage, for each user. They don't have to add to
18 100.</p>
19
20 <p>You're editing an expenditure of ${c.expenditure.amount} by
21 ${c.expenditure.spender.name} on ${c.expenditure.date}, described as
22 "${c.expenditure.description}"</p>
23
24 ${h.form('', method='post')}
25 <form>
26   <ul class="field_list">
27     % for user in c.users:
28     <%
29     name = user.username
30     try:
31         percent = c.values[name]
32     except TypeError:
33         try:
34             share = [s.share for s in c.expenditure.splits if s.user == user][0]
35             percent = (Decimal(100) * Decimal(int(share)) / Decimal(int(c.expenditure.amount))).quantize(Decimal("0.001"))
36         except IndexError:
37             percent = Decimal(0)
38     %>\
39     <li class="${form_cycle.next()}" id="${name}.container">
40       <label id="${name}.label" for="${name}" class="fieldlabel">${user.name}</label>
41       ${h.text(name, value=percent, class_="textfield required", id=name)}
42       % if name in c.errors:
43       <span class="fielderror">${c.errors[name]}</span>
44       % endif
45     </li>
46     % endfor
47     <li class="${form_cycle.next()}" id="submit.container">
48       ${h.submit(None, 'Submit', class_="submitbutton")}
49     </li>
50   </ul>
51 </form>