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
41
def authorize(self, req):
42
return req.user is not None
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]
47
ctx['enrolled_subjects'] = []
48
ctx['other_subjects'] = []
50
req.content_type = "text/html"
51
req.write_html_head_foot = True
53
for subject in enrolled_subjects:
55
new_subj['name'] = subject.name
56
new_subj['url'] = subject.url
57
ctx['enrolled_subjects'].append(new_subj)
59
if len(unenrolled_subjects) > 0:
60
for subject in unenrolled_subjects:
62
new_subj['name'] = subject.name
63
new_subj['url'] = subject.url
64
ctx['other_subjects'].append(new_subj)
67
class Plugin(ViewPlugin):
45
ctx['enrolments'] = req.user.active_enrolments
47
class Plugin(ViewPlugin, MediaPlugin):
69
49
('subjects/', SubjectsView),
53
('subjects', 'Subjects',
54
'View subject content and complete worksheets',
55
'subjects.png', 'subjects', 5)
58
media = 'subject-media'