~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: 2009-12-14 04:17:46 UTC
  • Revision ID: me@williamgrant.id.au-20091214041746-eurw04xssf4cvszc
Add ivle-dev-setup, a script to do most of the heavy lifting when setting up a new dev installation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# IVLE - Informatics Virtual Learning Environment
 
2
# Copyright (C) 2007-2009 The University of Melbourne
 
3
#
 
4
# This program is free software; you can redistribute it and/or modify
 
5
# it under the terms of the GNU General Public License as published by
 
6
# the Free Software Foundation; either version 2 of the License, or
 
7
# (at your option) any later version.
 
8
#
 
9
# This program is distributed in the hope that it will be useful,
 
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
12
# GNU General Public License for more details.
 
13
#
 
14
# You should have received a copy of the GNU General Public License
 
15
# along with this program; if not, write to the Free Software
 
16
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
17
 
 
18
# Author: Nick Chadwick
 
19
 
 
20
import datetime
 
21
import ivle.database
 
22
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
 
23
 
 
24
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
 
25
                                   require_permission)
 
26
from ivle.webapp.errors import NotFound, BadRequest
 
27
 
 
28
class ProjectSetRESTView(XHTMLRESTView):
 
29
    """Rest view for a projectset.
 
30
    
 
31
    Add new, delete, edit functionality is given here."""
 
32
    template = "templates/projectset_fragment.html"
 
33
 
 
34
    def _project_url(self, project):
 
35
        return "/subjects/%s/%s/%s/+projects/%s" % \
 
36
                (self.context.offering.subject.short_name,
 
37
                 self.context.offering.semester.year,
 
38
                 self.context.offering.semester.semester,
 
39
                 project.short_name)
 
40
 
 
41
    @named_operation('edit')
 
42
    def add_project(self, req, name, short_name, deadline, synopsis):
 
43
        """Add a Project to this ProjectSet"""
 
44
        new_project = Project()
 
45
        new_project.name = unicode(name)
 
46
        new_project.short_name = unicode(short_name)
 
47
        new_project.synopsis = unicode(synopsis)
 
48
        try:
 
49
            new_project.deadline = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M:%S')
 
50
        except ValueError:
 
51
            raise BadRequest("deadline must be in YYYY-MM-DD HH:MM:ss")
 
52
        new_project.project_set = self.context
 
53
 
 
54
        req.store.add(new_project)
 
55
        req.store.flush()
 
56
    
 
57
        self.template = "templates/project_fragment.html"
 
58
        self.ctx['req'] = req
 
59
        self.ctx['project'] = new_project
 
60
 
 
61
        return {'success': True, 'projectset_id': self.context.id}