621
by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic |
1 |
# IVLE
|
2 |
# Copyright (C) 2007-2008 The University of Melbourne
|
|
3 |
#
|
|
4 |
# This program is free software; you can redistribute it and/or modify
|
|
5 |
# it under the terms of the GNU General Public License as published by
|
|
6 |
# the Free Software Foundation; either version 2 of the License, or
|
|
7 |
# (at your option) any later version.
|
|
8 |
#
|
|
9 |
# This program is distributed in the hope that it will be useful,
|
|
10 |
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11 |
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
12 |
# GNU General Public License for more details.
|
|
13 |
#
|
|
14 |
# You should have received a copy of the GNU General Public License
|
|
15 |
# along with this program; if not, write to the Free Software
|
|
16 |
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
17 |
||
18 |
# App: subjects
|
|
19 |
# Author: Matt Giuca
|
|
20 |
# Date: 29/2/2008
|
|
21 |
||
22 |
# This is an IVLE application.
|
|
23 |
# A sample / testing application for IVLE.
|
|
24 |
||
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
25 |
import os |
26 |
import urllib |
|
27 |
import cgi |
|
28 |
||
621
by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic |
29 |
from common import util |
30 |
||
31 |
def handle(req): |
|
32 |
"""Handler for the Subjects application. Links to subject home pages."""
|
|
33 |
||
630
by mattgiuca
subjects: Added subjects/subjects.css to correctly style the iframe. |
34 |
req.styles = ["media/subjects/subjects.css"] |
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
35 |
if req.path == "": |
36 |
handle_toplevel_menu(req) |
|
37 |
else: |
|
38 |
handle_subject_page(req, req.path) |
|
39 |
||
40 |
def handle_toplevel_menu(req): |
|
41 |
# This is represented as a directory. Redirect and add a slash if it is
|
|
42 |
# missing.
|
|
43 |
if req.uri[-1] != '/': |
|
655
by mattgiuca
subjects: Fixed a bug from crufty code (exception thrown if you don't put a |
44 |
req.throw_redirect(req.uri + '/') |
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
45 |
|
46 |
# Get list of subjects
|
|
47 |
# TODO: Fetch from DB. For now, just get directory listing
|
|
48 |
try: |
|
49 |
subjects = os.listdir(util.make_local_path(os.path.join('media', |
|
50 |
'subjects'))) |
|
51 |
except OSError: |
|
52 |
req.throw_error(req.HTTP_INTERNAL_SERVER_ERROR, |
|
53 |
"There are is no subject homepages directory.") |
|
54 |
subjects.sort() |
|
55 |
||
56 |
req.content_type = "text/html" |
|
57 |
req.write_html_head_foot = True |
|
58 |
req.write('<div id="ivle_padding">\n') |
|
59 |
req.write("<h2>IVLE Subject Homepages</h2>\n") |
|
60 |
req.write("<h2>Subjects</h2>\n<ul>\n") |
|
61 |
for subject in subjects: |
|
62 |
req.write(' <li><a href="%s">%s</a></li>\n' |
|
63 |
% (urllib.quote(subject) + '/', cgi.escape(subject))) |
|
64 |
req.write("</ul>\n") |
|
65 |
req.write("</div>\n") |
|
66 |
||
67 |
def handle_subject_page(req, path): |
|
621
by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic |
68 |
req.content_type = "text/html" |
69 |
req.write_html_head_foot = True # Have dispatch print head and foot |
|
70 |
||
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
71 |
# Just make the iframe pointing to media/subjects
|
72 |
serve_loc = util.make_path(os.path.join('media', 'subjects', path)) |
|
73 |
req.write('<iframe src="%s"></iframe>' |
|
74 |
% urllib.quote(serve_loc)) |