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

« back to all changes in this revision

Viewing changes to www/apps/tutorial/__init__.py

  • Committer: mattgiuca
  • Date: 2008-01-24 21:51:17 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:287
setup.py: Added new conf.py variable: subjects_base. This is for storing the
local path (note: to be a URL) to the subject directories where worksheet
content is stored.

apps/tutorial: Added some basic URL processing and code structure. 3
functions, for handling top-level menu, subject-level menu, and worksheet.
(stubs).

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
# App: tutorial
19
19
# Author: Matt Giuca
20
 
# Date: 12/1/2008
 
20
# Date: 25/1/2008
21
21
 
22
22
# Tutorial application.
23
 
# Not yet implemented.
 
23
# Displays tutorial content with editable problems, allowing students to test
 
24
# and submit their solutions to problems and have them auto-tested.
 
25
 
 
26
# URL syntax
 
27
# All path segments are optional (omitted path segments will show menus).
 
28
# The first path segment is the subject code.
 
29
# The second path segment is the worksheet name.
 
30
 
 
31
import os
 
32
import cgi
24
33
 
25
34
from common import util
26
35
 
31
40
    req.content_type = "text/html"
32
41
    req.write_html_head_foot = True     # Have dispatch print head and foot
33
42
 
34
 
    # Start writing data
35
 
    req.write("<p>Tutorial (not yet implemented)</p>\n")
 
43
    path_segs = req.path.split(os.sep)
 
44
    subject = None
 
45
    worksheet = None
 
46
    if len(path_segs) > 2:
 
47
        req.throw_error(req.HTTP_NOT_FOUND)
 
48
    elif len(req.path) > 0:
 
49
        subject = path_segs[0]
 
50
        if len(path_segs) == 2:
 
51
            worksheet = path_segs[1]
 
52
 
 
53
    if subject == None:
 
54
        handle_toplevel_menu(req)
 
55
    elif worksheet == None:
 
56
        handle_subject_menu(req, subject)
 
57
    else:
 
58
        handle_worksheet(req, subject, worksheet)
 
59
 
 
60
def handle_toplevel_menu(req):
 
61
    req.write("<h1>IVLE Tutorials</h1>\n")
 
62
    req.write("<p>TODO: Top-level tutorial menu</p>\n")
 
63
 
 
64
def handle_subject_menu(req, subject):
 
65
    req.write("<h1>IVLE Tutorials - %s</h1>\n" % cgi.escape(subject))
 
66
    req.write("<p>TODO: Subject-level menu</p>\n")
 
67
 
 
68
def handle_worksheet(req, subject, worksheet):
 
69
    req.write("<h1>IVLE Tutorials - %s</h1>\n<h2>%s</h2>\n"
 
70
        % (cgi.escape(subject), cgi.escape(worksheet)))
 
71
    req.write("<p>TODO: Worksheet content</p>\n")
36
72