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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: dilshan_a
  • Date: 2008-01-25 00:20:21 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:295
Added a filesum problem.
Updated paths in test.py and test.py

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