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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-03-26 12:08:44 UTC
  • mto: (1165.3.1 submissions)
  • mto: This revision was merged to the branch mainline in revision 1174.
  • Revision ID: grantw@unimelb.edu.au-20090326120844-3ia4scf4jwbixtd8
Add a POST handler to SubmitView, which does the actual submission.

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
import datetime
24
24
 
25
25
from ivle.database import (User, ProjectGroup, Offering, Subject, Semester,
26
 
                           ProjectSet)
27
 
from ivle.webapp.errors import NotFound
 
26
                           ProjectSet, Project)
 
27
from ivle.webapp.errors import NotFound, BadRequest
28
28
from ivle.webapp.base.xhtml import XHTMLView
29
29
from ivle.webapp.base.plugins import ViewPlugin
30
30
 
51
51
        raise NotImplementedError()
52
52
 
53
53
    def populate(self, req, ctx):
 
54
        if req.method == 'POST':
 
55
            data = dict(req.get_fieldstorage())
 
56
            if 'project' not in data:
 
57
                raise BadRequest('"project" argument required')
 
58
 
 
59
            try:
 
60
                projectid = int(data['project'])
 
61
            except ValueError:
 
62
                raise BadRequest('"project" must be an integer')
 
63
 
 
64
            project = req.store.find(Project, Project.id == projectid).one()
 
65
 
 
66
            if project is None:
 
67
                raise BadRequest('Specified project does not exist')
 
68
 
 
69
            project.submit(self.context, self.path, 1) # XXX: Fix rev.
 
70
 
54
71
        ctx['principal'] = self.context
55
72
        ctx['path'] = self.path
56
73
        ctx['now'] = datetime.datetime.now()