]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/templates/spend/index.mako
ripped out toscawidgets, replaced with formencode, put split editing on main expendit...
[bluechips.git] / bluechips / templates / spend / index.mako
1 <%inherit file="/base.mako"/>
2
3 <%!
4     from decimal import Decimal
5 %>
6
7 <form action="${h.url_for(controller='spend', action='update', id=c.expenditure.id)}" method="post">
8   <table class="form">
9     <tr>
10       <th><label for="spender_id">Spender</label></th>
11       <td>${h.select('spender_id', c.expenditure.spender_id, c.users)}</td>
12     </tr>
13     <tr>
14       <th><label for="amount">Amount</label></th>
15       <td>$${h.text('amount', "%0.2f" % (int(c.expenditure.amount) / 100.), size=8)}</td>
16     </tr>
17     <tr>
18       <th><label for="date">Date</label></th>
19       <td>${h.text('date', c.expenditure.date.strftime('%m/%d/%Y'), size=16, class_='datepicker')}</td>
20     </tr>
21     <tr>
22       <th><label for="description">Description</label></th>
23       <td>${h.text('description', c.expenditure.description, size=64)}</td>
24     </tr>
25   </table>
26
27   <p>Change how an expenditure is split up. Enter a percentage, or something like a percentage, for each user. They don't have to add to 100.</p>
28
29   <table class="form">
30     % for user_id, user in c.users:
31       <%
32         try:
33             percent = c.values['shares-%d.amount' % user_id]
34         except TypeError:
35             if c.id != '':
36                 try:
37                     share = [s.share for s in c.expenditure.splits if s.user == user][0]
38                     percent = (Decimal(100) * Decimal(int(share)) / Decimal(int(c.expenditure.amount))).quantize(Decimal("0.001"))
39                 except IndexError:
40                     percent = 0
41             else:
42                 if user == request.environ['user']:
43                     percent = 1
44                 else:
45                     percent = 0
46       %>
47       <tr>
48         <th>
49           <label for="shares-${user_id}amount">${user.name}</label>
50         </th>
51         <td>
52           ${h.text('shares-%d.amount' % user_id, percent)}
53           ${h.hidden('shares-%d.user_id' % user_id, user.id)}
54         </td>
55       </tr>
56     % endfor
57     <tr>
58       <td colspan="2">
59         ${h.submit(None, 'Submit', class_="submitbutton")}
60       </td>
61     </tr>
62   </table>
63 </form>