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

« back to all changes in this revision

Viewing changes to ivle/webapp/base/xhtml.py

  • Committer: William Grant
  • Date: 2009-04-29 04:58:42 UTC
  • Revision ID: grantw@unimelb.edu.au-20090429045842-upijb1ybcbz1zg6u
Kill --nosvnrevno from setup.install - we don't use Subversion now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import genshi.template
25
25
 
26
26
from ivle.webapp.media import media_url
 
27
from ivle.webapp.core import Plugin as CorePlugin
27
28
from ivle.webapp.base.views import BaseView
28
29
from ivle.webapp.base.plugins import ViewPlugin, OverlayPlugin
29
30
from ivle.webapp.errors import HTTPError, Unauthorized
30
 
import ivle.conf
31
 
import ivle.util
32
31
 
33
32
class XHTMLView(BaseView):
34
33
    """
47
46
        for key in kwargs:
48
47
            setattr(self, key, kwargs[key])
49
48
 
 
49
    def filter(self, stream, ctx):
 
50
        return stream
 
51
 
50
52
    def render(self, req):
51
53
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
52
54
 
58
60
        # view.
59
61
        app_template = os.path.join(os.path.dirname(
60
62
                        inspect.getmodule(self).__file__), self.template) 
61
 
        req.write_html_head_foot = False
62
63
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
63
64
        tmpl = loader.load(app_template)
64
 
        app = tmpl.generate(viewctx)
 
65
        app = self.filter(tmpl.generate(viewctx), viewctx)
65
66
 
66
67
        for plugin in self.plugin_scripts:
67
68
            for path in self.plugin_scripts[plugin]:
74
75
        # Global template
75
76
        ctx = genshi.template.Context()
76
77
        # XXX: Leave this here!! (Before req.styles is read)
77
 
        ctx['overlays'] = self.render_overlays(req)
78
 
        ctx['app_styles'] = req.styles
79
 
        ctx['scripts'] = req.scripts
 
78
        ctx['overlays'] = self.render_overlays(req) if req.user else []
 
79
 
 
80
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
 
81
        ctx['styles'] += req.styles
 
82
 
 
83
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
 
84
                           ('util.js', 'json2.js', 'md5.js')]
 
85
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
 
86
        ctx['scripts'] += req.scripts
 
87
 
80
88
        ctx['scripts_init'] = req.scripts_init
81
89
        ctx['app_template'] = app
 
90
        ctx['title_img'] = media_url(req, CorePlugin,
 
91
                                     "images/chrome/title.png")
82
92
        self.populate_headings(req, ctx)
83
93
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
84
94
                                                        'ivle-headings.html'))
89
99
 
90
100
    def populate_headings(self, req, ctx):
91
101
        ctx['favicon'] = None
92
 
        ctx['root_dir'] = ivle.conf.root_dir
93
 
        ctx['public_host'] = ivle.conf.public_host
 
102
        ctx['root_dir'] = req.config['urls']['root']
 
103
        ctx['public_host'] = req.config['urls']['public_host']
 
104
        ctx['svn_base'] = req.config['urls']['svn_addr']
94
105
        ctx['write_javascript_settings'] = req.write_javascript_settings
95
106
        if req.user:
96
107
            ctx['login'] = req.user.login
104
115
            ctx['help_path'] = self.help
105
116
 
106
117
        ctx['apps_in_tabs'] = []
107
 
        for plugin in req.plugin_index[ViewPlugin]:
 
118
        for plugin in req.config.plugin_index[ViewPlugin]:
108
119
            if not hasattr(plugin, 'tabs'):
109
120
                continue
110
121
 
111
122
            for tab in plugin.tabs:
112
123
                # tab is a tuple: name, title, desc, icon, path
113
124
                new_app = {}
114
 
                new_app['this_app'] = hasattr(self, 'appname') \
115
 
                                      and tab[0] == self.appname
 
125
                new_app['this_app'] = hasattr(self, 'tab') \
 
126
                                      and tab[0] == self.tab
116
127
 
117
128
                # Icon name
118
129
                if tab[3] is not None:
123
134
                        ctx['favicon'] = icon_url
124
135
                else:
125
136
                    new_app['has_icon'] = False
126
 
                new_app['path'] = ivle.util.make_path(tab[4])
 
137
                new_app['path'] = req.make_path(tab[4])
127
138
                new_app['desc'] = tab[2]
128
139
                new_app['name'] = tab[1]
129
140
                new_app['weight'] = tab[5]
141
152
        if not self.allow_overlays:
142
153
            return overlays
143
154
 
144
 
        for plugin in req.plugin_index[OverlayPlugin]:
 
155
        for plugin in req.config.plugin_index[OverlayPlugin]:
145
156
            for overclass in plugin.overlays:
146
157
                if overclass in self.overlay_blacklist:
147
158
                    continue
185
196
 
186
197
        if req.user is None:
187
198
            # Not logged in. Redirect to login page.
188
 
            req.throw_redirect('/+login?' + 
189
 
                               urllib.urlencode([('url', req.uri)]))
 
199
            if req.uri == '/':
 
200
                query_string = ''
 
201
            else:
 
202
                query_string = '?url=' + urllib.quote(req.uri, safe="/~")
 
203
            req.throw_redirect('/+login' + query_string)
190
204
 
191
205
        req.status = 403