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

« back to all changes in this revision

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

Install to /usr/local/lib/python2.5/site-packages, not
/usr/lib/python2.5/site-packages.

Show diffs side-by-side

added added

removed removed

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