~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-12-02 03:54:55 UTC
  • mto: This revision was merged to the branch mainline in revision 1353.
  • Revision ID: grantw@unimelb.edu.au-20091202035455-bk7f4t0lbn2cl4ct
Add support for public views.

Show diffs side-by-side

added added

removed removed

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