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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2010-02-25 03:18:21 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225031821-mi9a2tm5679fht4d
Shuffle things around so that req.user and req.store only construct when actually retrieved, and ensure they're not retrieved for media files. Saves 50ms of DB connection time per request.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
# Author: Nick Chadwick
19
19
 
20
20
import datetime
 
21
 
 
22
import formencode
 
23
import formencode.validators
 
24
 
21
25
import ivle.database
22
26
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
23
27
 
 
28
from ivle.webapp.base.forms import VALID_URL_NAME
24
29
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
25
30
                                   require_permission)
26
31
from ivle.webapp.errors import NotFound, BadRequest
39
44
                 project.short_name)
40
45
 
41
46
    @named_operation('edit')
42
 
    def add_project(self, req, name, short_name, deadline, synopsis):
 
47
    def add_project(self, req, name, short_name, deadline, synopsis, url):
43
48
        """Add a Project to this ProjectSet"""
 
49
        if not VALID_URL_NAME.match(short_name):
 
50
            raise BadRequest(
 
51
                "Project names must consist of a lowercase alphanumeric "
 
52
                "character followed by any number of lowercase alphanumerics, "
 
53
                "., +, - or _.")
 
54
 
 
55
        if req.store.find(
 
56
            Project,
 
57
            Project.short_name == unicode(short_name),
 
58
            Project.project_set_id == ProjectSet.id,
 
59
            ProjectSet.offering == self.context.offering).one():
 
60
            raise BadRequest(
 
61
                "A project with that URL name already exists in this offering."
 
62
                )
 
63
 
 
64
        try:
 
65
            formencode.validators.URL().to_python(url)
 
66
        except formencode.Invalid, e:
 
67
            raise BadRequest(str(e))
 
68
 
44
69
        new_project = Project()
45
70
        new_project.name = unicode(name)
46
71
        new_project.short_name = unicode(short_name)
 
72
        new_project.url = unicode(url)
47
73
        new_project.synopsis = unicode(synopsis)
48
74
        try:
49
75
            new_project.deadline = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M:%S')