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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2010-02-11 03:17:12 UTC
  • Revision ID: matt.giuca@gmail.com-20100211031712-79c74lgh3mj7507s
docs: Tour of IVLE: Added lecturer tour (complete).

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
 
 
25
21
import ivle.database
26
22
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
27
23
 
28
 
from ivle.webapp.base.forms import VALID_URL_NAME
29
24
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
30
25
                                   require_permission)
31
26
from ivle.webapp.errors import NotFound, BadRequest
44
39
                 project.short_name)
45
40
 
46
41
    @named_operation('edit')
47
 
    def add_project(self, req, name, short_name, deadline, synopsis, url):
 
42
    def add_project(self, req, name, short_name, deadline, synopsis):
48
43
        """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
 
 
69
44
        new_project = Project()
70
45
        new_project.name = unicode(name)
71
46
        new_project.short_name = unicode(short_name)
72
 
        new_project.url = unicode(url)
73
47
        new_project.synopsis = unicode(synopsis)
74
48
        try:
75
49
            new_project.deadline = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M:%S')