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

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 __init__(self, req, subject, year, semester):
17
18
        self.context = req.store.find(Offering,
19
                Offering.subject_id == Subject.id,
20
                Subject.short_name == unicode(subject),
21
                Offering.semester_id == Semester.id,
22
                Semester.year == unicode(year),
23
                Semester.semester == unicode(semester)).one()
24
25
        if self.context is None:
26
            raise NotFound()
27
28
    def new_project_url(self, projectset):
29
        return "/api/subjects/" + str(self.context.subject.id) + "/" +\
30
               self.context.semester.year + "/" +\
31
               self.context.semester.semester + "/+projectsets/" +\
32
               (str(projectset.id)) + "/+projects/+new"
33
34
    @named_operation('edit')
35
    def add_projectset(self, req, group_size):
36
        """Add a new ProjectSet"""
37
        new_projectset = ProjectSet()
38
        if group_size == '':
39
            new_projectset.max_students_per_group = None
1165.4.1 by Nick Chadwick
Modified offeringservice to correctly add in a Solo Project.
40
        else:
41
            new_projectset.max_students_per_group = int(group_size)
42
        new_projectset.offering = self.context
43
1165.3.2 by Nick Chadwick
Created a new view for IVLE, allowing lecturers and tutors to
44
        req.store.add(new_projectset)
45
        req.store.flush()
46
47
        self.ctx['projectset'] = new_projectset
48
        self.ctx['projects'] = []
1165.3.30 by William Grant
Clean out the projectset fragment context.
49
        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
50
51
        self.template = 'templates/projectset_fragment.html'
52
53
        return {'success': True, 'projectset_id': new_projectset.id}
54
55