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

« back to all changes in this revision

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

Remove most of the remaining legacy app glue from dispatch. Only the stuff
needed to run fileservice remains.

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
    """
37
38
    """
38
39
 
39
40
    template = 'template.html'
40
 
 
41
41
    plugin_scripts = {}
42
42
    plugin_styles = {}
43
 
    scripts_init = []
44
 
 
45
43
    allow_overlays = True
46
44
    overlay_blacklist = []
47
45
 
49
47
        for key in kwargs:
50
48
            setattr(self, key, kwargs[key])
51
49
 
52
 
    def filter(self, stream, ctx):
53
 
        return stream
54
 
 
55
50
    def render(self, req):
56
51
        req.content_type = 'text/html' # TODO: Detect application/xhtml+xml
57
52
 
63
58
        # view.
64
59
        app_template = os.path.join(os.path.dirname(
65
60
                        inspect.getmodule(self).__file__), self.template) 
 
61
        req.write_html_head_foot = False
66
62
        loader = genshi.template.TemplateLoader(".", auto_reload=True)
67
63
        tmpl = loader.load(app_template)
68
 
        app = self.filter(tmpl.generate(viewctx), viewctx)
 
64
        app = tmpl.generate(viewctx)
69
65
 
70
 
        view_scripts = []
71
66
        for plugin in self.plugin_scripts:
72
67
            for path in self.plugin_scripts[plugin]:
73
 
                view_scripts.append(media_url(req, plugin, path))
 
68
                req.scripts.append(media_url(req, plugin, path))
74
69
 
75
 
        view_styles = []
76
70
        for plugin in self.plugin_styles:
77
71
            for path in self.plugin_styles[plugin]:
78
 
                view_styles.append(media_url(req, plugin, path))
 
72
                req.styles.append(media_url(req, plugin, path))
79
73
 
80
74
        # Global template
81
75
        ctx = genshi.template.Context()
82
 
 
83
 
        overlay_bits = self.render_overlays(req) if req.user else [[]]*4
84
 
        ctx['overlays'] = overlay_bits[0]
85
 
 
86
 
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
87
 
        ctx['styles'] += view_styles
88
 
        ctx['styles'] += overlay_bits[1]
89
 
 
90
 
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
91
 
                           ('util.js', 'json2.js', 'md5.js')]
92
 
        ctx['scripts'].append(media_url(req, '+external/jquery', 'jquery.js'))
93
 
        ctx['scripts'] += view_scripts
94
 
        ctx['scripts'] += overlay_bits[2]
95
 
 
96
 
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
 
76
        # 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
 
80
        ctx['scripts_init'] = req.scripts_init
97
81
        ctx['app_template'] = app
98
 
        ctx['title_img'] = media_url(req, CorePlugin,
99
 
                                     "images/chrome/title.png")
100
82
        self.populate_headings(req, ctx)
101
83
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
102
84
                                                        'ivle-headings.html'))
107
89
 
108
90
    def populate_headings(self, req, ctx):
109
91
        ctx['favicon'] = None
110
 
        ctx['root_dir'] = req.config['urls']['root']
111
 
        ctx['public_host'] = req.config['urls']['public_host']
112
 
        ctx['svn_base'] = req.config['urls']['svn_addr']
 
92
        ctx['root_dir'] = ivle.conf.root_dir
 
93
        ctx['public_host'] = ivle.conf.public_host
113
94
        ctx['write_javascript_settings'] = req.write_javascript_settings
114
95
        if req.user:
115
96
            ctx['login'] = req.user.login
123
104
            ctx['help_path'] = self.help
124
105
 
125
106
        ctx['apps_in_tabs'] = []
126
 
        for plugin in req.config.plugin_index[ViewPlugin]:
 
107
        for plugin in req.plugin_index[ViewPlugin]:
127
108
            if not hasattr(plugin, 'tabs'):
128
109
                continue
129
110
 
130
111
            for tab in plugin.tabs:
131
112
                # tab is a tuple: name, title, desc, icon, path
132
113
                new_app = {}
133
 
                new_app['this_app'] = hasattr(self, 'tab') \
134
 
                                      and tab[0] == self.tab
 
114
                new_app['this_app'] = hasattr(self, 'appname') \
 
115
                                      and tab[0] == self.appname
135
116
 
136
117
                # Icon name
137
118
                if tab[3] is not None:
142
123
                        ctx['favicon'] = icon_url
143
124
                else:
144
125
                    new_app['has_icon'] = False
145
 
                new_app['path'] = req.make_path(tab[4])
 
126
                new_app['path'] = ivle.util.make_path(tab[4])
146
127
                new_app['desc'] = tab[2]
147
128
                new_app['name'] = tab[1]
148
129
                new_app['weight'] = tab[5]
157
138
        scripts_init.
158
139
        """
159
140
        overlays = []
160
 
        styles = []
161
 
        scripts = []
162
 
        scripts_init = []
163
141
        if not self.allow_overlays:
164
 
            return (overlays, styles, scripts, scripts_init)
 
142
            return overlays
165
143
 
166
 
        for plugin in req.config.plugin_index[OverlayPlugin]:
 
144
        for plugin in req.plugin_index[OverlayPlugin]:
167
145
            for overclass in plugin.overlays:
168
146
                if overclass in self.overlay_blacklist:
169
147
                    continue
171
149
                #TODO: Re-factor this to look nicer
172
150
                for mplugin in overlay.plugin_scripts:
173
151
                    for path in overlay.plugin_scripts[mplugin]:
174
 
                        scripts.append(media_url(req, mplugin, path))
 
152
                        req.scripts.append(media_url(req, mplugin, path))
175
153
 
176
154
                for mplugin in overlay.plugin_styles:
177
155
                    for path in overlay.plugin_styles[mplugin]:
178
 
                        styles.append(media_url(req, mplugin, path))
 
156
                        req.styles.append(media_url(req, mplugin, path))
179
157
 
180
 
                scripts_init += overlay.plugin_scripts_init
 
158
                req.scripts_init += overlay.plugin_scripts_init
181
159
 
182
160
                overlays.append(overlay.render(req))
183
 
        return (overlays, styles, scripts, scripts_init)
 
161
        return overlays
184
162
 
185
163
    @classmethod
186
164
    def get_error_view(cls, e):
207
185
 
208
186
        if req.user is None:
209
187
            # Not logged in. Redirect to login page.
210
 
            if req.uri == '/':
211
 
                query_string = ''
212
 
            else:
213
 
                query_string = '?url=' + urllib.quote(req.uri, safe="/~")
214
 
            req.throw_redirect('/+login' + query_string)
 
188
            req.throw_redirect('/+login?' + 
 
189
                               urllib.urlencode([('url', req.uri)]))
215
190
 
216
191
        req.status = 403