~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-12 15:39:43 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:202
authenticate.py: Now always returns true (temporarily).
    Reason: This allows any user to log in, with any password, for the time
    being. It is necessary to log in with your own user name to get certain
    things to work (and this is the best solution in the absence of a
    database).

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
 
    if req.user:
56
 
        username = repr(req.user.login)
 
54
    if req.username:
 
55
        username = repr(req.username)
57
56
    else:
58
57
        username = "null"
59
58
    req.write("""  <script type="text/javascript">
61
60
    username = %s;
62
61
  </script>
63
62
""" % (repr(conf.root_dir), username))
64
 
    iconurl = get_icon_url(req.app, small=True)
 
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
 
    if req.user:
90
 
        # Get the user's nickname from the request session
91
 
        nickname = req.user.nick
92
 
        req.write('  <p class="userhello"><span id="usernick">%s</span> '
93
 
            '(<span class="username">%s</span>) |\n'
94
 
            '    <a href="%s">Settings</a> |\n'
 
87
    if req.username:
 
88
        req.write('  <p class="userhello">Welcome, <span '
 
89
            'class="username">%s</span> |\n'
95
90
            '    <a href="%s">Help</a> |\n'
96
 
            '    <a href="%s">Sign out</a>\n'
 
91
            '    <a href="%s">Logout</a>\n'
97
92
            '  </p>\n' %
98
 
            (cgi.escape(nickname), cgi.escape(req.user.login),
99
 
             cgi.escape(util.make_path('settings')),
100
 
             cgi.escape(get_help_url(req)),
101
 
             cgi.escape(util.make_path('logout'))))
 
93
            (req.username, get_help_url(req), util.make_path('logout')))
102
94
    else:
103
95
        req.write('  <p class="userhello">Not logged in.</p>')
104
96
 
105
 
    # ivleheader_tabs is a separate div, so it can be positioned absolutely
106
 
    req.write('</div>\n<div id="ivleheader_tabs">\n')
107
 
 
108
97
    # If the "debuginfo" app is installed, display a warning to the admin to
109
98
    # make sure it is removed in production.
110
99
    if "debuginfo" in conf.apps.app_url:
111
 
        req.write("  <p><small>Warning: debuginfo is enabled. Set "
112
 
            "enable_debuginfo = False in lib/conf/apps.py, when placing IVLE "
113
 
            "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")
114
103
 
115
 
    # If req has a "no_agreement" attribute, then it is because the user has
116
 
    # not signed the agreement; therefore we are displaying the TOS page.
117
 
    # Do not show apps (see dispatch.login).
118
 
    if req.user and not req.user.state == 'no_agreement':
 
104
    if req.username:
119
105
        # Only print app tabs if logged in
120
106
        print_apps_list(req, req.app)
121
107
    req.write('</div>\n<div id="ivlebody">\n')
130
116
def get_help_url(req):
131
117
    """Gets the help URL most relevant to this page, to place as the
132
118
    "help" link at the top of the page."""
133
 
    reqapp = req.app if hasattr(req, 'app') else None
134
 
    if reqapp == 'help':
 
119
    if req.app == 'help':
135
120
        # We're already in help. Link to the exact current page
136
121
        # instead of the generic help page.
137
122
        return req.uri
138
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
139
 
        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)
140
125
    else:
141
126
        help_path = 'help'
142
127
    return util.make_path(help_path)
145
130
    """Given an app's url name, gets the URL of the icon image for this app,
146
131
    relative to the site root. Returns None if the app has no icon."""
147
132
    if appurl is None: return None
148
 
    try:
149
 
        app = conf.apps.app_url[appurl]
150
 
    except KeyError:
151
 
        # Due to navigating to a bad app
152
 
        return None
 
133
    app = conf.apps.app_url[appurl]
153
134
    if small:
154
135
        icon_dir = conf.apps.app_icon_dir_small
155
136
    else:
164
145
    file: Object with a "write" method - ie. the request object.
165
146
    Reads from: conf
166
147
    """
167
 
    file.write('  <ul id="apptabs">\n')
 
148
    file.write('  <ul class="apptabs">\n')
168
149
 
169
150
    for urlname in conf.apps.apps_in_tabs:
170
151
        app = conf.apps.app_url[urlname]
174
155
            li_attr = ''
175
156
        file.write('    <li%s>' % li_attr)
176
157
        if app.icon:
177
 
            file.write('<img src="%s" alt="" /> '
178
 
                % cgi.escape(get_icon_url(urlname)))
 
158
            file.write('<img src="%s" alt="" /> ' % get_icon_url(urlname))
179
159
        file.write('<a href="%s">%s</a></li>\n'
180
 
            % (cgi.escape(util.make_path(urlname)), cgi.escape(app.name)))
 
160
            % (util.make_path(urlname), app.name))
181
161
 
182
162
    file.write('  </ul>\n')