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

1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
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
1316.1.2 by David Coles
Allow specification of a deadline when creating new projects.
20
import datetime
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
21
import ivle.database
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
22
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
23
24
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
25
                                   require_permission)
1316.1.2 by David Coles
Allow specification of a deadline when creating new projects.
26
from ivle.webapp.errors import NotFound, BadRequest
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
27
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
28
class ProjectSetRESTView(XHTMLRESTView):
29
    """Rest view for a projectset.
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
30
    
31
    Add new, delete, edit functionality is given here."""
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
32
    template = "templates/projectset_fragment.html"
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
33
    
34
    def __init__(self, req, subject, year, semester, projectset):
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
35
        self.context = req.store.find(ProjectSet,
36
            ProjectSet.id == int(projectset),
37
            ProjectSet.offering_id == Offering.id,
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
38
            Offering.subject_id == Subject.id,
39
            Subject.short_name == unicode(subject),
40
            Offering.semester_id == Semester.id,
41
            Semester.year == unicode(year),
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
42
            Semester.semester == unicode(semester)).one()
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
43
        
44
        if self.context is None:
45
            raise NotFound()
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
46
47
    def _project_url(self, project):
1165.3.15 by William Grant
Remove the ProjectSet from Project URLs.
48
        return "/subjects/%s/%s/%s/+projects/%s" % \
49
                (self.context.offering.subject.short_name,
1165.3.11 by Nick Chadwick
Fixed a broken link when adding a new project.
50
                 self.context.offering.semester.year,
51
                 self.context.offering.semester.semester,
52
                 project.short_name)
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
53
54
    @named_operation('edit')
1316.1.2 by David Coles
Allow specification of a deadline when creating new projects.
55
    def add_project(self, req, name, short_name, deadline, synopsis):
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
56
        """Add a Project to this ProjectSet"""
57
        new_project = Project()
58
        new_project.name = unicode(name)
59
        new_project.short_name = unicode(short_name)
60
        new_project.synopsis = unicode(synopsis)
1316.1.2 by David Coles
Allow specification of a deadline when creating new projects.
61
        try:
62
            new_project.deadline = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M:%S')
63
        except ValueError:
64
            raise BadRequest("deadline must be in YYYY-MM-DD HH:MM:ss")
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
65
        new_project.project_set = self.context
66
67
        req.store.add(new_project)
68
        req.store.flush()
1165.2.3 by Nick Chadwick
Added a new Admin view, which allows for the administration of projects
69
    
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
70
        self.template = "templates/project_fragment.html"
71
        self.ctx['project'] = new_project
72
        self.ctx['project_url'] = self._project_url(new_project)
73
74
        return {'success': True, 'projectset_id': self.context.id}
75
76
class ProjectRESTView(XHTMLRESTView):
77
    """Rest view for a project."""