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

« back to all changes in this revision

Viewing changes to ivle/webapp/userservice/__init__.py

  • Committer: William Grant
  • Date: 2010-02-16 06:57:04 UTC
  • mto: This revision was merged to the branch mainline in revision 1674.
  • Revision ID: grantw@unimelb.edu.au-20100216065704-t95a9opd2vc74uif
Display a nice error when trying to add a group with an invalid name.

Show diffs side-by-side

added added

removed removed

Lines of Context:
114
114
from ivle.auth import AuthError, authenticate
115
115
import urllib
116
116
 
 
117
from ivle.webapp.base.forms import VALID_URL_NAME
117
118
from ivle.webapp.base.views import BaseView
118
119
from ivle.webapp.base.plugins import ViewPlugin
119
120
from ivle.webapp.errors import NotFound, BadRequest, Unauthorized
139
140
            func = actions_map[self.path]
140
141
        except KeyError:
141
142
            raise NotFound()
142
 
        func(req, fields)
 
143
        try:
 
144
            func(req, fields)
 
145
        except BadRequest, e:
 
146
            req.headers_out['X-IVLE-Action-Error'] = e.message
 
147
            raise
143
148
 
144
149
    @property
145
150
    def path(self):
314
319
    # Get required fields
315
320
    projectsetid = fields.getfirst('projectsetid').value
316
321
    groupnm = fields.getfirst('groupnm').value
 
322
 
317
323
    if projectsetid is None or groupnm is None:
318
324
        raise BadRequest("Required: projectsetid, groupnm")
319
325
    groupnm = unicode(groupnm)
322
328
    except:
323
329
        raise BadRequest("projectsetid must be an integer")
324
330
 
 
331
    if not VALID_URL_NAME.match(groupnm):
 
332
        raise BadRequest(
 
333
            "Group names must consist of an alphanumeric character followed "
 
334
            "by any number of alphanumerics, ., + or -.")
 
335
 
325
336
    projectset = req.store.get(ivle.database.ProjectSet, projectsetid)
326
337
    if projectset is None:
327
338
        raise BadRequest("Invalid projectsetid")