29
from storm.locals import Desc
29
31
from ivle.webapp.base.xhtml import XHTMLView
30
32
from ivle.webapp.base.plugins import ViewPlugin, MediaPlugin
31
33
from ivle.webapp.errors import NotFound
32
from ivle.database import Subject
34
from ivle.database import Subject, Semester
33
35
from ivle import util
36
38
class SubjectsView(XHTMLView):
37
39
'''The view of the list of subjects.'''
38
40
template = 'subjects.html'
39
appname = 'subjects' # XXX
41
43
def authorize(self, req):
42
return req.user is not None
46
return req.user.enrolments.count() > 0
44
48
def populate(self, req, ctx):
45
enrolled_subjects = req.user.subjects
46
unenrolled_subjects = [subject for subject in
47
req.store.find(Subject)
48
if subject not in enrolled_subjects]
50
ctx['enrolled_subjects'] = []
51
ctx['other_subjects'] = []
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)
50
for semester in req.store.find(Semester).order_by(Desc(Semester.year),
51
Desc(Semester.semester)):
52
enrolments = semester.enrolments.find(user=req.user)
53
if enrolments.count():
54
ctx['semesters'].append((semester, enrolments))
67
56
class Plugin(ViewPlugin, MediaPlugin):
73
('subjects', 'Subjects', 'Announcements and information about the '
74
'subjects you are enrolled in.', 'subjects.png', 'subjects', 5)
62
('subjects', 'Subjects',
63
'View subject content and complete worksheets',
64
'subjects.png', 'subjects', 5)
77
67
media = 'subject-media'