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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-06-13 04:54:25 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:762
setup.py: Modified library files list so it works on the latest
    set of packages for Ubuntu Gutsy (7.10).
    Note that an up-to-date Gutsy install broke IVLE due to newer
    versions of .so files with new names.
    This is a temporary solution, as this is going to keep happening
    (and it likely still won't work in Hardy). But at least it's working for
    now.

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