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

« back to all changes in this revision

Viewing changes to ivle/webapp/admin/offeringservice.py

Unbreak TestFramework's exception reporting mechanism, and report TestCreationErrors in test mode.

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
import ivle.database
4
4
from ivle.database import ProjectSet, Subject, Semester, Offering
5
5
 
 
6
from ivle.webapp.admin.projectservice import ProjectSetRESTView
 
7
from ivle.webapp.groups import GroupsView
6
8
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
7
9
                                   require_permission)
8
 
 
9
10
from ivle.webapp.errors import NotFound
10
11
 
11
12
class OfferingRESTView(XHTMLRESTView):
15
16
 
16
17
    template = "subject.html"
17
18
 
18
 
    def __init__(self, req, subject, year, semester):
19
 
 
20
 
        self.context = req.store.find(Offering,
21
 
                Offering.subject_id == Subject.id,
22
 
                Subject.short_name == unicode(subject),
23
 
                Offering.semester_id == Semester.id,
24
 
                Semester.year == unicode(year),
25
 
                Semester.semester == unicode(semester)).one()
26
 
 
27
 
        if self.context is None:
28
 
            raise NotFound()
29
 
 
30
 
    def new_project_url(self, projectset):
31
 
        return "/api/subjects/" + str(self.context.subject.id) + "/" +\
32
 
               self.context.semester.year + "/" +\
33
 
               self.context.semester.semester + "/+projectsets/" +\
34
 
               (str(projectset.id)) + "/+projects/+new"
35
 
 
36
19
    @named_operation('edit')
37
20
    def add_projectset(self, req, group_size):
38
21
        """Add a new ProjectSet"""
39
22
        new_projectset = ProjectSet()
40
 
        new_projectset.max_students_per_group = int(group_size)
 
23
        if group_size == '':
 
24
            new_projectset.max_students_per_group = None
 
25
        else:
 
26
            new_projectset.max_students_per_group = int(group_size)
41
27
        new_projectset.offering = self.context
42
28
 
43
29
        req.store.add(new_projectset)
44
30
        req.store.flush()
45
31
 
46
 
        self.ctx['group_size'] = new_projectset.max_students_per_group
47
 
        self.ctx['projectset_id'] = new_projectset.id
 
32
        self.ctx['req'] = req
 
33
        self.ctx['projectset'] = new_projectset
48
34
        self.ctx['projects'] = []
49
 
        self.ctx['new_project_url'] = self.new_project_url(new_projectset)
 
35
        self.ctx['GroupsView'] = GroupsView
 
36
        self.ctx['ProjectSetRESTView'] = ProjectSetRESTView
50
37
 
51
38
        self.template = 'templates/projectset_fragment.html'
52
39