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

« back to all changes in this revision

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

  • Committer: David Coles
  • Date: 2009-08-17 21:11:50 UTC
  • Revision ID: coles.david@gmail.com-20090817211150-r3bljeiv5t78v0uz
Normalise usernames to lowercase so that they are case insensitive.
This is to prevent an issue with a certain "unnamed LDAP service" doing case insensative lookups meaning we will create duplicate users.
Fixes lp:415171

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