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

« back to all changes in this revision

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

Add support for custom error views. Plugins can now declare that errors
occuring in a view class or its subclasses should be passed into another view.

We start with an XHTMLErrorView used to render errors in XHTMLViews.

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, require_permission
 
20
from ivle.webapp.base.rest import JSONRESTView
21
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
 
22
from ivle.webapp.base.plugins import ViewPlugin
 
23
from ivle.webapp.errors import NotFound
24
24
import ivle.database
25
25
import ivle.util
26
26
 
42
42
        if self.context is None:
43
43
            raise NotFound()
44
44
 
45
 
    @require_permission('view')
46
45
    def GET(self, req):
47
46
        # XXX Check Caps
48
47
        user = ivle.util.object_to_dict(user_fields_list, self.context)
54
53
        user['local_password'] = self.context.passhash is not None
55
54
        return user
56
55
 
57
 
    @require_permission('edit')
58
56
    def PATCH(self, req, data):
 
57
        # XXX Check Caps
59
58
        # XXX Admins can set extra fields
60
59
        # Note: Cannot change password here (use change_password named op)
61
60
 
71
70
class UserSettingsView(XHTMLView):
72
71
    template = 'user-settings.html'
73
72
    appname = 'settings'
74
 
    permission = 'edit'
75
73
 
76
74
    def __init__(self, req, login):
77
75
        self.context = ivle.database.User.get_by_login(req.store, login)
84
82
 
85
83
        ctx['login'] = self.context.login
86
84
 
87
 
class Plugin(ViewPlugin, MediaPlugin):
 
85
class Plugin(ViewPlugin):
88
86
    """
89
87
    The Plugin class for the user plugin.
90
88
    """