4
from ivle.database import ProjectSet, Subject, Semester, Offering
6
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
9
from ivle.webapp.errors import NotFound
11
class OfferingRESTView(XHTMLRESTView):
12
"""REST view for a subject.
14
This view allows for added a ProjectSet to an existing subject."""
16
template = "subject.html"
18
def new_project_url(self, projectset):
19
return "/api/subjects/%s/%s/%s/+projectsets/%d/+projects/+new" % (
20
self.context.subject.short_name, self.context.semester.year,
21
self.context.semester.semester, projectset.id)
23
@named_operation('edit')
24
def add_projectset(self, req, group_size):
25
"""Add a new ProjectSet"""
26
new_projectset = ProjectSet()
28
new_projectset.max_students_per_group = None
30
new_projectset.max_students_per_group = int(group_size)
31
new_projectset.offering = self.context
33
req.store.add(new_projectset)
36
self.ctx['projectset'] = new_projectset
37
self.ctx['projects'] = []
38
self.ctx['new_project_url'] = self.new_project_url(new_projectset)
40
self.template = 'templates/projectset_fragment.html'
42
return {'success': True, 'projectset_id': new_projectset.id}