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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

Merge from object-publishing.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
46
46
from ivle.webapp.base.xhtml import XHTMLView, XHTMLErrorView
47
47
from ivle.webapp.errors import HTTPError, Unauthorized, NotFound
48
 
from ivle.webapp.routing import Router, RoutingError
 
48
from ivle.webapp.publisher import Publisher, PublishingError
49
49
from ivle.webapp import ApplicationRoot
50
50
 
51
51
config = ivle.config.Config()
52
52
 
53
 
def generate_router(view_plugins, root):
 
53
def generate_publisher(view_plugins, root):
54
54
    """
55
55
    Build a Mapper object for doing URL matching using 'routes', based on the
56
56
    given plugin registry.
57
57
    """
58
 
    r = Router(root=root)
 
58
    r = Publisher(root=root)
59
59
 
60
60
    r.add_set_switch('api', 'api')
61
61
 
104
104
    if req.publicmode:
105
105
        raise NotImplementedError("no public mode with obtrav yet!")
106
106
 
107
 
    req.router = generate_router(config.plugin_index[ViewPlugin],
 
107
    req.publisher = generate_publisher(config.plugin_index[ViewPlugin],
108
108
                                 ApplicationRoot(req.config, req.store))
109
109
 
110
110
    try:
111
 
        obj, viewcls, subpath = req.router.resolve(req.uri.decode('utf-8'))
 
111
        obj, viewcls, subpath = req.publisher.resolve(req.uri.decode('utf-8'))
112
112
        try:
113
113
            # We 404 if we have a subpath but the view forbids it.
114
114
            if not viewcls.subpath_allowed and subpath:
134
134
                errviewcls = XHTMLView.get_error_view(e)
135
135
 
136
136
            if errviewcls:
137
 
                errview = errviewcls(req, e)
 
137
                errview = errviewcls(req, e, obj)
138
138
                errview.render(req)
139
139
                return req.OK
140
140
            elif e.message:
154
154
        else:
155
155
            req.store.commit()
156
156
            return req.OK
157
 
    except RoutingError, e:
 
157
    except PublishingError, e:
 
158
        req.status = 404
 
159
 
158
160
        if req.user.admin:
159
161
            XHTMLErrorView(req, NotFound('Not found: ' +
160
 
                                         str(e.args))).render(req)
 
162
                                         str(e.args)), e[0]).render(req)
161
163
        else:
162
 
            XHTMLErrorView(req, NotFound()).render(req)
 
164
            XHTMLErrorView(req, NotFound(), e[0]).render(req)
163
165
 
164
166
        return req.OK
165
167