~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/user.py

  • Committer: David Coles
  • Date: 2009-08-02 08:57:44 UTC
  • mto: (1294.2.119 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: coles.david@gmail.com-20090802085744-ig0mr5fcm29ngibv
Show drop down icon for breadcrumbs with a sub-menu.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE - Informatics Virtual Learning Environment
 
2
# Copyright (C) 2007-2009 The University of Melbourne
 
3
#
 
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.
 
8
#
 
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.
 
13
#
 
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
 
17
 
 
18
# Author: Matt Giuca, Will Grant
 
19
 
 
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.admin.publishing import root_to_user, user_url
 
24
import ivle.database
 
25
import ivle.util
 
26
 
 
27
# List of fields returned as part of the user JSON dictionary
 
28
# (as returned by the get_user action)
 
29
user_fields_list = (
 
30
    "login", "state", "unixid", "email", "nick", "fullname",
 
31
    "admin", "studentid", "acct_exp", "pass_exp", "last_login",
 
32
    "svn_pass"
 
33
)
 
34
 
 
35
class UserRESTView(JSONRESTView):
 
36
    """
 
37
    A REST interface to the user object.
 
38
    """
 
39
 
 
40
    @require_permission('view')
 
41
    def GET(self, req):
 
42
        # XXX Check Caps
 
43
        user = ivle.util.object_to_dict(user_fields_list, self.context)
 
44
        # Convert time stamps to nice strings
 
45
        for k in 'pass_exp', 'acct_exp', 'last_login':
 
46
            if user[k] is not None:
 
47
                user[k] = unicode(user[k])
 
48
 
 
49
        user['local_password'] = self.context.passhash is not None
 
50
        return user
 
51
 
 
52
class UserSettingsView(XHTMLView):
 
53
    template = 'templates/user-settings.html'
 
54
    tab = 'settings'
 
55
    permission = 'edit'
 
56
 
 
57
    def populate(self, req, ctx):
 
58
        self.plugin_scripts[Plugin] = ['settings.js']
 
59
        self.scripts_init = ['revert_settings']
 
60
 
 
61
        ctx['login'] = self.context.login
 
62
 
 
63
class Plugin(ViewPlugin, MediaPlugin):
 
64
    """
 
65
    The Plugin class for the user plugin.
 
66
    """
 
67
 
 
68
    forward_routes = (root_to_user,)
 
69
    reverse_routes = (user_url,)
 
70
    views = [(ivle.database.User, '+settings', UserSettingsView),
 
71
             (ivle.database.User, '+index', UserRESTView, 'api'),
 
72
             ]
 
73
 
 
74
    media = 'user-media'