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

« back to all changes in this revision

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

  • Committer: William Grant
  • Date: 2009-02-25 23:04:11 UTC
  • Revision ID: grantw@unimelb.edu.au-20090225230411-lbdyl32ir0m3d59b
Make all of the services executable.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import cgi
28
28
 
29
29
from ivle.webapp.base.xhtml import XHTMLView
30
 
from ivle.webapp.base.plugins import ViewPlugin
 
30
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
31
31
from ivle.webapp.errors import NotFound
32
32
from ivle.database import Subject
33
33
from ivle import util
36
36
class SubjectsView(XHTMLView):
37
37
    '''The view of the list of subjects.'''
38
38
    template = 'subjects.html'
39
 
    appname = 'subjects' # XXX
 
39
    tab = 'subjects'
 
40
 
 
41
    def authorize(self, req):
 
42
        return req.user is not None
40
43
 
41
44
    def populate(self, req, ctx):
42
 
        enrolled_subjects = req.user.subjects
43
 
        unenrolled_subjects = [subject for subject in
44
 
                               req.store.find(Subject)
45
 
                               if subject not in enrolled_subjects]
46
 
 
47
 
        ctx['enrolled_subjects'] = []
48
 
        ctx['other_subjects'] = []
49
 
 
50
 
        req.content_type = "text/html"
51
 
        req.write_html_head_foot = True
52
 
 
53
 
        for subject in enrolled_subjects:
54
 
            new_subj = {}
55
 
            new_subj['name'] = subject.name
56
 
            new_subj['url'] = subject.url
57
 
            ctx['enrolled_subjects'].append(new_subj)
58
 
 
59
 
        if len(unenrolled_subjects) > 0:
60
 
            for subject in unenrolled_subjects:
61
 
                new_subj = {}
62
 
                new_subj['name'] = subject.name
63
 
                new_subj['url'] = subject.url
64
 
                ctx['other_subjects'].append(new_subj)
65
 
 
66
 
 
67
 
class Plugin(ViewPlugin):
 
45
        ctx['enrolments'] = req.user.active_enrolments
 
46
 
 
47
class Plugin(ViewPlugin, MediaPlugin):
68
48
    urls = [
69
49
        ('subjects/', SubjectsView),
70
50
    ]
 
51
 
 
52
    tabs = [
 
53
        ('subjects', 'Subjects',
 
54
         'View subject content and complete worksheets',
 
55
         'subjects.png', 'subjects', 5)
 
56
    ]
 
57
 
 
58
    media = 'subject-media'