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

« back to all changes in this revision

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

  • Committer: Matt Giuca
  • Date: 2009-12-08 05:05:20 UTC
  • Revision ID: matt.giuca@gmail.com-20091208050520-a4nmmjxwtmhip063
ivle-createdatadirs: Fixed exit -- if path already exists, log and exit(0).

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}