29
29
import ivle.database
30
30
from ivle import util
33
import genshi.template
33
36
"""Handler for the Subjects application. Links to subject home pages."""
35
38
req.styles = ["media/subjects/subjects.css"]
39
ctx = genshi.template.Context()
37
handle_toplevel_menu(req)
41
# This is represented as a directory. Redirect and add a slash if it is
43
if req.uri[-1] != '/':
44
req.throw_redirect(req.uri + '/')
45
ctx['whichpage'] = "toplevel"
46
handle_toplevel_menu(req, ctx)
39
handle_subject_page(req, req.path)
48
ctx['whichpage'] = "subject"
49
handle_subject_page(req, req.path, ctx)
51
loader = genshi.template.TemplateLoader(".", auto_reload=True)
52
tmpl = loader.load(util.make_local_path("apps/subjects/template.html"))
53
req.write(tmpl.generate(ctx).render('html')) #'xhtml', doctype='xhtml'))
41
def handle_toplevel_menu(req):
42
# This is represented as a directory. Redirect and add a slash if it is
44
if req.uri[-1] != '/':
45
req.throw_redirect(req.uri + '/')
55
def handle_toplevel_menu(req, ctx):
47
57
enrolled_subjects = req.user.subjects
48
58
unenrolled_subjects = [subject for subject in
49
59
req.store.find(ivle.database.Subject)
50
60
if subject not in enrolled_subjects]
52
def print_subject(subject):
53
if subject.url is None:
54
req.write(' <li>%s (no home page)</li>\n'
55
% cgi.escape(subject.name))
57
req.write(' <li><a href="%s">%s</a></li>\n'
58
% (cgi.escape(subject.url),
59
cgi.escape(subject.name)))
62
ctx['enrolled_subjects'] = []
63
ctx['other_subjects'] = []
61
65
req.content_type = "text/html"
62
66
req.write_html_head_foot = True
63
req.write('<div id="ivle_padding">\n')
64
req.write("<h2>IVLE Subject Homepages</h2>\n")
65
req.write("<h2>Subjects</h2>\n<ul>\n")
66
68
for subject in enrolled_subjects:
67
print_subject(subject)
70
new_subj['name'] = subject.name
71
new_subj['url'] = subject.url
72
ctx['enrolled_subjects'].append(new_subj)
69
74
if len(unenrolled_subjects) > 0:
70
req.write("<h3>Other Subjects</h3>\n")
71
req.write("<p>You are not currently enrolled in these subjects</p>\n")
73
75
for subject in unenrolled_subjects:
74
print_subject(subject)
78
def handle_subject_page(req, path):
77
new_subj['name'] = subject.name
78
new_subj['url'] = subject.url
79
ctx['other_subjects'].append(new_subj)
82
def handle_subject_page(req, path, ctx):
79
83
req.content_type = "text/html"
80
84
req.write_html_head_foot = True # Have dispatch print head and foot
82
86
# Just make the iframe pointing to media/subjects
83
serve_loc = util.make_path(os.path.join('media', 'subjects', path))
84
req.write('<object class="fullscreen" type="text/html" \
85
data="%s"></iframe>'% urllib.quote(serve_loc))
87
ctx['serve_loc'] = urllib.quote(util.make_path(os.path.join('media', 'subjects', path)))