deform_bootstrap_extensions package

Module contents

Provide custom colander schemas and associated widgets to render forms differently

class deform_bootstrap_extensions.AccordionFormWidget(**kw)

Bases: deform_bootstrap_extensions.GridFormWidget

AccordionFormWidget is supposed to be combined with colanderalchemy

The way it works:

In your SqlAlchemy models, enter the __colanderalchemy__ key under the
info attribute.  All columns of a single model can have a section key.
If so, an accordion will contain all columns under the same section key

If you want each accordion to be rendered as a grid, you can optionnaly
pass a grids or named_grids argument that should be a dict :
    {<section_name>: <associated_grid_object>}

The associated_grid_object should be in the same format as for the
GridMappingWidget
class Model(DBBASE):
    coordonnees_emergency_name = Column(
        String(50),
        info={
            'colanderalchemy':{
                'title': u"Contact urgent : Nom",
                'section': u'Coordonnées',
            }
        }
    )
    coordonnees_emergency_phone = Column(
        String(14),
        info={
            'colanderalchemy':{
                'title': u'Contact urgent : Téléphone',
                'section': u'Coordonnées',
            }
        }
    )

    # STATUT
    statut_social_status_id = Column(
        ForeignKey('social_status_option.id'),
        info={
            'colanderalchemy':
            {
                'title': u"Statut social à l'entrée",
                'section': u'Statut',
                'widget': get_deferred_select(SocialStatusOption),
            }
        }
    )

schema = SQLAlchemySchemaNode(Model)
form = Form(schema)
form.widget = AccordionMappingWidget()
accordions(form)

return the chlidren of the given form in a dict allowing to render them in accordions with a grid layout :param form: the form object

default_item_template = 'mapping_item'
num_cols = 12
readonly_template = 'deform_bootstrap_extensions:templates/accordion_form'
template = 'deform_bootstrap_extensions:templates/accordion_form'
class deform_bootstrap_extensions.AccordionMappingWidget(**kw)

Bases: deform_bootstrap_extensions.GridMappingWidget

Render a mapping as an accordion and places inner fields in a grid

class Mapping(colander.MappingSchema):
    field = colander.SchemaNode(...)

class Schema(colander.Schema):
    mymapping = Mapping(title=u'The accordion header',
        widget = AccordionMappingWidget(grid=GRID)
        )

you’ll need to set the bootstrap_form_style to ‘form-grid’

Form(schema=Schema(), bootstrap_form_style=’form-grid’)

readonly_template = 'deform_bootstrap_extensions:templates/accordion_mapping'
tag_id

Return a unique tag id for this mapping

template = 'deform_bootstrap_extensions:templates/accordion_mapping'
class deform_bootstrap_extensions.CustomChosenOptGroupWidget(**kw)

Bases: deform.widget.SelectWidget

Customize the chosenselectwidget to be able to provide a default value for unselection

template = 'deform_bootstrap_extensions:templates/chosen_optgroup.pt'
class deform_bootstrap_extensions.CustomDateInputWidget(*args, **kwargs)

Bases: deform.widget.Widget

Renders a JQuery UI date picker widget (http://jqueryui.com/demos/datepicker/). Most useful when the schema node is a colander.Date object. alt Tag is used to allow full customization of the displayed input

Attributes/Arguments

size
The size, in columns, of the text input field. Defaults to None, meaning that the size is not included in the widget output (uses browser default size).
template
The template name used to render the widget. Default: dateinput.
options
Options for configuring the widget (eg: date format)
readonly_template
The template name used to render the widget in read-only mode. Default: readonly/textinput.
default_options = (('dateFormat', 'dd/mm/yy'),)
deserialize(field, pstruct)
readonly_template = 'readonly/textinput'
requirements = (('modernizr', None), ('jqueryui', None))
serialize(field, cstruct, readonly=False)
size = None
template = 'deform_bootstrap_extensions:templates/dateinput'
class deform_bootstrap_extensions.CustomDateTimeInputWidget(*args, **kwargs)

Bases: deform_bootstrap_extensions.CustomDateInputWidget

Renders a datetime picker widget.

The default rendering is as a native HTML5 datetime input widget, falling back to jQuery UI date picker with a JQuery Timepicker add-on (http://trentrichardson.com/examples/timepicker/).

Used for colander.DateTime schema nodes.

Attributes/Arguments

options
A dictionary of options that’s passed to the datetimepicker.
size
The size, in columns, of the text input field. Defaults to None, meaning that the size is not included in the widget output (uses browser default size).
style
A string that will be placed literally in a style attribute on the text input tag. For example, ‘width:150px;’. Default: None, meaning no style attribute will be added to the input tag.
template
The template name used to render the widget. Default: dateinput.
readonly_template
The template name used to render the widget in read-only mode. Default: readonly/textinput.
default_options = (('dateFormat', 'dd/mm/yy'), ('timeFormat', 'HH:mm'), ('separator', ' '))
deserialize(field, pstruct)
readonly_template = 'readonly/textinput'
requirements = (('modernizr', None), ('jqueryui', None), ('datetimepicker', None))
serialize(field, cstruct, readonly=False)
size = None
style = None
template = 'deform_bootstrap_extensions:templates/datetimeinput'
type_name = 'datetime'
class deform_bootstrap_extensions.CustomSequenceWidget(**kw)

Bases: deform.widget.SequenceWidget

See : https://github.com/Pylons/deform/pull/79

prototype(field)

Build the prototype of a serialized sequence item

serialize(field, cstruct, readonly=False)

Overrided serialize method

class deform_bootstrap_extensions.DisabledInput(**kw)

Bases: deform.widget.Widget

A non editable input

deserialize(field, pstruct)
serialize(field, cstruct=None, readonly=True)
template = 'deform_bootstrap_extensions:templates/disabledinput.pt'
class deform_bootstrap_extensions.GridFormWidget(**kw)

Bases: deform_bootstrap_extensions.GridMappingWidget

Render a form as a grid

class CompanyMainInformations(colander.MappingSchema):
    title = colander.SchemaNode(
        colander.String(),
        title=u'Nom entreprise',
    )
    address = colander.SchemaNode(
        colander.String(),
        title=u'Adresse',
        width="5",
    )

LAYOUT = (((2, True), (2, False), (2, True),),)

schema = CompanyMainInformations()
form = Form(schema)
form.widget = GridFormWidget(grid=LAYOUT)

Warning

Here you need to set the widget after you initialize the form object

readonly_template = 'deform_bootstrap_extensions:templates/grid_form'
template = 'deform_bootstrap_extensions:templates/grid_form'
class deform_bootstrap_extensions.GridMappingWidget(**kw)

Bases: deform_bootstrap_extensions.TableMappingWidget

A custom mapping widget rendering it as a grid

Parameters:grid (tuple) – A matrix describing the grid we want. The matrix should

be composed of two dimensionnal vectors (width, filled) where filled is a boolean.

Parameters:named_grid (tuple) – A matrix describing the grid we want. The matrix

should be composed of two dimensionnal vectors (name, width).

class CompanyMainInformations(colander.MappingSchema):
    title = colander.SchemaNode(
        colander.String(),
        title=u'Nom entreprise',
    )
    address = colander.SchemaNode(
        colander.String(),
        title=u'Adresse',
        width="5",
    )
    lon_coord = colander.SchemaNode(
        colander.Float(),
        title=u"Longitude",
    )
    lat_coord = colander.SchemaNode(
        colander.Float(),
        title=u"Latitude",
    )

    GRID = (
        ((3, True), ),
        ((6, True), (2, False), (2, True), (2, True)),
        )

    class CompanySchema(colander.Schema):
        tab = CompanyMainInformations(i
            widget=GridMappingWidget(grid=GRID)
        )

    NAMED_GRID = (
        (('title', 3), ),
        (('address', 6), (None, 2), ('lon_coord', 2), ('lat_coord', 2)),
        )

    class CompanySchema(colander.Schema):
        tab = CompanyMainInformations(
            widget=GridMappingWidget(named_grid=NAMED_GRID)
            )

Here, in both cases, we’ve got a two lines grid with 1 element on the first line and 3 on the second one. The second element of the second line will be a void cell of 2 units width

childgroup(field)

Return a list of fields stored by row regarding the configured grid

Parameters:field – The original field this widget is attached to
num_cols = 12
class deform_bootstrap_extensions.HiddenLocalizationWidget(**kw)

Bases: deform.widget.TextInputWidget

A hidden version

readonly_template = 'deform_bootstrap_extensions:templates/hidden_localization'
template = 'deform_bootstrap_extensions:templates/hidden_localization'
class deform_bootstrap_extensions.Inline(unknown='ignore')

Bases: colander.Mapping

Inline schema type, necessary to avoid our mapping to be render as tabs (see deform_bootstrap.utils.tabify function )

class deform_bootstrap_extensions.InlineMappingSchema(*arg, **kw)

Bases: colander.Schema

Schema providing inline rendering of form elements

schema_type

alias of Inline

widget = <deform_bootstrap_extensions.InlineMappingWidget object at 0x1fe1a50>
class deform_bootstrap_extensions.InlineMappingWidget(**kw)

Bases: deform.widget.MappingWidget

The custom widget we use to render our mapping

item_template = 'deform_bootstrap_extensions:templates/inline_mapping_item'
readonly_item_template = 'deform_bootstrap_extensions:templates/inline_mapping_item'
readonly_template = 'deform_bootstrap_extensions:templates/inline_mapping'
template = 'deform_bootstrap_extensions:templates/inline_mapping'
class deform_bootstrap_extensions.LocalizationWidget(**kw)

Bases: deform.widget.TextInputWidget

A widget with a link for configuring localization picking it from a map A link will be provided, by clicking on it, we do some fancy html manipulation to replace the fields and have a pretty layout

e.g:

>>> widget = LocalizationWidget(
...     lat_field_name='lat_coord',
...     lon_field_name='lon_coord'
... )
>>> class Schema():
...     lat_coord = colander.Schema(colander.Float())
...     lon_coord = colander.Schema(colander.Float(), widget=widget)
readonly_template = 'deform_bootstrap_extensions:templates/localization'
template = 'deform_bootstrap_extensions:templates/localization'
class deform_bootstrap_extensions.TableFormWidget(**kw)

Bases: deform_bootstrap_extensions.TableMappingWidget

readonly_template = 'deform_bootstrap_extensions:templates/grid_form'
template = 'deform_bootstrap_extensions:templates/grid_form'
class deform_bootstrap_extensions.TableMappingWidget(**kw)

Bases: deform.widget.MappingWidget

A custom widget rendering a mapping as a table

Parameters:cols – number of columns we want
childgroup(field)

Return children grouped regarding the grid description

default_cols = 3
item_template = 'deform_bootstrap_extensions:templates/grid_mapping_item'
num_cols = 12
readonly_item_template = 'deform_bootstrap_extensions:templates/grid_mapping_item'
readonly_template = 'deform_bootstrap_extensions:templates/grid_mapping'
template = 'deform_bootstrap_extensions:templates/grid_mapping'
class deform_bootstrap_extensions.VoidWidget(width=1)

Bases: object

Void widget used to fill our grid

render_template(template)

Return a div of class span<width>

deform_bootstrap_extensions.gen_random_string(size=15)

Generate random string

size

size of the resulting string
deform_bootstrap_extensions.grouper(iterable, items, fillvalue=None)

Collect data into fixed-length chunks or blocks

e.g:

grouper(‘ABCDEFG’, 3, ‘x’) –> ABC DEF Gxx

Got it from https://docs.python.org/2/library/itertools.html#recipes

deform_bootstrap_extensions.includeme(config)
deform_bootstrap_extensions.random_tag_id(size=15)

Return a random string supposed to be used as tag id

deform_bootstrap_extensions.set_default_widgets()

Set custom date and datetime input widgets for a better user-experience

Table Of Contents

Previous topic

Welcome to deform_bootstrap_extensions’s documentation!

This Page