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 |
||
1080.1.32
by me at id
www/app/{subjects,tutorial}: Use the new Storm API to get enrolled subjects. |
29 |
import ivle.database |
1079
by William Grant
Merge setup-refactor branch. This completely breaks existing installations; |
30 |
from ivle import util |
621
by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic |
31 |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
32 |
import genshi |
33 |
import genshi.template |
|
34 |
||
621
by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic |
35 |
def handle(req): |
36 |
"""Handler for the Subjects application. Links to subject home pages."""
|
|
37 |
||
630
by mattgiuca
subjects: Added subjects/subjects.css to correctly style the iframe. |
38 |
req.styles = ["media/subjects/subjects.css"] |
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
39 |
ctx = genshi.template.Context() |
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
40 |
if req.path == "": |
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
41 |
# This is represented as a directory. Redirect and add a slash if it is
|
42 |
# missing.
|
|
43 |
if req.uri[-1] != '/': |
|
44 |
req.throw_redirect(req.uri + '/') |
|
45 |
ctx['whichpage'] = "toplevel" |
|
46 |
handle_toplevel_menu(req, ctx) |
|
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
47 |
else: |
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
48 |
ctx['whichpage'] = "subject" |
49 |
handle_subject_page(req, req.path, ctx) |
|
50 |
||
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')) |
|
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
54 |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
55 |
def handle_toplevel_menu(req, ctx): |
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
56 |
|
1080.1.32
by me at id
www/app/{subjects,tutorial}: Use the new Storm API to get enrolled subjects. |
57 |
enrolled_subjects = req.user.subjects |
58 |
unenrolled_subjects = [subject for subject in |
|
59 |
req.store.find(ivle.database.Subject) |
|
60 |
if subject not in enrolled_subjects] |
|
958
by mattgiuca
db: Added "get_subjects", which retrieves all subjects in the system. |
61 |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
62 |
ctx['enrolled_subjects'] = [] |
63 |
ctx['other_subjects'] = [] |
|
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
64 |
|
65 |
req.content_type = "text/html" |
|
66 |
req.write_html_head_foot = True |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
67 |
|
958
by mattgiuca
db: Added "get_subjects", which retrieves all subjects in the system. |
68 |
for subject in enrolled_subjects: |
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
69 |
new_subj = {} |
70 |
new_subj['name'] = subject.name |
|
71 |
new_subj['url'] = subject.url |
|
72 |
ctx['enrolled_subjects'].append(new_subj) |
|
73 |
||
958
by mattgiuca
db: Added "get_subjects", which retrieves all subjects in the system. |
74 |
if len(unenrolled_subjects) > 0: |
75 |
for subject in unenrolled_subjects: |
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
76 |
new_subj = {} |
77 |
new_subj['name'] = subject.name |
|
78 |
new_subj['url'] = subject.url |
|
79 |
ctx['other_subjects'].append(new_subj) |
|
80 |
||
81 |
||
82 |
def handle_subject_page(req, path, ctx): |
|
621
by mattgiuca
Added 2 new apps: home and subjects. Both fairly incomplete, just a basic |
83 |
req.content_type = "text/html" |
84 |
req.write_html_head_foot = True # Have dispatch print head and foot |
|
85 |
||
627
by mattgiuca
subjects: Now presents a top-level subjects menu (same as tutorials). |
86 |
# Just make the iframe pointing to media/subjects
|
1093
by chadnickbok
Adding the changes from my genshi branch into trunk. |
87 |
ctx['serve_loc'] = urllib.quote(util.make_path(os.path.join('media', 'subjects', path))) |