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

« back to all changes in this revision

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

Update docs to comply with more recent Debian standards, and IVLE changes.

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
    """
37
39
    """
38
40
 
39
41
    template = 'template.html'
40
 
 
41
42
    plugin_scripts = {}
42
43
    plugin_styles = {}
43
 
    scripts_init = []
44
 
 
45
 
    allow_overlays = True
46
44
    overlay_blacklist = []
47
45
 
48
46
    def __init__(self, req, **kwargs):
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]
 
76
        # XXX: Leave this here!! (Before req.styles is read)
 
77
        ctx['overlays'] = self.render_overlays(req)
85
78
 
86
79
        ctx['styles'] = [media_url(req, CorePlugin, 'ivle.css')]
87
 
        ctx['styles'] += view_styles
88
 
        ctx['styles'] += overlay_bits[1]
 
80
        ctx['styles'] += req.styles
89
81
 
90
82
        ctx['scripts'] = [media_url(req, CorePlugin, path) for path in
91
83
                           ('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]
 
84
        ctx['scripts'] += req.scripts
95
85
 
96
 
        ctx['scripts_init'] = self.scripts_init + overlay_bits[3]
 
86
        ctx['scripts_init'] = req.scripts_init
97
87
        ctx['app_template'] = app
98
 
        ctx['title_img'] = media_url(req, CorePlugin,
99
 
                                     "images/chrome/title.png")
100
88
        self.populate_headings(req, ctx)
101
89
        tmpl = loader.load(os.path.join(os.path.dirname(__file__), 
102
90
                                                        'ivle-headings.html'))
107
95
 
108
96
    def populate_headings(self, req, ctx):
109
97
        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']
 
98
        ctx['root_dir'] = ivle.conf.root_dir
 
99
        ctx['public_host'] = ivle.conf.public_host
113
100
        ctx['write_javascript_settings'] = req.write_javascript_settings
114
101
        if req.user:
115
102
            ctx['login'] = req.user.login
123
110
            ctx['help_path'] = self.help
124
111
 
125
112
        ctx['apps_in_tabs'] = []
126
 
        for plugin in req.config.plugin_index[ViewPlugin]:
 
113
        for plugin in req.plugin_index[ViewPlugin]:
127
114
            if not hasattr(plugin, 'tabs'):
128
115
                continue
129
116
 
130
117
            for tab in plugin.tabs:
131
118
                # tab is a tuple: name, title, desc, icon, path
132
119
                new_app = {}
133
 
                new_app['this_app'] = hasattr(self, 'tab') \
134
 
                                      and tab[0] == self.tab
 
120
                new_app['this_app'] = hasattr(self, 'appname') \
 
121
                                      and tab[0] == self.appname
135
122
 
136
123
                # Icon name
137
124
                if tab[3] is not None:
142
129
                        ctx['favicon'] = icon_url
143
130
                else:
144
131
                    new_app['has_icon'] = False
145
 
                new_app['path'] = req.make_path(tab[4])
 
132
                new_app['path'] = ivle.util.make_path(tab[4])
146
133
                new_app['desc'] = tab[2]
147
134
                new_app['name'] = tab[1]
148
135
                new_app['weight'] = tab[5]
157
144
        scripts_init.
158
145
        """
159
146
        overlays = []
160
 
        styles = []
161
 
        scripts = []
162
 
        scripts_init = []
163
 
        if not self.allow_overlays:
164
 
            return (overlays, styles, scripts, scripts_init)
165
 
 
166
 
        for plugin in req.config.plugin_index[OverlayPlugin]:
 
147
        for plugin in req.plugin_index[OverlayPlugin]:
167
148
            for overclass in plugin.overlays:
168
149
                if overclass in self.overlay_blacklist:
169
150
                    continue
171
152
                #TODO: Re-factor this to look nicer
172
153
                for mplugin in overlay.plugin_scripts:
173
154
                    for path in overlay.plugin_scripts[mplugin]:
174
 
                        scripts.append(media_url(req, mplugin, path))
 
155
                        req.scripts.append(media_url(req, mplugin, path))
175
156
 
176
157
                for mplugin in overlay.plugin_styles:
177
158
                    for path in overlay.plugin_styles[mplugin]:
178
 
                        styles.append(media_url(req, mplugin, path))
 
159
                        req.styles.append(media_url(req, mplugin, path))
179
160
 
180
 
                scripts_init += overlay.plugin_scripts_init
 
161
                req.scripts_init += overlay.plugin_scripts_init
181
162
 
182
163
                overlays.append(overlay.render(req))
183
 
        return (overlays, styles, scripts, scripts_init)
 
164
        return overlays
184
165
 
185
166
    @classmethod
186
167
    def get_error_view(cls, e):
207
188
 
208
189
        if req.user is None:
209
190
            # 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)
 
191
            req.throw_redirect('/+login?' + 
 
192
                               urllib.urlencode([('url', req.uri)]))
215
193
 
216
194
        req.status = 403