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

« back to all changes in this revision

Viewing changes to www/dispatch/html.py

  • Committer: mattgiuca
  • Date: 2008-02-25 02:54:45 UTC
  • Revision ID: svn-v3-trunk0:2b9c9e99-6f39-0410-b283-7f802c844ae2:trunk:563
install_proc: Notes on apt-get for epydoc and docutils.

Show diffs side-by-side

added added

removed removed

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