~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-12-08 05:17:41 UTC
  • Revision ID: grantw@unimelb.edu.au-20091208051741-ge3tbktd1ebyt6p4
Use the publishing framework to generate URLs to projectsets.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
 
 
2
 
 
3
import ivle.database
 
4
from ivle.database import ProjectSet, Subject, Semester, Offering
 
5
 
 
6
from ivle.webapp.admin.projectservice import ProjectSetRESTView
 
7
from ivle.webapp.base.rest import (XHTMLRESTView, named_operation,
 
8
                                   require_permission)
 
9
from ivle.webapp.errors import NotFound
 
10
 
 
11
class OfferingRESTView(XHTMLRESTView):
 
12
    """REST view for a subject.
 
13
      
 
14
    This view allows for added a ProjectSet to an existing subject."""
 
15
 
 
16
    template = "subject.html"
 
17
 
 
18
    @named_operation('edit')
 
19
    def add_projectset(self, req, group_size):
 
20
        """Add a new ProjectSet"""
 
21
        new_projectset = ProjectSet()
 
22
        if group_size == '':
 
23
            new_projectset.max_students_per_group = None
 
24
        else:
 
25
            new_projectset.max_students_per_group = int(group_size)
 
26
        new_projectset.offering = self.context
 
27
 
 
28
        req.store.add(new_projectset)
 
29
        req.store.flush()
 
30
 
 
31
        self.ctx['req'] = req
 
32
        self.ctx['projectset'] = new_projectset
 
33
        self.ctx['projects'] = []
 
34
        self.ctx['ProjectSetRESTView'] = ProjectSetRESTView
 
35
 
 
36
        self.template = 'templates/projectset_fragment.html'
 
37
 
 
38
        return {'success': True, 'projectset_id': new_projectset.id}