~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:
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.publishing 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()
 
58
        self.plugin_scripts[Plugin] = ['settings.js']
 
59
        self.scripts_init = ['revert_settings']
77
60
 
78
 
        req.scripts = [
79
 
            "/media/settings/settings.js",
80
 
            "/media/common/json2.js",
81
 
            "/media/common/util.js",
82
 
        ]
83
 
        req.scripts_init = [
84
 
            "revert_settings"
85
 
        ]
86
61
        ctx['login'] = self.context.login
87
62
 
88
 
class Plugin(BasePlugin):
 
63
class Plugin(ViewPlugin, MediaPlugin):
89
64
    """
90
65
    The Plugin class for the user plugin.
91
66
    """
92
 
    # Magic attribute: urls
93
 
    # Sequence of pairs/triples of
94
 
    # (regex str, handler class, kwargs dict)
95
 
    # The kwargs dict is passed to the __init__ of the view object
96
 
    urls = [
97
 
        ('users/:login/+settings', UserSettingsView),
98
 
        ('api/users/:login', UserRESTView),
99
 
    ]
 
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'