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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-12-08 06:56:53 UTC
  • Revision ID: matt.giuca@gmail.com-20091208065653-wzeowlzx2a0471l3
Enrolments view: Use a pretty table instead of a bulleted list for user lists.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import formencode.validators
22
22
from genshi.filters import HTMLFormFiller
23
23
 
24
 
from ivle.webapp import ApplicationRoot
25
24
from ivle.webapp.base.rest import JSONRESTView, require_permission
26
25
from ivle.webapp.base.xhtml import XHTMLView
27
26
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
28
27
from ivle.webapp.admin.publishing import root_to_user, user_url
29
 
from ivle.database import User
30
28
import ivle.database
31
29
import ivle.date
32
30
import ivle.util
33
31
 
34
 
 
35
 
class UsersView(XHTMLView):
36
 
    """A list of all IVLE users."""
37
 
    template = 'templates/users.html'
38
 
    tab = 'users'
39
 
    breadcrumb_text = 'Users'
40
 
 
41
 
    def authorize(self, req):
42
 
        return req.user and req.user.admin
43
 
 
44
 
    def populate(self, req, ctx):
45
 
        ctx['req'] = req
46
 
        ctx['users'] = req.store.find(User).order_by(User.login)
47
 
 
48
 
 
49
32
# List of fields returned as part of the user JSON dictionary
50
33
# (as returned by the get_user action)
51
34
user_fields_list = (
79
62
class UserEditView(XHTMLView):
80
63
    """A form to change a user's details."""
81
64
    template = 'templates/user-edit.html'
82
 
    tab = 'users'
 
65
    tab = 'settings'
83
66
    permission = 'edit'
84
67
 
85
68
    def filter(self, stream, ctx):
114
97
 
115
98
class UserAdminSchema(formencode.Schema):
116
99
    admin = formencode.validators.StringBoolean(if_missing=False)
117
 
    disabled = formencode.validators.StringBoolean(if_missing=False)
118
100
    fullname = formencode.validators.UnicodeString(not_empty=True)
119
101
    studentid = formencode.validators.UnicodeString(not_empty=False,
120
102
                                                    if_missing=None
123
105
class UserAdminView(XHTMLView):
124
106
    """A form for admins to change more of a user's details."""
125
107
    template = 'templates/user-admin.html'
126
 
    tab = 'users'
 
108
    tab = 'settings'
127
109
 
128
110
    def authorize(self, req):
129
111
        """Only allow access if the requesting user is an admin."""
130
 
        return req.user and req.user.admin
 
112
        return req.user.admin
131
113
 
132
114
    def filter(self, stream, ctx):
133
115
        return stream | HTMLFormFiller(data=ctx['data'])
139
121
                validator = UserAdminSchema()
140
122
                data = validator.to_python(data, state=req)
141
123
 
142
 
                if self.context is req.user:
143
 
                    # Admin checkbox is disabled -- assume unchanged
144
 
                    data['admin'] = self.context.admin
145
 
                    data['disabled'] = self.context.state == u'disabled'
146
 
                else:
147
 
                    self.context.admin = data['admin']
148
 
                    if self.context.state in (u'enabled', u'disabled'):
149
 
                        self.context.state = (u'disabled' if data['disabled']
150
 
                                else u'enabled')
 
124
                self.context.admin = data['admin']
151
125
                self.context.fullname = data['fullname'] \
152
126
                                        if data['fullname'] else None
153
127
                self.context.studentid = data['studentid'] \
158
132
                errors = e.unpack_errors()
159
133
        else:
160
134
            data = {'admin': self.context.admin,
161
 
                    'disabled': self.context.state == u'disabled',
162
135
                    'fullname': self.context.fullname,
163
136
                    'studentid': self.context.studentid,
164
137
                   }
166
139
 
167
140
        ctx['req'] = req
168
141
        ctx['user'] = self.context
169
 
        # Disable the Admin checkbox if editing oneself
170
 
        ctx['disable_admin'] = self.context is req.user
171
142
        ctx['data'] = data
172
143
        ctx['errors'] = errors
173
144
 
174
145
class PasswordChangeView(XHTMLView):
175
146
    """A form to change a user's password, with knowledge of the old one."""
176
147
    template = 'templates/user-password-change.html'
177
 
    tab = 'users'
 
148
    tab = 'settings'
178
149
    permission = 'edit'
179
150
 
180
151
    def authorize(self, req):
208
179
class PasswordResetView(XHTMLView):
209
180
    """A form to reset a user's password, without knowledge of the old one."""
210
181
    template = 'templates/user-password-reset.html'
211
 
    tab = 'users'
 
182
    tab = 'settings'
212
183
 
213
184
    def authorize(self, req):
214
185
        """Only allow access if the requesting user is an admin."""
215
 
        return req.user and req.user.admin
 
186
        return req.user.admin
216
187
 
217
188
    def populate(self, req, ctx):
218
189
        error = None
237
208
 
238
209
    forward_routes = (root_to_user,)
239
210
    reverse_routes = (user_url,)
240
 
    views = [(ApplicationRoot, 'users', UsersView),
241
 
             (ivle.database.User, '+index', UserEditView),
 
211
    views = [(ivle.database.User, '+edit', UserEditView),
242
212
             (ivle.database.User, '+admin', UserAdminView),
243
213
             (ivle.database.User, '+changepassword', PasswordChangeView),
244
214
             (ivle.database.User, '+resetpassword', PasswordResetView),
245
215
             (ivle.database.User, '+index', UserRESTView, 'api'),
246
216
             ]
247
217
 
248
 
    tabs = [
249
 
        ('users', 'Users', 'Display and edit all users',
250
 
         'users.png', 'users', 90, True)
251
 
    ]
252
 
 
253
218
    public_forward_routes = forward_routes
254
219
    public_reverse_routes = reverse_routes
255
220