]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/controllers/user.py
b710a6c07e6cc4c2bc4b202f6938dc9fe45df8da
[bluechips.git] / bluechips / controllers / user.py
1 """
2 Calculate the current state of the books
3 """
4
5 import logging
6
7 from bluechips.lib.base import *
8
9 import sqlalchemy
10 from sqlalchemy import orm
11
12 from pylons import request
13 from pylons.decorators import validate
14
15 from formencode import validators, Schema
16
17 log = logging.getLogger(__name__)
18
19
20 class EmailSchema(Schema):
21     "Validate email updates."
22     allow_extra_fields = False
23     new_email = validators.Email()
24
25
26 class UserController(BaseController):
27     def index(self):
28         c.title = 'User Settings'
29         return render('/user/index.mako')
30
31     @validate(schema=EmailSchema(), form='index')
32     def update(self):
33         new_email = self.form_result['new_email']
34         if new_email == '':
35             new_email = None
36         request.environ['user'].email = new_email
37         meta.Session.commit()
38         if new_email is None:
39             h.flash("Removed email address.")
40         else:
41             h.flash("Updated email address to '%s'." % new_email)
42         return h.redirect_to('/')