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

« back to all changes in this revision

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

Fix circular import in ivle.zip.

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
28
27
from ivle.webapp.base.views import BaseView
29
28
from ivle.webapp.base.plugins import ViewPlugin, OverlayPlugin
30
29
from ivle.webapp.errors import HTTPError, Unauthorized
 
30
import ivle.conf
 
31
import ivle.util
31
32
 
32
33
class XHTMLView(BaseView):
33
34
    """
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 []
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
 
 
 
77
        ctx['overlays'] = self.render_overlays(req)
 
78
        ctx['app_styles'] = req.styles
 
79
        ctx['scripts'] = req.scripts
88
80
        ctx['scripts_init'] = req.scripts_init
89
81
        ctx['app_template'] = app
90
 
        ctx['title_img'] = media_url(req, CorePlugin,
91
 
                                     "images/chrome/title.png")
92
82
        self.populate_headings(req, ctx)
93
83
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
94
84
                                                        'ivle-headings.html'))
99
89
 
100
90
    def populate_headings(self, req, ctx):
101
91
        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']
 
92
        ctx['root_dir'] = ivle.conf.root_dir
 
93
        ctx['public_host'] = ivle.conf.public_host
105
94
        ctx['write_javascript_settings'] = req.write_javascript_settings
106
95
        if req.user:
107
96
            ctx['login'] = req.user.login
115
104
            ctx['help_path'] = self.help
116
105
 
117
106
        ctx['apps_in_tabs'] = []
118
 
        for plugin in req.config.plugin_index[ViewPlugin]:
 
107
        for plugin in req.plugin_index[ViewPlugin]:
119
108
            if not hasattr(plugin, 'tabs'):
120
109
                continue
121
110
 
122
111
            for tab in plugin.tabs:
123
112
                # tab is a tuple: name, title, desc, icon, path
124
113
                new_app = {}
125
 
                new_app['this_app'] = hasattr(self, 'tab') \
126
 
                                      and tab[0] == self.tab
 
114
                new_app['this_app'] = hasattr(self, 'appname') \
 
115
                                      and tab[0] == self.appname
127
116
 
128
117
                # Icon name
129
118
                if tab[3] is not None:
134
123
                        ctx['favicon'] = icon_url
135
124
                else:
136
125
                    new_app['has_icon'] = False
137
 
                new_app['path'] = req.make_path(tab[4])
 
126
                new_app['path'] = ivle.util.make_path(tab[4])
138
127
                new_app['desc'] = tab[2]
139
128
                new_app['name'] = tab[1]
140
129
                new_app['weight'] = tab[5]
152
141
        if not self.allow_overlays:
153
142
            return overlays
154
143
 
155
 
        for plugin in req.config.plugin_index[OverlayPlugin]:
 
144
        for plugin in req.plugin_index[OverlayPlugin]:
156
145
            for overclass in plugin.overlays:
157
146
                if overclass in self.overlay_blacklist:
158
147
                    continue
196
185
 
197
186
        if req.user is None:
198
187
            # 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)
 
188
            req.throw_redirect('/+login?' + 
 
189
                               urllib.urlencode([('url', req.uri)]))
204
190
 
205
191
        req.status = 403