tori.controller

Author:Juti Noppornpitak

This package contains an abstract controller (based on tornado.web.RequestHandler) and built-in controllers.

class tori.controller.Controller(*args, **kwargs)

The abstract controller for Tori framework which uses Jinja2 as a template engine instead of the default one that comes with Tornado.

component(name, fork_component=False)

Get the (re-usable) component from the initialized Imagination component locator service.

Parameters:
  • name – the name of the registered re-usable component.
  • fork_component – the flag to fork the component
Returns:

module, package registered or None

redirect_to(route_id, params={}, full_url=False)

Redirect to the path by ID

Parameters:
  • str (id) – the path ID
  • params (dict) – the variables used in the routing pattern
  • full_url (bool) – option to provide full URL to the server.
render(template_name, **contexts)

Render the template with the given contexts and push the output buffer.

See tori.renderer.Renderer.render() for more information on the parameters.

render_template(template_name, **contexts)

Render the template with the given contexts.

See tori.renderer.Renderer.render() for more information on the parameters.

resolve_route(route_id, params={}, full_url=False)

Resolve the path by ID

Parameters:
  • str (id) – the path ID
  • params (dict) – the variables used in the routing pattern
  • full_url (bool) – option to provide full URL to the server.
session

Session Controller

Return type:tori.session.controller.Controller
template_engine

Template Engine

Return type:tori.template.renderer.Renderer
Raises:RenderingSourceMissingError – if the template base path and the reverse core reference are not defined.

Changed in version 3.0: The exception will not be raised if the reverse core reference is defined.

Note

The reverse core reference is the first instance of tori.application.Application in the process.

class tori.controller.ErrorController(*args, **kwargs)

Generates an error response with status_code for all requests.

class tori.controller.ResourceService(*args, **kwargs)

Resource service is to serve a static resource via HTTP/S protocol.

static add_pattern(pattern, base_path, enable_cache=False)

Add the routing pattern for the resource path prefix.

Parameters:
  • pattern – a routing pattern. It can be a Python-compatible regular expression.
  • base_path – a path prefix of the resource corresponding to the routing pattern.
  • enable_cache – a flag to indicate whether any loaded resources need to be cached on the first request.
get(path=None)

Get a particular resource.

Parameters:path – blocks of path used to composite an actual path.

Note

This method requires refactoring.

class tori.controller.RestController(*args, **kwargs)

Abstract REST-capable controller based on a single primary key.

create()

Create an entity.

delete(key=None)

Handle DELETE requests.

get(key=None)

Handle GET requests.

list()

Retrieve the list of all entities.

post(key=None)

Handle POST requests.

put(key=None)

Handle PUT requests.

remove(key)

Remove an entity with key.

retrieve(key)

Retrieve an entity with key.

update(key)

Update an entity with key.

class tori.controller.SimpleController(*args, **kwargs)

Simplified Request Controller