~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: 2010-02-25 09:34:17 UTC
  • Revision ID: matt.giuca@gmail.com-20100225093417-02z6stnx9biqpbol
Exercise display: Shows a warning if the worksheet cutoff has passed for this subject, that it will not count towards your marks.

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.database import User
25
 
import ivle.date
26
 
from ivle.pulldown_subj import enrol_user
27
24
from ivle.webapp import ApplicationRoot
28
 
from ivle.webapp.base.forms import BaseFormView, URLNameValidator
 
25
from ivle.webapp.base.forms import BaseFormView
29
26
from ivle.webapp.base.xhtml import XHTMLView
30
27
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
31
28
from ivle.webapp.admin.publishing import root_to_user, user_url
 
29
from ivle.database import User
 
30
import ivle.date
32
31
 
33
32
 
34
33
class UsersView(XHTMLView):
186
185
        ctx['user'] = self.context
187
186
        ctx['error'] = error
188
187
 
189
 
 
190
 
class UserNewSchema(formencode.Schema):
191
 
    login = URLNameValidator() # XXX: Validate uniqueness.
192
 
    admin = formencode.validators.StringBoolean(if_missing=False)
193
 
    fullname = formencode.validators.UnicodeString(not_empty=True)
194
 
    studentid = formencode.validators.UnicodeString(not_empty=False,
195
 
                                                    if_missing=None
196
 
                                                    )
197
 
    email = formencode.validators.Email(not_empty=False,
198
 
                                        if_missing=None)
199
 
 
200
 
 
201
 
class UserNewView(BaseFormView):
202
 
    """A form for admins to create new users."""
203
 
    template = 'templates/user-new.html'
204
 
    tab = 'users'
205
 
 
206
 
    def authorize(self, req):
207
 
        """Only allow access if the requesting user is an admin."""
208
 
        return req.user and req.user.admin
209
 
 
210
 
    @property
211
 
    def validator(self):
212
 
        return UserNewSchema()
213
 
 
214
 
    def get_default_data(self, req):
215
 
        return {}
216
 
 
217
 
    def save_object(self, req, data):
218
 
        data['nick'] = data['fullname']
219
 
        data['email'] = unicode(data['email']) if data['email'] else None
220
 
        userobj = User(**data)
221
 
        req.store.add(userobj)
222
 
        enrol_user(req.config, req.store, userobj)
223
 
 
224
 
        return userobj
225
 
 
226
 
 
227
188
class Plugin(ViewPlugin, MediaPlugin):
228
189
    """
229
190
    The Plugin class for the user plugin.
231
192
 
232
193
    forward_routes = (root_to_user,)
233
194
    reverse_routes = (user_url,)
234
 
    views = [(ApplicationRoot, ('users', '+index'), UsersView),
235
 
             (ApplicationRoot, ('users', '+new'), UserNewView),
 
195
    views = [(ApplicationRoot, 'users', UsersView),
236
196
             (User, '+index', UserEditView),
237
197
             (User, '+admin', UserAdminView),
238
198
             (User, '+changepassword', PasswordChangeView),