Module component
This module implements the component model of the framework.
This model is inspired by the Seaside one. With the possibility to embed, replace and call a component. It's described in ComponentModel
- Imports:
- nagare, peak.rules, stackless, sys, types
- Classes:
- AnswerWithoutCall(BaseException):
- Component(object): This class transforms any Python object into a component
- Task: A Task encapsulated a simple method. A task is typically used to manage other components by calling them.
- Methods:
- call_wrapper(action, *args, **kw): A wrapper that create a tasklet.
- init_for(self, url, comp, http_method, request): Initialisation from an url
- render(self, renderer, comp, model): Rendering of a Component
- render(self, renderer, comp, *args):
- render(f, renderer, comp, *args):
- Attributes:
- _marker = object()
Class component.Component
- Bases:
- object
This class transforms any Python object into a component
A component has views, can the embedded, replaced, called and can answsered a value.
- Methods:
- __call__(self): Return the inner object
- __init__(self, o=None, model=0, url=None): Initialisation
- __repr__(self):
- answer(self, r=None): Answer to a call
- becomes(self, o=_marker, model=0, url=None): Replace a component by an object or an other component
- call(self, o=_marker, model=0, url=None): Call an other object or component
- init(self, url, http_method, request): Initialisation from an url
- on_answer(self, f): Register a function to listen to my answer
- render(self, renderer, model=0): Rendering method of a component
Method component.Component.__init__
- Arguments:
- self, o=None, model=0, url=None
Initialisation
- In:
- o -- the python object (or component) to transform into a component
- model -- the name of the view to use (None for the default view)
- url -- the url fragment to add before all the links generated by views of this component
Method component.Component.answer
- Arguments:
- self, r=None
Answer to a call
- In:
- the value to answer
Method component.Component.becomes
- Arguments:
- self, o=_marker, model=0, url=None
Replace a component by an object or an other component
- In:
- o -- object to be replaced by
- model -- the name of the view to use (None for the default view)
- url -- the url fragment to add before all the links generated by views of this component
- Return:
- self
Method component.Component.call
- Arguments:
- self, o=_marker, model=0, url=None
Call an other object or component
The current component is replaced and will be back when the object will do an answer()
- In:
- o -- the object to call
- model -- the name of the view to use (None for the default view)
- url -- the url fragment to add before all the links generated by views of this component
- Return:
- the answer of the called object
Method component.Component.init
- Arguments:
- self, url, http_method, request
Initialisation from an url
Forward the call to the generic method of the presentation service
Method component.Component.on_answer
- Arguments:
- self, f
Register a function to listen to my answer
- In:
- f -- function to call with my answer
Method component.Component.render
- Arguments:
- self, renderer, model=0
Rendering method of a component
Forward the call to the generic method of the presentation service
Class component.Task
- Bases:
- None
A Task encapsulated a simple method. A task is typically used to manage other components by calling them.
Warning
A Task is an object, not a component: you must wrap it into a Component() to use it.
- Methods:
- _go(self, comp):
- go(self, comp):
Method component.call_wrapper
- Arguments:
- action, *args, **kw
A wrapper that create a tasklet.
It's necessary to wrapper a callable that do directly or indirectly a comp.call(o) into such a call_wrapper.
Note
The actions your registred on the <a> tags or on the submit buttons are already wrapped for you.
- In:
- action -- a callable. It will be called, wrapped into a new tasklet, with the args and kw parameters.
- args -- positional parameters of the callable
- kw -- keywords parameters of the callable
- Return:
- Never
Method component.init_for
- Arguments:
- self, url, comp, http_method, request
Initialisation from an url
- In:
- url -- rest of the url to process
- comp -- the component
- http_method -- the HTTP method
- request -- the complete Request object
- Return:
- presentation.NOT_FOUND if the url is invalid, else None
- Decorators:
- @presentation.init_for(Component)
Method component.render
- Arguments:
- self, renderer, comp, model
Rendering of a Component
- In:
- renderer -- the renderer
- comp -- the component
- model -- the name of the view
- Return:
- the view of the component object
- Decorators:
- @when(presentation.render, (Component, object, object, int)), @when(presentation.render, (Component, object, object, str)), @when(presentation.render, (Component, object, object, types.NoneType))