49
49
email = formencode.validators.Email(not_empty=False,
52
class UserEditView(XHTMLView):
52
class UserEditView(BaseFormView):
53
53
"""A form to change a user's details."""
54
54
template = 'templates/user-edit.html'
56
56
permission = 'edit'
58
def filter(self, stream, ctx):
59
return stream | HTMLFormFiller(data=ctx['data'])
60
return UserEditSchema()
62
def get_default_data(self, req):
63
return {'nick': self.context.nick,
64
'email': self.context.email
67
def save_object(self, req, data):
68
self.context.nick = data['nick']
69
self.context.email = unicode(data['email']) if data['email'] \
61
73
def populate(self, req, ctx):
62
if req.method == 'POST':
63
data = dict(req.get_fieldstorage())
65
validator = UserEditSchema()
66
data = validator.to_python(data, state=req)
67
self.context.nick = data['nick']
68
self.context.email = unicode(data['email']) if data['email'] \
71
req.throw_redirect(req.uri)
72
except formencode.Invalid, e:
73
errors = e.unpack_errors()
75
data = {'nick': self.context.nick,
76
'email': self.context.email
74
super(UserEditView, self).populate(req, ctx)
80
75
ctx['format_datetime'] = ivle.date.make_date_nice
81
76
ctx['format_datetime_short'] = ivle.date.format_datetime_for_paragraph
84
ctx['user'] = self.context
86
ctx['errors'] = errors
88
79
class UserAdminSchema(formencode.Schema):
89
80
admin = formencode.validators.StringBoolean(if_missing=False)
129
120
if data['studentid'] else None
130
121
return self.context
133
123
def populate(self, req, ctx):
134
124
super(UserAdminView, self).populate(req, ctx)