18
18
# Author: Nick Chadwick
20
21
import ivle.database
21
22
from ivle.database import ProjectSet, Project, Subject, Semester, Offering
23
24
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
24
25
require_permission)
25
from ivle.webapp.errors import NotFound
26
from ivle.webapp.errors import NotFound, BadRequest
27
28
class ProjectSetRESTView(XHTMLRESTView):
28
29
"""Rest view for a projectset.
30
31
Add new, delete, edit functionality is given here."""
31
32
template = "templates/projectset_fragment.html"
33
def __init__(self, req, subject, year, semester, projectset):
34
self.context = req.store.find(ProjectSet,
35
ProjectSet.id == int(projectset),
36
ProjectSet.offering_id == Offering.id,
37
Offering.subject_id == Subject.id,
38
Subject.short_name == unicode(subject),
39
Offering.semester_id == Semester.id,
40
Semester.year == unicode(year),
41
Semester.semester == unicode(semester)).one()
43
if self.context is None:
46
34
def _project_url(self, project):
47
35
return "/subjects/%s/%s/%s/+projects/%s" % \
51
39
project.short_name)
53
41
@named_operation('edit')
54
def add_project(self, req, name, short_name, synopsis):
42
def add_project(self, req, name, short_name, deadline, synopsis):
55
43
"""Add a Project to this ProjectSet"""
56
44
new_project = Project()
57
45
new_project.name = unicode(name)
58
46
new_project.short_name = unicode(short_name)
59
47
new_project.synopsis = unicode(synopsis)
49
new_project.deadline = datetime.datetime.strptime(deadline, '%Y-%m-%d %H:%M:%S')
51
raise BadRequest("deadline must be in YYYY-MM-DD HH:MM:ss")
60
52
new_project.project_set = self.context
62
54
req.store.add(new_project)
65
57
self.template = "templates/project_fragment.html"
66
59
self.ctx['project'] = new_project
67
self.ctx['project_url'] = self._project_url(new_project)
69
61
return {'success': True, 'projectset_id': self.context.id}
71
class ProjectRESTView(XHTMLRESTView):
72
"""Rest view for a project."""