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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-07-05 05:55:33 UTC
  • mto: (1294.4.2 ui-the-third)
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20090705055533-9gs58527qs6u4zi0
Add a new root breadcrumb image, and a pathetic breadcrumb chevron.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
# Author: Matt Giuca, Will Grant
19
19
 
20
 
from ivle.webapp.base.rest import JSONRESTView
 
20
from ivle.webapp.base.rest import JSONRESTView, require_permission
21
21
from ivle.webapp.base.xhtml import XHTMLView
22
 
from ivle.webapp.base.plugins import BasePlugin
 
22
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
 
23
from ivle.webapp.admin.traversal import root_to_user, user_url
23
24
import ivle.database
24
25
import ivle.util
25
26
 
27
28
# (as returned by the get_user action)
28
29
user_fields_list = (
29
30
    "login", "state", "unixid", "email", "nick", "fullname",
30
 
    "rolenm", "studentid", "acct_exp", "pass_exp", "last_login",
 
31
    "admin", "studentid", "acct_exp", "pass_exp", "last_login",
31
32
    "svn_pass"
32
33
)
33
34
 
35
36
    """
36
37
    A REST interface to the user object.
37
38
    """
38
 
    def __init__(self, req, login):
39
 
        super(UserRESTView, self).__init__(self, req, login)
40
 
        self.context = ivle.database.User.get_by_login(req.store, login)
41
39
 
 
40
    @require_permission('view')
42
41
    def GET(self, req):
43
42
        # XXX Check Caps
44
43
        user = ivle.util.object_to_dict(user_fields_list, self.context)
50
49
        user['local_password'] = self.context.passhash is not None
51
50
        return user
52
51
 
53
 
    def PATCH(self, req, data):
54
 
        # XXX Check Caps
55
 
        # XXX Admins can set extra fields
56
 
        # Note: Cannot change password here (use change_password named op)
57
 
 
58
 
        for f in user_fields_list:
59
 
            try:
60
 
                field = data[f]
61
 
                if isinstance(field, str):
62
 
                    field = unicode(field)
63
 
                setattr(self.context, f, field)
64
 
            except KeyError:
65
 
                continue
66
 
 
67
52
class UserSettingsView(XHTMLView):
68
 
    template = 'user-settings.html'
69
 
    appname = 'settings'
70
 
 
71
 
    def __init__(self, req, login):
72
 
        self.context = ivle.database.User.get_by_login(req.store, login)
 
53
    template = 'templates/user-settings.html'
 
54
    tab = 'settings'
 
55
    permission = 'edit'
73
56
 
74
57
    def populate(self, req, ctx):
75
 
        if not self.context:
76
 
            raise NotFound()
77
 
 
78
58
        self.plugin_scripts[Plugin] = ['settings.js']
79
 
        req.scripts_init = ['revert_settings']
 
59
        self.scripts_init = ['revert_settings']
80
60
 
81
61
        ctx['login'] = self.context.login
82
62
 
83
 
class Plugin(BasePlugin):
 
63
class Plugin(ViewPlugin, MediaPlugin):
84
64
    """
85
65
    The Plugin class for the user plugin.
86
66
    """
87
 
    # Magic attribute: urls
88
 
    # Sequence of pairs/triples of
89
 
    # (regex str, handler class, kwargs dict)
90
 
    # The kwargs dict is passed to the __init__ of the view object
91
 
    urls = [
92
 
        ('~:login/+settings', UserSettingsView),
93
 
        ('api/~:login', UserRESTView),
94
 
    ]
 
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
             ]
95
73
 
96
74
    media = 'user-media'