~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-15 06:17:23 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:233
Added a shaky implementation of EditArea as the text editor.
Installed the EditArea files in media/common.
FileBrowser app includes EditArea.
editor.js calls the appropriate methods to set up an EditArea and the Save
button saves its contents.

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
50
48
<head>
51
49
  <title>%sIVLE</title>
52
50
  <meta http-equiv="Content-Type" content="%s; charset=utf-8" />
53
 
""" % (cgi.escape(titlepart), cgi.escape(req.content_type)))
 
51
""" % (titlepart, req.content_type))
54
52
    # Write inline JavaScript which gives the client code access to certain
55
53
    # server-side variables.
56
 
    if req.user:
57
 
        username = repr(req.user.login)
 
54
    if req.username:
 
55
        username = repr(req.username)
58
56
    else:
59
57
        username = "null"
60
58
    req.write("""  <script type="text/javascript">
61
59
    root_dir = %s;
62
 
    public_host = %s;
63
60
    username = %s;
64
61
  </script>
65
 
""" % (repr(conf.root_dir), repr(conf.public_host), username))
66
 
    iconurl = get_icon_url(req.app, small=True)
 
62
""" % (repr(conf.root_dir), username))
 
63
    iconurl = get_icon_url(req.app)
67
64
    if iconurl:
68
65
        req.write("""  <link rel="shortcut icon" href="%s" />
69
 
""" % cgi.escape(iconurl))
 
66
""" % iconurl)
70
67
    req.write("""  <link rel="stylesheet" type="text/css" href="%s" />
71
 
""" % cgi.escape(util.make_path('media/common/ivle.css')))
 
68
""" % util.make_path('media/common/ivle.css'))
72
69
 
73
70
    # Write any app-specific style and script links
74
71
    for style in req.styles:
75
72
        req.write('  <link rel="stylesheet" type="text/css" href="%s" />\n'
76
 
            % cgi.escape(util.make_path(style)))
 
73
            % util.make_path(style))
77
74
    for script in req.scripts:
78
 
        req.write('  <script type="text/javascript" src="%s"></script>\n'
79
 
            % cgi.escape(util.make_path(script)))
 
75
        req.write('  <script type="text/javascript" src="%s" />\n'
 
76
            % util.make_path(script))
80
77
 
81
78
    req.write("</head>\n\n")
82
79
 
83
80
    # Open the body element and write a bunch of stuff there (the header)
84
81
    req.write("""<body>
85
 
<div id="ivleheader"></div>
86
 
<div id="ivleheader_text">
 
82
<div id="ivleheader">
87
83
  <h1>IVLE</h1>
88
84
  <h2>Informatics Virtual Learning Environment</h2>
89
85
""")
90
86
 
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'
 
87
    if req.username:
 
88
        req.write('  <p class="userhello">Welcome, <span '
 
89
            'class="username">%s</span> |\n'
97
90
            '    <a href="%s">Help</a> |\n'
98
 
            '    <a href="%s">Sign out</a>\n'
 
91
            '    <a href="%s">Logout</a>\n'
99
92
            '  </p>\n' %
100
 
            (cgi.escape(nickname), cgi.escape(req.user.login),
101
 
             cgi.escape(util.make_path('settings')),
102
 
             cgi.escape(get_help_url(req)),
103
 
             cgi.escape(util.make_path('logout'))))
 
93
            (req.username, get_help_url(req), util.make_path('logout')))
104
94
    else:
105
95
        req.write('  <p class="userhello">Not logged in.</p>')
106
96
 
107
 
    # ivleheader_tabs is a separate div, so it can be positioned absolutely
108
 
    req.write('</div>\n<div id="ivleheader_tabs">\n')
109
 
 
110
97
    # If the "debuginfo" app is installed, display a warning to the admin to
111
98
    # make sure it is removed in production.
112
99
    if "debuginfo" in conf.apps.app_url:
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")
 
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")
116
103
 
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':
 
104
    if req.username:
121
105
        # Only print app tabs if logged in
122
106
        print_apps_list(req, req.app)
123
107
    req.write('</div>\n<div id="ivlebody">\n')
132
116
def get_help_url(req):
133
117
    """Gets the help URL most relevant to this page, to place as the
134
118
    "help" link at the top of the page."""
135
 
    reqapp = req.app if hasattr(req, 'app') else None
136
 
    if reqapp == 'help':
 
119
    if req.app == 'help':
137
120
        # We're already in help. Link to the exact current page
138
121
        # instead of the generic help page.
139
122
        return req.uri
140
 
    if reqapp is not None and conf.apps.app_url[reqapp].hashelp:
141
 
        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)
142
125
    else:
143
126
        help_path = 'help'
144
127
    return util.make_path(help_path)
147
130
    """Given an app's url name, gets the URL of the icon image for this app,
148
131
    relative to the site root. Returns None if the app has no icon."""
149
132
    if appurl is None: return None
150
 
    try:
151
 
        app = conf.apps.app_url[appurl]
152
 
    except KeyError:
153
 
        # Due to navigating to a bad app
154
 
        return None
 
133
    app = conf.apps.app_url[appurl]
155
134
    if small:
156
135
        icon_dir = conf.apps.app_icon_dir_small
157
136
    else:
176
155
            li_attr = ''
177
156
        file.write('    <li%s>' % li_attr)
178
157
        if app.icon:
179
 
            file.write('<img src="%s" alt="" /> '
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)))
 
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))
184
161
 
185
162
    file.write('  </ul>\n')