]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/templates/spend/split.mako
big interface overhaul, doesn't really add any new features yet
[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   <table>
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       <tr class="${form_cycle.next()}" id="${name}.container">
40         <td class="labelcol">
41           <label id="${name}.label" for="${name}" class="fieldlabel">${user.name}</label>
42         </td>
43         <td class="fieldcol">
44           ${h.text(name, value=percent, class_="textfield required", id=name)}
45           % if name in c.errors:
46             <span class="fielderror">${c.errors[name]}</span>
47           % endif
48         </td>
49       </tr>
50     % endfor
51     <tr class="${form_cycle.next()}" id="submit.container">
52       <td class="labelcol"></td>
53       <td class="fieldcol">
54         ${h.submit(None, 'Submit', class_="submitbutton")}
55       </td>
56     </tr>
57   </ul>
58 </form>