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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: dcoles
  • Date: 2008-08-20 08:10:40 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:1034
Console: Refactored the code to support supplying of stdin to the console.  
Renamed and unified a few call in the module - inspect is now execute since 
stdout is written to the console.stdout file-like object rather than being 
returned as part of the call. __chat becomes split into __chat which deals with 
the low level chat protocol issues and __handle_chat which deals with console's 
own protocol.

Updated tutorial service to use these new calls. Still have to fix the 
'add_stdin' function but should be very simple now. (Just write to 
console.stdin)

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
# Does not include the login page. See login.py.
25
25
 
26
26
import cgi
 
27
import urllib
27
28
import os.path
28
29
 
29
30
import conf
30
31
import conf.apps
31
32
from common import util
 
33
import plugins.console
32
34
 
33
35
def write_html_head(req):
34
36
    """Writes the HTML header, given a request object.
52
54
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
53
55
    # Write inline JavaScript which gives the client code access to certain
54
56
    # server-side variables.
55
 
    if req.username:
56
 
        username = repr(req.username)
 
57
    if req.user:
 
58
        username = repr(req.user.login)
57
59
    else:
58
60
        username = "null"
59
61
    req.write("""  <script type="text/javascript">
60
62
    root_dir = %s;
 
63
    public_host = %s;
61
64
    username = %s;
62
65
  </script>
63
 
""" % (repr(conf.root_dir), username))
64
 
    iconurl = get_icon_url(req.app)
 
66
""" % (repr(conf.root_dir), repr(conf.public_host), username))
 
67
    iconurl = get_icon_url(req.app, small=True)
65
68
    if iconurl:
66
69
        req.write("""  <link rel="shortcut icon" href="%s" />
67
70
""" % cgi.escape(iconurl))
73
76
        req.write('  <link rel="stylesheet" type="text/css" href="%s" />\n'
74
77
            % cgi.escape(util.make_path(style)))
75
78
    for script in req.scripts:
76
 
        req.write('  <script type="text/javascript" src="%s" />\n'
 
79
        req.write('  <script type="text/javascript" src="%s"></script>\n'
77
80
            % cgi.escape(util.make_path(script)))
 
81
    req.write('  <script type="text/javascript">\n    /* Init Functions */\n')
 
82
    for init in req.scripts_init:
 
83
        req.write('    window.addEventListener("load", %s, false);\n'%init)
 
84
    req.write('  </script>\n')
78
85
 
79
86
    req.write("</head>\n\n")
80
87
 
81
88
    # Open the body element and write a bunch of stuff there (the header)
82
89
    req.write("""<body>
83
 
<div id="ivleheader">
 
90
<div id="ivleheader"></div>
 
91
<div id="ivleheader_text">
84
92
  <h1>IVLE</h1>
85
93
  <h2>Informatics Virtual Learning Environment</h2>
86
94
""")
87
95
 
88
 
    if req.username:
89
 
        req.write('  <p class="userhello">Welcome, <span '
90
 
            'class="username">%s</span> |\n'
 
96
    if req.publicmode:
 
97
        req.write('   <p class="userhello">Running in public mode.</p>')
 
98
    elif req.user:
 
99
        # Get the user's nickname from the request session
 
100
        nickname = req.user.nick
 
101
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
 
102
            '(<span class="username">%s</span>) |\n'
 
103
            '    <a href="%s">Settings</a> |\n'
91
104
            '    <a href="%s">Help</a> |\n'
92
 
            '    <a href="%s">Logout</a>\n'
 
105
            '    <a href="%s">Sign out</a>\n'
93
106
            '  </p>\n' %
94
 
            (cgi.escape(req.username),
 
107
            (cgi.escape(nickname), cgi.escape(req.user.login),
 
108
             cgi.escape(util.make_path('settings')),
95
109
             cgi.escape(get_help_url(req)),
96
110
             cgi.escape(util.make_path('logout'))))
97
111
    else:
98
112
        req.write('  <p class="userhello">Not logged in.</p>')
99
113
 
 
114
    # ivleheader_tabs is a separate div, so it can be positioned absolutely
 
115
    req.write('</div>\n<div id="ivleheader_tabs">\n')
 
116
 
100
117
    # If the "debuginfo" app is installed, display a warning to the admin to
101
118
    # make sure it is removed in production.
102
119
    if "debuginfo" in conf.apps.app_url:
103
 
        req.write("  <p><small>Warning: debuginfo is enabled. Remove this "
104
 
            "app from conf.apps.app_url when placed into production."
105
 
            "</small></p>\n")
 
120
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
 
121
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
 
122
            "into production.</small></p>\n")
106
123
 
107
 
    if req.username:
 
124
    # If req has a "no_agreement" attribute, then it is because the user has
 
125
    # not signed the agreement; therefore we are displaying the TOS page.
 
126
    # Do not show apps (see dispatch.login).
 
127
    if req.user and not req.user.state == 'no_agreement':
108
128
        # Only print app tabs if logged in
109
129
        print_apps_list(req, req.app)
110
130
    req.write('</div>\n<div id="ivlebody">\n')
119
139
def get_help_url(req):
120
140
    """Gets the help URL most relevant to this page, to place as the
121
141
    "help" link at the top of the page."""
122
 
    if req.app == 'help':
 
142
    reqapp = req.app if hasattr(req, 'app') else None
 
143
    if reqapp == 'help':
123
144
        # We're already in help. Link to the exact current page
124
145
        # instead of the generic help page.
125
146
        return req.uri
126
 
    if conf.apps.app_url[req.app].hashelp:
127
 
        help_path = os.path.join('help', req.app)
 
147
    if reqapp is not None and reqapp in conf.apps.app_url and \
 
148
        conf.apps.app_url[reqapp].hashelp:
 
149
        help_path = os.path.join('help', reqapp)
128
150
    else:
129
151
        help_path = 'help'
130
152
    return util.make_path(help_path)
133
155
    """Given an app's url name, gets the URL of the icon image for this app,
134
156
    relative to the site root. Returns None if the app has no icon."""
135
157
    if appurl is None: return None
136
 
    app = conf.apps.app_url[appurl]
 
158
    try:
 
159
        app = conf.apps.app_url[appurl]
 
160
    except KeyError:
 
161
        # Due to navigating to a bad app
 
162
        return None
137
163
    if small:
138
164
        icon_dir = conf.apps.app_icon_dir_small
139
165
    else:
159
185
        file.write('    <li%s>' % li_attr)
160
186
        if app.icon:
161
187
            file.write('<img src="%s" alt="" /> '
162
 
                % cgi.escape(get_icon_url(urlname)))
163
 
        file.write('<a href="%s">%s</a></li>\n'
164
 
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
 
188
                % urllib.quote(get_icon_url(urlname)))
 
189
        file.write('<a href="%s" title="%s">%s</a></li>\n'
 
190
            % (urllib.quote(util.make_path(urlname)), cgi.escape(app.desc),
 
191
                cgi.escape(app.name)))
165
192
 
166
193
    file.write('  </ul>\n')