~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:32:54 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:200
fileservice.listing: Now returns a nicer date format for mtime_nice.
    Applies an intuitive algorithm to make the date even shorter,
    (eg. "today" or "3 days ago") and returns this as mtime_short.
util.js: Fixed path_join if the first path is empty. (Was incorrectly adding
    a leading slash).
    Added optional "title" arguments to dom_make_text_elem and
    dom_make_link_elem.
browser.js: Displays mtime_short in the file table instead of mtime_nice
    (it was always too long). Displays the full date as a tooltip.
    Auto-navigates to the user's home directory if accessed from the root.
    (This may be a temporary measure, but it was giving a mean error before).
    Various code makes use of util's new optional "title" arguments.
dispatch.html: Writes a new JavaScript variable, "username", so JavaScript
    code knows which user is logged in.
    Cleaned up JS variables repr (previously they did bad escapes in some
    cases).

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
    # Note the inline JavaScript, which provides the client with constants
40
40
    # derived from the server configuration.
41
41
    if req.title != None:
42
 
        titlepart = ' - ' + req.title
 
42
        titlepart = req.title + ' - '
43
43
    else:
44
44
        titlepart = ''
45
45
    req.write("""<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
46
46
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
47
47
<html xmlns="http://www.w3.org/1999/xhtml">
48
48
<head>
49
 
  <title>IVLE%s</title>
 
49
  <title>%sIVLE</title>
50
50
  <meta http-equiv="Content-Type" content="%s; charset=utf-8" />
51
 
  <script type="text/javascript">
52
 
    root_dir = "%s";
 
51
""" % (titlepart, req.content_type))
 
52
    # Write inline JavaScript which gives the client code access to certain
 
53
    # server-side variables.
 
54
    if req.username:
 
55
        username = repr(req.username)
 
56
    else:
 
57
        username = "null"
 
58
    req.write("""  <script type="text/javascript">
 
59
    root_dir = %s;
 
60
    username = %s;
53
61
  </script>
54
 
  <link rel="stylesheet" type="text/css" href="%s" />
55
 
""" % (titlepart, req.content_type,
56
 
        repr(conf.root_dir)[1:-1],
57
 
        util.make_path('media/common/ivle.css')))
 
62
""" % (repr(conf.root_dir), username))
 
63
    iconurl = get_icon_url(req.app)
 
64
    if iconurl:
 
65
        req.write("""  <link rel="shortcut icon" href="%s" />
 
66
""" % iconurl)
 
67
    req.write("""  <link rel="stylesheet" type="text/css" href="%s" />
 
68
""" % util.make_path('media/common/ivle.css'))
58
69
 
59
70
    # Write any app-specific style and script links
60
71
    for style in req.styles:
69
80
    # Open the body element and write a bunch of stuff there (the header)
70
81
    req.write("""<body>
71
82
<div id="ivleheader">
72
 
  <h1>IVLE - Informatics Virtual Learning Environment</h1>
 
83
  <h1>IVLE</h1>
 
84
  <h2>Informatics Virtual Learning Environment</h2>
73
85
""")
74
86
 
75
87
    if req.username:
114
126
        help_path = 'help'
115
127
    return util.make_path(help_path)
116
128
 
 
129
def get_icon_url(appurl, small=False):
 
130
    """Given an app's url name, gets the URL of the icon image for this app,
 
131
    relative to the site root. Returns None if the app has no icon."""
 
132
    if appurl is None: return None
 
133
    app = conf.apps.app_url[appurl]
 
134
    if small:
 
135
        icon_dir = conf.apps.app_icon_dir_small
 
136
    else:
 
137
        icon_dir = conf.apps.app_icon_dir
 
138
    if app.icon is None: return None
 
139
    return util.make_path(os.path.join(icon_dir, app.icon))
 
140
 
117
141
def print_apps_list(file, thisapp):
118
142
    """Prints all app tabs, as a UL. Prints a list item for each app that has
119
143
    a tab.
129
153
            li_attr = ' class="thisapp"'
130
154
        else:
131
155
            li_attr = ''
132
 
        file.write('    <li%s><a href="%s">%s</a></li>\n'
133
 
            % (li_attr, util.make_path(urlname), app.name))
 
156
        file.write('    <li%s>' % li_attr)
 
157
        if app.icon:
 
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))
134
161
 
135
162
    file.write('  </ul>\n')