29
29
from ivle.webapp.base.xhtml import XHTMLView
30
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
30
from ivle.webapp.base.plugins import ViewPlugin
31
31
from ivle.webapp.errors import NotFound
32
32
from ivle.database import Subject
33
33
from ivle import util
38
38
template = 'subjects.html'
39
39
appname = 'subjects' # XXX
41
def authorize(self, req):
42
return req.user is not None
44
41
def populate(self, req, ctx):
45
ctx['enrolments'] = req.user.active_enrolments
47
class Plugin(ViewPlugin, MediaPlugin):
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):
49
69
('subjects/', SubjectsView),
53
('subjects', 'Subjects', 'Announcements and information about the '
54
'subjects you are enrolled in.', 'subjects.png', 'subjects', 5)
57
media = 'subject-media'