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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-02-05 01:41:15 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:409
Moved www/conf and www/common to a new directory lib. This separates the "web"
part of IVLE from what is becoming less web oriented (at least from Apache's
standpoint).
Modified setup.py to install this lib directory correctly and write conf in
the right place. Also adds the lib directory to ivle.pth.

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
28
27
import os.path
29
28
 
30
29
import conf
31
30
import conf.apps
32
31
from common import util
33
 
import plugins.console
34
32
 
35
33
def write_html_head(req):
36
34
    """Writes the HTML header, given a request object.
54
52
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
55
53
    # Write inline JavaScript which gives the client code access to certain
56
54
    # server-side variables.
57
 
    if req.user:
58
 
        username = repr(req.user.login)
 
55
    if req.username:
 
56
        username = repr(req.username)
59
57
    else:
60
58
        username = "null"
61
59
    req.write("""  <script type="text/javascript">
62
60
    root_dir = %s;
63
 
    public_host = %s;
64
61
    username = %s;
65
62
  </script>
66
 
""" % (repr(conf.root_dir), repr(conf.public_host), username))
67
 
    iconurl = get_icon_url(req.app, small=True)
 
63
""" % (repr(conf.root_dir), username))
 
64
    iconurl = get_icon_url(req.app)
68
65
    if iconurl:
69
66
        req.write("""  <link rel="shortcut icon" href="%s" />
70
67
""" % cgi.escape(iconurl))
76
73
        req.write('  <link rel="stylesheet" type="text/css" href="%s" />\n'
77
74
            % cgi.escape(util.make_path(style)))
78
75
    for script in req.scripts:
79
 
        req.write('  <script type="text/javascript" src="%s"></script>\n'
 
76
        req.write('  <script type="text/javascript" src="%s" />\n'
80
77
            % 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')
85
78
 
86
79
    req.write("</head>\n\n")
87
80
 
93
86
  <h2>Informatics Virtual Learning Environment</h2>
94
87
""")
95
88
 
96
 
    if req.publicmode:
97
 
        req.write('   <p class="userhello">Running in public mode.</p>')
98
 
    elif req.user:
 
89
    if req.username:
99
90
        # 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
        nickname = req.get_session()['nick']
 
92
        req.write('  <p class="userhello">%s (<span '
 
93
            'class="username">%s</span>) |\n'
104
94
            '    <a href="%s">Help</a> |\n'
105
 
            '    <a href="%s">Sign out</a>\n'
 
95
            '    <a href="%s">Logout</a>\n'
106
96
            '  </p>\n' %
107
 
            (cgi.escape(nickname), cgi.escape(req.user.login),
108
 
             cgi.escape(util.make_path('settings')),
 
97
            (cgi.escape(nickname), cgi.escape(req.username),
109
98
             cgi.escape(get_help_url(req)),
110
99
             cgi.escape(util.make_path('logout'))))
111
100
    else:
117
106
    # If the "debuginfo" app is installed, display a warning to the admin to
118
107
    # make sure it is removed in production.
119
108
    if "debuginfo" in conf.apps.app_url:
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")
 
109
        req.write("  <p><small>Warning: debuginfo is enabled. Remove this "
 
110
            "app from conf.apps.app_url when placed into production."
 
111
            "</small></p>\n")
123
112
 
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':
 
113
    if req.username:
128
114
        # Only print app tabs if logged in
129
115
        print_apps_list(req, req.app)
130
116
    req.write('</div>\n<div id="ivlebody">\n')
139
125
def get_help_url(req):
140
126
    """Gets the help URL most relevant to this page, to place as the
141
127
    "help" link at the top of the page."""
142
 
    reqapp = req.app if hasattr(req, 'app') else None
143
 
    if reqapp == 'help':
 
128
    if req.app == 'help':
144
129
        # We're already in help. Link to the exact current page
145
130
        # instead of the generic help page.
146
131
        return req.uri
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)
 
132
    if conf.apps.app_url[req.app].hashelp:
 
133
        help_path = os.path.join('help', req.app)
150
134
    else:
151
135
        help_path = 'help'
152
136
    return util.make_path(help_path)
155
139
    """Given an app's url name, gets the URL of the icon image for this app,
156
140
    relative to the site root. Returns None if the app has no icon."""
157
141
    if appurl is None: return None
158
 
    try:
159
 
        app = conf.apps.app_url[appurl]
160
 
    except KeyError:
161
 
        # Due to navigating to a bad app
162
 
        return None
 
142
    app = conf.apps.app_url[appurl]
163
143
    if small:
164
144
        icon_dir = conf.apps.app_icon_dir_small
165
145
    else:
185
165
        file.write('    <li%s>' % li_attr)
186
166
        if app.icon:
187
167
            file.write('<img src="%s" alt="" /> '
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)))
 
168
                % cgi.escape(get_icon_url(urlname)))
 
169
        file.write('<a href="%s">%s</a></li>\n'
 
170
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
192
171
 
193
172
    file.write('  </ul>\n')