morepath.publish – Web publisher¶
Functionality to turn a morepath.Request into a
morepath.Response using Morepath configuration. It looks up a
model instance for the request path and parameters, then looks up a
view for that model object to create the response.
The publish module:
- resolves the request into a model object.
- resolves the model object and the request into a view.
- the view then generates a response.
It all starts at publish().
-
morepath.publish.consume(app, request)¶ Consume path segments from request to find model obj.
Removes the successfully consumed path segments from
morepath.Request.unconsumed.Uses
morepath.traject.Traject.consume()to consume path segments according to path configuration.Extracts URL parameters from the path.
Gets a factory function and uses matched path variables and URL parameters to construct the model instance (or
morepath.Appinstance).Parameters: - app – the
morepath.Appinstance that contains the path registry to use. - request –
morepath.Requestinstance that contains the path segments to consume.
Returns: The new model object, or a mounted
morepath.Appinstance, orNoneif no new instance could be found.- app – the
-
morepath.publish.get_view_name(stack)¶ Determine view name from leftover stack of path segments
Parameters: stack – a list of path segments left over after consuming the path. Returns: view name string or Noneif no view name can be determined.
-
morepath.publish.publish(request)¶ Handle request and return response.
It uses
resolve_model()to use the information inrequest(path, request method, etc) to resolve to a model object.resolve_response()then creates a view for the request and the object.Parameters: - request –
morepath.Requestinstance. - return –
morepath.Responseinstance.
- request –
-
morepath.publish.resolve_model(request)¶ Resolve request to a model object.
This takes the path information as a stack of path segments in
morepath.Request.unconsumedand consumes it step by step usingconsume()to find the model object as declared bymorepath.App.path()directive. It can traverse through mounted applications as indicated by themorepath.App.mount()directive.The implicit Reg lookup used to look up generic dispatch functions is set to the app and is updated to the mounted application when traversing into it.
Param: morepath.Requestinstance.Returns: model object or Noneif not found.
-
morepath.publish.resolve_response(obj, request)¶ Given model object and request, create response.
This uses
get_view_name()to set up the view name on the request object.If no view name exist it raises
webob.exc.HTTPNotFound.It then uses
morepath.generic.view()to resolve the view for the model object and the request by doing dynamic dispatch.Parameters: - obj – model object to get response for.
- request –
morepath.Requestinstance.
Returns: morepath.Responseinstance