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

« back to all changes in this revision

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

  • Committer: mattgiuca
  • Date: 2008-01-29 23:52:19 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:329
Converted Console from an "app" into a "plugin". It can now be plugged in to
any app.
Added "plugins" directory in www. Added "console" plugin. This contains all of
the functionality of what was previously the console app, but modularized so
it can be imported by another app.

apps/console: Removed most of the logic (moved to plugins/console). Replaced
with a simple import of the console plugin. Should behave exactly the same.
apps/tutorial: As proof of concept, imported the console plugin. It now
appears at the bottom of the page (yet to make it have "pop up" behaviour).

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 __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
 
    @named_operation('edit')
37
 
    def add_projectset(self, req, group_size):
38
 
        """Add a new ProjectSet"""
39
 
        new_projectset = ProjectSet()
40
 
        if group_size == '':
41
 
            new_projectset.max_students_per_group = None
42
 
        else:
43
 
            new_projectset.max_students_per_group = int(group_size)
44
 
        new_projectset.offering = self.context
45
 
 
46
 
        req.store.add(new_projectset)
47
 
        req.store.flush()
48
 
 
49
 
        self.ctx['projectset'] = new_projectset
50
 
        self.ctx['projects'] = []
51
 
        self.ctx['new_project_url'] = self.new_project_url(new_projectset)
52
 
 
53
 
        self.template = 'templates/projectset_fragment.html'
54
 
 
55
 
        return {'success': True, 'projectset_id': new_projectset.id}