]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/templates/spend/index.mako
cleaned up some issues with validation errors being displayed improperly
[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.currency('amount', c.expenditure.amount, 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 ii, user_row in enumerate(c.users):
31       <%
32         user_id, user = user_row
33         try:
34             percent = c.values['shares-%d.amount' % ii]
35         except TypeError:
36             if c.id != '':
37                 try:
38                     share = [s.share for s in c.expenditure.splits if s.user == user][0]
39                     percent = (Decimal(100) * Decimal(int(share)) / Decimal(int(c.expenditure.amount))).quantize(Decimal("0.001"))
40                 except IndexError:
41                     percent = 0
42             else:
43                 if user == request.environ['user']:
44                     percent = 1
45                 else:
46                     percent = 0
47       %>
48       <tr>
49         <th>
50           <label for="shares-${ii}amount">${user.name}</label>
51         </th>
52         <td>
53           ${h.text('shares-%d.amount' % ii, percent)}
54           ${h.hidden('shares-%d.user_id' % ii, user.id)}
55         </td>
56       </tr>
57     % endfor
58     <tr>
59       <td colspan="2">
60         ${h.submit(None, 'Submit', class_="submitbutton")}
61       </td>
62     </tr>
63   </table>
64 </form>