]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/controllers/spend.py
Move title into controller to encourage template reuse
[bluechips.git] / bluechips / controllers / spend.py
1 """
2 Handle expenditures
3 """
4
5 import logging
6
7 from bluechips.lib.base import *
8 from bluechips.widgets import spend
9
10 from pylons import request
11
12 log = logging.getLogger(__name__)
13
14 class SpendController(BaseController):
15     def index(self):
16         c.title = 'Add a New Expenditure'
17         
18         c.expenditure = dict()
19         c.expenditure['spender'] = request.environ['user']
20         
21         return render('/spend/index.mako')
22     
23     @validate(form=spend.new_spend_form, error_handler='index')
24     def new(self):
25         e = model.Expenditure()
26         update_sar(e, self.form_result)
27         meta.Session.save(e)
28         
29         e.even_split()
30         meta.Session.commit()
31         
32         h.flash('Expenditure recorded.')
33         h.flash("""Want to do something unusual?
34
35 <ul id="expenditure_options">
36   <li>%s</li>
37   <li>%s</li>
38 </ul>""" % (h.link_to('Change the split', h.url_for(controller='spend',
39                                                    action='split',
40                                                    id=e.id)),
41            h.link_to('Spin off a subitem', h.url_for(controller='spend',
42                                                      action='subitem',
43                                                      id=e.id))))
44         
45         return h.redirect_to('/')