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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-07-17 22:02:23 UTC
  • Revision ID: me@williamgrant.id.au-20090717220223-9b1j9lm6oyon4xsa
Actually 404 when a matching route is not found.

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
8
6
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
9
7
                                   require_permission)
 
8
 
10
9
from ivle.webapp.errors import NotFound
11
10
 
12
11
class OfferingRESTView(XHTMLRESTView):
14
13
      
15
14
    This view allows for added a ProjectSet to an existing subject."""
16
15
 
 
16
    template = "subject.html"
 
17
 
 
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
 
17
36
    @named_operation('edit')
18
37
    def add_projectset(self, req, group_size):
19
38
        """Add a new ProjectSet"""
27
46
        req.store.add(new_projectset)
28
47
        req.store.flush()
29
48
 
30
 
        self.ctx['req'] = req
31
49
        self.ctx['projectset'] = new_projectset
32
50
        self.ctx['projects'] = []
33
 
        self.ctx['GroupsView'] = GroupsView
34
 
        self.ctx['ProjectSetRESTView'] = ProjectSetRESTView
 
51
        self.ctx['new_project_url'] = self.new_project_url(new_projectset)
35
52
 
36
53
        self.template = 'templates/projectset_fragment.html'
37
54