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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

Add support for public mode views to the new framework.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
import ivle.conf.apps
46
46
from ivle.dispatch.request import Request
47
47
from ivle.dispatch import login
48
 
from ivle.webapp.base.plugins import ViewPlugin
 
48
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
49
49
from ivle.webapp.errors import HTTPError, Unauthorized
50
50
import apps
51
51
import html
70
70
    'ivle.webapp.userservice#Plugin',
71
71
72
72
 
73
 
def generate_route_mapper(view_plugins):
 
73
def generate_route_mapper(view_plugins, attr):
74
74
    """
75
75
    Build a Mapper object for doing URL matching using 'routes', based on the
76
76
    given plugin registry.
79
79
    for plugin in view_plugins:
80
80
        # Establish a URL pattern for each element of plugin.urls
81
81
        assert hasattr(plugin, 'urls'), "%r does not have any urls" % plugin 
82
 
        for url in plugin.urls:
 
82
        for url in getattr(plugin, attr):
83
83
            routex = url[0]
84
84
            view_class = url[1]
85
85
            kwargs_dict = url[2] if len(url) >= 3 else {}
150
150
                req.plugin_index[base] = []
151
151
            req.plugin_index[base].append(plugin)
152
152
    req.reverse_plugins = dict([(v, k) for (k, v) in req.plugins.items()])
153
 
    req.mapper = generate_route_mapper(req.plugin_index[ViewPlugin])
 
153
 
 
154
    if req.publicmode:
 
155
        req.mapper = generate_route_mapper(req.plugin_index[PublicViewPlugin],
 
156
                                           'public_urls')
 
157
    else:
 
158
        req.mapper = generate_route_mapper(req.plugin_index[ViewPlugin],
 
159
                                           'urls')
154
160
 
155
161
    matchdict = req.mapper.match(req.uri)
156
162
    if matchdict is not None: