1
# IVLE - Informatics Virtual Learning Environment
2
# Copyright (C) 2007-2009 The University of Melbourne
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12
# GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18
# Author: Matt Giuca, Will Grant
20
from ivle.webapp.base.rest import JSONRESTView, require_permission
21
from ivle.webapp.base.xhtml import XHTMLView
22
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
23
from ivle.webapp.errors import NotFound, Unauthorized
24
from ivle.webapp.urls import RoutingError
25
from ivle.webapp import ApplicationRoot
29
# List of fields returned as part of the user JSON dictionary
30
# (as returned by the get_user action)
32
"login", "state", "unixid", "email", "nick", "fullname",
33
"admin", "studentid", "acct_exp", "pass_exp", "last_login",
37
class UserRESTView(JSONRESTView):
39
A REST interface to the user object.
42
@require_permission('view')
45
user = ivle.util.object_to_dict(user_fields_list, self.context)
46
# Convert time stamps to nice strings
47
for k in 'pass_exp', 'acct_exp', 'last_login':
48
if user[k] is not None:
49
user[k] = unicode(user[k])
51
user['local_password'] = self.context.passhash is not None
54
class UserSettingsView(XHTMLView):
55
template = 'templates/user-settings.html'
59
def populate(self, req, ctx):
60
self.plugin_scripts[Plugin] = ['settings.js']
61
self.scripts_init = ['revert_settings']
63
ctx['login'] = self.context.login
65
def root_to_user(root, segment):
66
if not segment.startswith('~'):
68
return ivle.database.User.get_by_login(root.store, segment[1:])
70
class Plugin(ViewPlugin, MediaPlugin):
72
The Plugin class for the user plugin.
75
forward_routes = [(ApplicationRoot, None, root_to_user, 1)]
76
views = [(ivle.database.User, '+settings', UserSettingsView),
77
(ivle.database.User, '+index', UserRESTView, 'api'),