control

New in version 1.1.0.

Control in MVC – Base Controller and helpers like function-to-URL conversion.

class smisk.mvc.control.Controller

The base controller from which the controller tree is grown.

To grow a controller tree, you need to set a root first. This is done by defining a subclass of Controller with the special name ‘root’ (case-insensitive).

Here is a very simple, but valid, controller tree:

class root(Controller):
  def hello(self):
    return {'message': 'Hello'}
controller_name

Returns the canonical name of this controller.

Return type:string
controller_path

Returns the canonical path to this controller.

Returns:path as token list or None if no path to this controller.
Return type:list
controller_uri

Returns the canonical URI for this controller.

Return type:string
redirect_to_referrer(fallback='/')
smisk_charsets(filter=None, *args, **params)

List available character sets.

Parameters:
  • filter (string) – Only list charsets matching this regular expression.
Returns:

Character sets keyed by name

smisk_methods(filter=None, *args, **params)

List available methods.

Parameters:
  • filter (string) – Only list methods which URI matches this regular expression.
Returns:

Methods keyed by URI

smisk_serializers(filter=None, *args, **params)

List available content serializers.

Parameters:
  • filter (string) – Only list serializers which name matches this regular expression.
Returns:

Serializers keyed by name

special_methods

Returns a dictionary of available special methods, keyed by exposed name.

See:enable_reflection
Return type:list
smisk.mvc.control.controllers()

Available controllers as a list, incuding the root.

Returns:List of controller instances in an undefined order.
Return type:list
smisk.mvc.control.leaf_is_visible(node, cls=None)

Return True if node defined on class cls is visible.

Parameters:
  • cls (class) –
  • node (object) –
Return type:

bool

smisk.mvc.control.leaf_reflection(leaf)
Structured info for leaf. Returns a dict or None if leaf is not exposed or not on the controller tree.
smisk.mvc.control.method_origin(method)

Return the class on which method was originally defined.

>>> from smisk.mvc.control import method_origin
>>> class Animal(object):
>>>   def name(self):
>>>     pass
>>> 
>>> class Fish(Animal):
>>>   def color(self):
>>>     pass
>>> 
>>> o = Fish()
>>> print method_origin(o.name)
<class '__main__.Animal'>
>>> print method_origin(o.color)
<class '__main__.Fish'>
Parameters:
  • method (callable) –
Returns:

Class on which method was originally defined or None if no parent could be deduced.

Return type:

object

smisk.mvc.control.node_name(node)

Name of an exposed node.

Parameters:
  • node (callable) –
Returns:

The name of node or None if node is not exposed. Note that this function returns the empty string (“”) if node is the root controller.

Return type:

string

smisk.mvc.control.path_to(node)

Returns the canonical path to node.

Parameters:
  • node (object) – Something on the controller tree. (method, class, instance, etc)
Return type:

list

smisk.mvc.control.root_controller()

Returns the root controller.

Return type:Controller
smisk.mvc.control.template_for(node)

Returns the template uri for node.

Parameters:
  • node (object) – Something on the controller tree. (method, class, instance, etc)
Return type:

list

smisk.mvc.control.uri_for(node)

Returns the canonical exposed URI of a node.

If node is a controller or a __call__, the uri always ends in a slash. Otherwise it never ends in a slash.

Parameters:
  • node (callable) –
Return type:

string