Provide custom colander schemas and associated widgets to render forms differently
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()
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
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’)
Return a unique tag id for this mapping
Bases: deform.widget.SelectWidget
Customize the chosenselectwidget to be able to provide a default value for unselection
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
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
Bases: deform.widget.SequenceWidget
See : https://github.com/Pylons/deform/pull/79
Build the prototype of a serialized sequence item
Overrided serialize method
Bases: deform.widget.Widget
A non editable input
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
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
Return a list of fields stored by row regarding the configured grid
Parameters: | field – The original field this widget is attached to |
---|
Bases: deform.widget.TextInputWidget
A hidden version
Bases: colander.Mapping
Inline schema type, necessary to avoid our mapping to be render as tabs (see deform_bootstrap.utils.tabify function )
Bases: colander.Schema
Schema providing inline rendering of form elements
Bases: deform.widget.MappingWidget
The custom widget we use to render our mapping
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)
Bases: deform_bootstrap_extensions.TableMappingWidget
Bases: deform.widget.MappingWidget
A custom widget rendering a mapping as a table
Parameters: | cols – number of columns we want |
---|
Return children grouped regarding the grid description
Bases: object
Void widget used to fill our grid
Return a div of class span<width>
Generate random string
size
size of the resulting string
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
Return a random string supposed to be used as tag id
Set custom date and datetime input widgets for a better user-experience