]> asedeno.scripts.mit.edu Git - bluechips.git/blob - bluechips/controllers/user.py
added interface to edit email address
[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         return render('/user/index.mako')
29
30     @validate(schema=EmailSchema(), form='index')
31     def update(self):
32         new_email = self.form_result['new_email']
33         if new_email == '':
34             new_email = None
35         request.environ['user'].email = new_email
36         meta.Session.commit()
37         if new_email is None:
38             h.flash("Removed email address.")
39         else:
40             h.flash("Updated email address to '%s'." % new_email)
41         return h.redirect_to('/')