sprox.widgets

Classes

class sprox.widgets.ContainerWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.SproxCalendarDatePicker(*args, **kw)

Bases: tw.forms.calendars.CalendarDatePicker

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

Takes care of post-initialization of InputWidgets.

prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.SproxCalendarDateTimePicker(*args, **kw)

Bases: tw.forms.calendars.CalendarDateTimePicker

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

Takes care of post-initialization of InputWidgets.

prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.SproxCheckBox(*args, **kw)

Bases: tw.forms.fields.InputField

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

Takes care of post-initialization of InputWidgets.

prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

validator

alias of StringBool

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.SproxDataGrid(*args, **kw)

Bases: tw.forms.datagrid.DataGrid

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_column(name)

Return Column with specified name.

Raises KeyError if no such column exists.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

static get_field_getter(columns)

Return a function to access the fields of table by row, col.

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.SproxTableForm(*args, **kw)

Bases: tw.forms.fields.TableForm

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifields
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
ihidden_fields
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)
prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.SproxTimePicker(*args, **kw)

Bases: tw.forms.calendars.CalendarDateTimePicker

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

Returns a CalendarLangFileLink containing a list of name patterns to try in turn to find the correct calendar locale file to use.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

Takes care of post-initialization of InputWidgets.

prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.EntityDefWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.EntityLabelWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.ModelLabelWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.PropertyMixin(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.PropertyMultipleSelectField(*args, **kw)

Bases: tw.forms.fields.MultipleSelectField, sprox.widgets.widgets.PropertyMixin

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)
children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)
prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

validator

alias of DefaultValidator

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.PropertySingleSelectField(*args, **kw)

Bases: tw.forms.fields.SingleSelectField, sprox.widgets.widgets.PropertyMixin

adapt_value(value)
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

adjust_value(value, validator=None)

Adjusts the python value sent to InputWidget.display() with the validator so it can be rendered in the template.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

error_at_request

Validation error for current request.

generate_schema()

If the widget has children this method generates a Schema to validate including the validators from all children once these are all known.

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_required
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
name
name_path_elem
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

Takes care of post-initialization of InputWidgets.

prepare_dict(value, kw, adapt=True)

Prepares the dict sent to the template with functions to access the children’s errors if any.

propagate_errors(parent_kw, parent_error)
register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

safe_validate(value)

Tries to coerce the value to python using the validator. If validation fails the original value will be returned unmodified.

update_attrs(d, *args)

Fetches values from the dict and inserts the in the attrs dict.

This is useful when you want to avoid boiler-place at the template:

Instead of:

Do:

And inside update_params:

self.update_attrs(d, 'bar', 'zoo')

(‘bar’ and ‘zoo’ need to be listed at params)

update_params(d)
validate(value, state=None, use_request_local=True)

Validate value using validator if widget has one. If validation fails a formencode.Invalid exception will be raised.

If use_request_local is True and validation fails the exception and value will be placed at request local storage so if the widget is redisplayed in the same request error and value don’t have to be passed explicitly to display.

validator

alias of DefaultValidator

value_at_request

Value being validated in current request.

walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.RecordFieldWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.RecordViewWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.TableDefWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''
class sprox.widgets.TableLabelWidget(*args, **kw)

Bases: tw.core.base.Widget

adapt_value(value)
Adapt object value for rendering in this widget. Should return one of:
  • A list of objects for repeated widgets.
  • A dict for widgets with children, keyed by the children’s ids.
  • Any other object the widget understands.
add_call(call, location='bodybottom')

Adds a tw.api.js_function() call that will be made when the widget is rendered.

children_deep
clone(*args, **kw)
display(value=None, **kw)

Renders a widget and adapts the output. This method must be used to display child widgets inside their parent’s template so output is adapted.

Unlike tw.api.Widget.render(), tw.api.Widget.display() returns adapted output compatible with the template the widget is being rendered on. For example, this is needed so Genshi doesn’t autoescape string output from mako and to serialize Genshi output on the other way around.

displays_on

Where the widget is being displayed on

get_default()

Returns the default value for the widget. If the default is a funtion that it can be called without arguments it will be called on each render to retrieve a value

id

The calculated id of the widget. This string will provide a unique id for each widget in the tree in a format which allows to re-recreate the nested structure. Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.id
'A_B_C'
id_path_elem
ifilter_children(filter)

Returns an iterator for all children applying a filter to them.

>>> class Widgets(WidgetsList):
...     aa = Widget()
...     ab = Widget()
...     ba = Widget()
...     bb = Widget()
...
>>> w = Widget(children=Widgets)
>>> [c.id for c in w.ifilter_children(lambda w: w.id.startswith('a'))]
['aa', 'ab']
is_root

True if the widget doesn’t have a parent

key

A string that can be used as a key to index the dictionary of parameters sent to the root widget so it reaches this widget when displaying.

Example:

>>> A = Widget("A", children=[
...     Widget("B", children=[
...         Widget("C")
...         ])
...     ])
...
>>> C = A.c.B.c.C
>>> C.key
'.B.C'
path

Iterates a walk from this widget to the root of the tree

post_init(*args, **kw)

This method is called for all tw.api.Widget base classes to perform final setup after the widget is initialized but before it is locked.

prepare_dict(value, d, adapt=True)

Prepares the all kw arguments sent to display or render before passing the kw argument’s dict to update_params.

register_resources()

Register the resources required by this Widget with tw.framework for inclusion in the page.

This method is called whenever a Widget is rendered

render(value=None, **kw)

Renders a widget as an unicode string.

retrieve_css(*args, **kw)
retrieve_javascript(*args, **kw)
retrieve_resources(*args, **kw)
root

The root of this widget tree

update_params(d)

Updates the dict sent to the template for the current request.

It is called when displaying or rendering a widget with all keyword arguments passed stuffed inside dict.

Widget subclasses can call super cooperatively to avoid boiler-plate code as Widget.update_params takes care of pre-populating this dict with all attributes from self listed at params (copying them if mutable) and preparing arguments for child widgets.

Any parameter sent to display or render will override those fetched from the instance or the class.

Any function listed at params which can be called without arguments will be automatically called to fetch fresh results on every request. Parameters not found either on the class, the instance or the keyword args to display or render will be set to None.

>>> class MyWidget(Widget):
...     params = ["foo", "bar", "null"]
...     foo = "foo"
...
>>> w = MyWidget('test', bar=lambda: "bar")
>>> d = {}
>>> w.update_params(d)
>>> d['bar']
'bar'
>>> d['foo']
'foo'
>>> d['null'] is None
True
>>> d = {'foo':'overriden'}
>>> w.update_params(d)
>>> d['foo']
'overriden'
walk(filter=None, recur_if_filtered=True)

Does a pre-order walk on widget tree rooted at self optionally applying a filter on them.

Example:

>>> W = Widget
>>> w = W('a', children=[W('b', children=[W('c')]), W('d')])
>>> ''.join(i._id for i in w.walk())
'abcd'
>>> ''.join(i._id for i in w.walk(lambda x: not x.is_root))
'bcd'
>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c'))
'c'

Recursion can be prevented on children that not match filter.

>>> ''.join(i._id for i in w.walk(lambda x: x._id == 'c', False))
''

Discuss

blog comments powered by Disqus

Table Of Contents

Previous topic

sprox.iprovider

Next topic

sprox.util

This Page