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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-01-18 01:07:48 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:244
interpret.py: Major refactor of CGI interpreter code. Still missing some
functionality but now buffers input correctly and can handle binary files.
Also code much more nicely separated.
    Note: May not present error message correctly any more (temp).

Show diffs side-by-side

added added

removed removed

Lines of Context:
23
23
# content (the common parts of the HTML pages shared across the entire site).
24
24
# Does not include the login page. See login.py.
25
25
 
26
 
import cgi
27
26
import os.path
28
27
 
29
28
import conf
49
48
<head>
50
49
  <title>%sIVLE</title>
51
50
  <meta http-equiv="Content-Type" content="%s; charset=utf-8" />
52
 
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
 
51
""" % (titlepart, req.content_type))
53
52
    # Write inline JavaScript which gives the client code access to certain
54
53
    # server-side variables.
55
54
    if req.username:
64
63
    iconurl = get_icon_url(req.app)
65
64
    if iconurl:
66
65
        req.write("""  <link rel="shortcut icon" href="%s" />
67
 
""" % cgi.escape(iconurl))
 
66
""" % iconurl)
68
67
    req.write("""  <link rel="stylesheet" type="text/css" href="%s" />
69
 
""" % cgi.escape(util.make_path('media/common/ivle.css')))
 
68
""" % util.make_path('media/common/ivle.css'))
70
69
 
71
70
    # Write any app-specific style and script links
72
71
    for style in req.styles:
73
72
        req.write('  <link rel="stylesheet" type="text/css" href="%s" />\n'
74
 
            % cgi.escape(util.make_path(style)))
 
73
            % util.make_path(style))
75
74
    for script in req.scripts:
76
 
        req.write('  <script type="text/javascript" src="%s"></script>\n'
77
 
            % cgi.escape(util.make_path(script)))
 
75
        req.write('  <script type="text/javascript" src="%s" />\n'
 
76
            % util.make_path(script))
78
77
 
79
78
    req.write("</head>\n\n")
80
79
 
81
80
    # Open the body element and write a bunch of stuff there (the header)
82
81
    req.write("""<body>
83
 
<div id="ivleheader"></div>
84
 
<div id="ivleheader_text">
 
82
<div id="ivleheader">
85
83
  <h1>IVLE</h1>
86
84
  <h2>Informatics Virtual Learning Environment</h2>
87
85
""")
88
86
 
89
87
    if req.username:
90
 
        # Get the user's nickname from the request session
91
 
        nickname = req.get_session()['nick']
92
 
        req.write('  <p class="userhello">%s (<span '
93
 
            'class="username">%s</span>) |\n'
 
88
        req.write('  <p class="userhello">Welcome, <span '
 
89
            'class="username">%s</span> |\n'
94
90
            '    <a href="%s">Help</a> |\n'
95
91
            '    <a href="%s">Logout</a>\n'
96
92
            '  </p>\n' %
97
 
            (cgi.escape(nickname), cgi.escape(req.username),
98
 
             cgi.escape(get_help_url(req)),
99
 
             cgi.escape(util.make_path('logout'))))
 
93
            (req.username, get_help_url(req), util.make_path('logout')))
100
94
    else:
101
95
        req.write('  <p class="userhello">Not logged in.</p>')
102
96
 
103
 
    # ivleheader_tabs is a separate div, so it can be positioned absolutely
104
 
    req.write('</div>\n<div id="ivleheader_tabs">\n')
105
 
 
106
97
    # If the "debuginfo" app is installed, display a warning to the admin to
107
98
    # make sure it is removed in production.
108
99
    if "debuginfo" in conf.apps.app_url:
110
101
            "app from conf.apps.app_url when placed into production."
111
102
            "</small></p>\n")
112
103
 
113
 
    # If req has a "no_agreement" attribute, then it is because the user has
114
 
    # not signed the agreement; therefore we are displaying the TOS page.
115
 
    # Do not show apps (see dispatch.login).
116
 
    if req.username and not hasattr(req, 'no_agreement'):
 
104
    if req.username:
117
105
        # Only print app tabs if logged in
118
106
        print_apps_list(req, req.app)
119
107
    req.write('</div>\n<div id="ivlebody">\n')
128
116
def get_help_url(req):
129
117
    """Gets the help URL most relevant to this page, to place as the
130
118
    "help" link at the top of the page."""
131
 
    reqapp = req.app if hasattr(req, 'app') else None
132
 
    if reqapp == 'help':
 
119
    if req.app == 'help':
133
120
        # We're already in help. Link to the exact current page
134
121
        # instead of the generic help page.
135
122
        return req.uri
136
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
137
 
        help_path = os.path.join('help', reqapp)
 
123
    if conf.apps.app_url[req.app].hashelp:
 
124
        help_path = os.path.join('help', req.app)
138
125
    else:
139
126
        help_path = 'help'
140
127
    return util.make_path(help_path)
168
155
            li_attr = ''
169
156
        file.write('    <li%s>' % li_attr)
170
157
        if app.icon:
171
 
            file.write('<img src="%s" alt="" /> '
172
 
                % cgi.escape(get_icon_url(urlname)))
 
158
            file.write('<img src="%s" alt="" /> ' % get_icon_url(urlname))
173
159
        file.write('<a href="%s">%s</a></li>\n'
174
 
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
 
160
            % (util.make_path(urlname), app.name))
175
161
 
176
162
    file.write('  </ul>\n')