1165.3.2
by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to |
1 |
import ivle.database |
2 |
from ivle.database import ProjectSet, Subject, Semester, Offering |
|
3 |
||
4 |
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation, |
|
5 |
require_permission) |
|
6 |
||
7 |
from ivle.webapp.errors import NotFound |
|
8 |
||
9 |
class OfferingRESTView(XHTMLRESTView): |
|
10 |
"""REST view for a subject.
|
|
11 |
|
|
12 |
This view allows for added a ProjectSet to an existing subject."""
|
|
13 |
||
14 |
template = "subject.html" |
|
15 |
||
16 |
def new_project_url(self, projectset): |
|
17 |
return "/api/subjects/" + str(self.context.subject.id) + "/" +\ |
|
18 |
self.context.semester.year + "/" +\ |
|
19 |
self.context.semester.semester + "/+projectsets/" +\ |
|
20 |
(str(projectset.id)) + "/+projects/+new" |
|
21 |
||
22 |
@named_operation('edit') |
|
23 |
def add_projectset(self, req, group_size): |
|
24 |
"""Add a new ProjectSet"""
|
|
25 |
new_projectset = ProjectSet() |
|
26 |
if group_size == '': |
|
27 |
new_projectset.max_students_per_group = None |
|
1165.4.1
by Nick Chadwick
Modified offeringservice to correctly add in a Solo Project. |
28 |
else: |
29 |
new_projectset.max_students_per_group = int(group_size) |
|
30 |
new_projectset.offering = self.context |
|
31 |
||
1165.3.2
by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to |
32 |
req.store.add(new_projectset) |
33 |
req.store.flush() |
|
34 |
||
35 |
self.ctx['projectset'] = new_projectset |
|
36 |
self.ctx['projects'] = [] |
|
1165.3.30
by William Grant
Clean out the projectset fragment context. |
37 |
self.ctx['new_project_url'] = self.new_project_url(new_projectset) |
1165.3.2
by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to |
38 |
|
39 |
self.template = 'templates/projectset_fragment.html' |
|
40 |
||
41 |
return {'success': True, 'projectset_id': new_projectset.id} |
|
42 |
||
43 |