~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 03:50:24 UTC
  • mfrom: (1294.2.143 ui-the-third)
  • Revision ID: grantw@unimelb.edu.au-20091208035024-wjx8zp54gth15ph8
Merge ui-the-third. This is another UI revamp.

The header is now thin! Thin! The yellow bar is gone. The tabs are gone.
Breadcrumbs are here. Routes is replaced (with an object publishing
mechanism). Views are less repetitive. etc.

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.base.rest import (XHTMLRESTView, named_operation,
 
7
                                   require_permission)
 
8
 
 
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
    def new_project_url(self, projectset):
 
19
        return "/api/subjects/%s/%s/%s/+projectsets/%d/+projects/+new" % (
 
20
            self.context.subject.short_name, self.context.semester.year,
 
21
            self.context.semester.semester, projectset.id)
 
22
 
 
23
    @named_operation('edit')
 
24
    def add_projectset(self, req, group_size):
 
25
        """Add a new ProjectSet"""
 
26
        new_projectset = ProjectSet()
 
27
        if group_size == '':
 
28
            new_projectset.max_students_per_group = None
 
29
        else:
 
30
            new_projectset.max_students_per_group = int(group_size)
 
31
        new_projectset.offering = self.context
 
32
 
 
33
        req.store.add(new_projectset)
 
34
        req.store.flush()
 
35
 
 
36
        self.ctx['projectset'] = new_projectset
 
37
        self.ctx['projects'] = []
 
38
        self.ctx['new_project_url'] = self.new_project_url(new_projectset)
 
39
 
 
40
        self.template = 'templates/projectset_fragment.html'
 
41
 
 
42
        return {'success': True, 'projectset_id': new_projectset.id}