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

« back to all changes in this revision

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

  • Committer: Nick Chadwick
  • Date: 2009-02-23 23:11:26 UTC
  • mto: (1099.1.227 exercise-ui)
  • mto: This revision was merged to the branch mainline in revision 1100.
  • Revision ID: chadnickbok@gmail.com-20090223231126-zfb5wfw8jnxazefl
Fixed database so that lecturers can edit worksheets

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.errors import NotFound, Unauthorized
23
24
import ivle.database
24
25
import ivle.util
25
26
 
38
39
    def __init__(self, req, login):
39
40
        super(UserRESTView, self).__init__(self, req, login)
40
41
        self.context = ivle.database.User.get_by_login(req.store, login)
 
42
        if self.context is None:
 
43
            raise NotFound()
41
44
 
 
45
    @require_permission('view')
42
46
    def GET(self, req):
43
47
        # XXX Check Caps
44
48
        user = ivle.util.object_to_dict(user_fields_list, self.context)
50
54
        user['local_password'] = self.context.passhash is not None
51
55
        return user
52
56
 
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
57
class UserSettingsView(XHTMLView):
68
58
    template = 'user-settings.html'
69
59
    appname = 'settings'
 
60
    permission = 'edit'
70
61
 
71
62
    def __init__(self, req, login):
72
63
        self.context = ivle.database.User.get_by_login(req.store, login)
 
64
        if self.context is None:
 
65
            raise NotFound()
73
66
 
74
67
    def populate(self, req, ctx):
75
 
        if not self.context:
76
 
            raise NotFound()
77
 
 
78
68
        self.plugin_scripts[Plugin] = ['settings.js']
79
69
        req.scripts_init = ['revert_settings']
80
70
 
81
71
        ctx['login'] = self.context.login
82
72
 
83
 
class Plugin(BasePlugin):
 
73
class Plugin(ViewPlugin, MediaPlugin):
84
74
    """
85
75
    The Plugin class for the user plugin.
86
76
    """