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

« back to all changes in this revision

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

Merge enforce-naming-constraints. Users, subjects, semesters, projects, groups exercises and worksheets now have restricted name character sets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import ivle.database
22
22
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
23
23
 
 
24
from ivle.webapp.base.forms import VALID_URL_NAME
24
25
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
25
26
                                   require_permission)
26
27
from ivle.webapp.errors import NotFound, BadRequest
41
42
    @named_operation('edit')
42
43
    def add_project(self, req, name, short_name, deadline, synopsis):
43
44
        """Add a Project to this ProjectSet"""
 
45
        if not VALID_URL_NAME.match(short_name):
 
46
            raise BadRequest(
 
47
                "Project names must consist of a lowercase alphanumeric "
 
48
                "character followed by any number of lowercase alphanumerics, "
 
49
                "., +, - or _.")
 
50
 
 
51
        if req.store.find(
 
52
            Project,
 
53
            Project.short_name == unicode(short_name),
 
54
            Project.project_set_id == ProjectSet.id,
 
55
            ProjectSet.offering == self.context.offering).one():
 
56
            raise BadRequest(
 
57
                "A project with that URL name already exists in this offering."
 
58
                )
 
59
 
44
60
        new_project = Project()
45
61
        new_project.name = unicode(name)
46
62
        new_project.short_name = unicode(short_name)