~azzar1/unity/add-show-desktop-key

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
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
29
from ivle import util
30
import ivle.db
621 by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic
31
32
def handle(req):
33
    """Handler for the Subjects application. Links to subject home pages."""
34
630 by mattgiuca
subjects: Added subjects/subjects.css to correctly style the iframe.
35
    req.styles = ["media/subjects/subjects.css"]
627 by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials).
36
    if req.path == "":
37
        handle_toplevel_menu(req)
38
    else:
39
        handle_subject_page(req, req.path)
40
41
def handle_toplevel_menu(req):
42
    # This is represented as a directory. Redirect and add a slash if it is
43
    # missing.
44
    if req.uri[-1] != '/':
655 by mattgiuca
subjects: Fixed a bug from crufty code (exception thrown if you don't put a
45
        req.throw_redirect(req.uri + '/')
627 by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials).
46
983 by wagrant
subjects, tutorial: Factor out subject enrolment status calculation
47
    (enrolled_subjects, unenrolled_subjects) = \
1079 by William Grant
Merge setup-refactor branch. This completely breaks existing installations;
48
              ivle.db.DB().get_subjects_status(req.user.login)
958 by mattgiuca
db: Added "get_subjects", which retrieves all subjects in the system.
49
50
    def print_subject(subject):
51
        if subject['url'] is None:
52
            req.write('  <li>%s (no home page)</li>\n'
53
                % cgi.escape(subject['subj_name']))
54
        else:
55
            req.write('  <li><a href="%s">%s</a></li>\n'
56
                % (cgi.escape(subject['url']),
57
                   cgi.escape(subject['subj_name'])))
627 by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials).
58
59
    req.content_type = "text/html"
60
    req.write_html_head_foot = True
61
    req.write('<div id="ivle_padding">\n')
62
    req.write("<h2>IVLE Subject Homepages</h2>\n")
63
    req.write("<h2>Subjects</h2>\n<ul>\n")
958 by mattgiuca
db: Added "get_subjects", which retrieves all subjects in the system.
64
    for subject in enrolled_subjects:
65
        print_subject(subject)
627 by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials).
66
    req.write("</ul>\n")
958 by mattgiuca
db: Added "get_subjects", which retrieves all subjects in the system.
67
    if len(unenrolled_subjects) > 0:
68
        req.write("<h3>Other Subjects</h3>\n")
69
        req.write("<p>You are not currently enrolled in these subjects</p>\n")
70
        req.write("<ul>\n")
71
        for subject in unenrolled_subjects:
72
            print_subject(subject)
73
        req.write("</ul>\n")
627 by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials).
74
    req.write("</div>\n")
75
76
def handle_subject_page(req, path):
621 by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic
77
    req.content_type = "text/html"
78
    req.write_html_head_foot = True     # Have dispatch print head and foot
79
627 by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials).
80
    # Just make the iframe pointing to media/subjects
81
    serve_loc = util.make_path(os.path.join('media', 'subjects', path))
868 by dcoles
Layout: Attempt to patch some CSS layout issues. Subject window now no longer
82
    req.write('<object class="fullscreen" type="text/html" \
83
data="%s"></iframe>'% urllib.quote(serve_loc))