watson.framework.controllers¶
- class watson.framework.controllers.Action[source]¶
A controller thats methods can be accessed with an _action suffix.
Example:
class MyController(controllers.Action): def my_func_action(self): return 'something'
- class watson.framework.controllers.FlashMessagesContainer(session)[source]¶
Contains all the flash messages associated with a controller.
Flash messages persist across requests until they are displayed to the user.
- __init__(session)[source]¶
Initializes the container.
Parameters: session (watson.http.session.StorageMixin) – A session object containing the flash messages data.
- add(message, namespace='info')[source]¶
Adds a flash message within the specified namespace.
Parameters: - message (string) – The message to add to the container.
- namespace (string) – The namespace to sit the message in.
- class watson.framework.controllers.HttpMixin[source]¶
A mixin for controllers that can contain http request and response objects.
- _request¶
The request made that has triggered the controller
- _response¶
The response that will be returned by the controller
- event[source]¶
The event that was triggered that caused the execution of the controller.
Returns: watson.events.types.Event
- flash_messages[source]¶
Retrieves all the flash messages associated with the controller.
Example:
# within controller action self.flash_messages.add('Some message') return { 'flash_messages': self.flash_messages } # within view {% for namespace, message in flash_messages %} {{ message }} {% endfor %}
Returns: A watson.framework.controllers.FlashMessagesContainer object.
- forward(controller, method=None, *args, **kwargs)[source]¶
Fowards a request across to a different controller.
- controller string|object¶
The controller to execute
- method string¶
The method to run, defaults to currently called method
Returns: Response from other controller.
- redirect(path, params=None, status_code=302, clear=False)[source]¶
Redirect to a different route.
Redirecting will bypass the rendering of the view, and the body of the request will be displayed.
Also supports Post Redirect Get (http://en.wikipedia.org/wiki/Post/Redirect/Get) which can allow post variables to accessed from a GET resource after a redirect (to repopulate form fields for example).
Parameters: - path (string) – The URL or route name to redirect to
- params (dict) – The params to send to the route
- status_code (int) – The status code to use for the redirect
- clear (bool) – Whether or not the session data should be cleared
Returns: A watson.http.messages.Response object.
- response[source]¶
The HTTP response related to the controller.
If no response object has been set, then a new one will be generated.
Returns: watson.http.messages.Response
- url(route_name, host=None, scheme=None, **params)[source]¶
Converts a route into a url.
Parameters: - route_name (string) – The name of the route to convert
- host (string) – The hostname to prepend to the route path
- scheme (string) – The scheme to prepend to the route path
- params (dict) – The params to use on the route
Returns: The assembled url.