deform_bootstrap_extensions package¶
Module contents¶
Provide custom colander schemas and associated widgets to render forms differently
-
class
deform_extensions.
AccordionFormWidget
(**kw)¶ Bases:
deform_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 = AccordionFormWidget()
-
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_extensions:templates/accordion_form.pt'¶
-
template
= 'deform_extensions:templates/accordion_form.pt'¶
-
-
class
deform_extensions.
AccordionMappingWidget
(**kw)¶ Bases:
deform_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_extensions:templates/accordion_mapping.pt'¶
-
tag_id
¶ Return a unique tag id for this mapping
-
template
= 'deform_extensions:templates/accordion_mapping.pt'¶
-
-
class
deform_extensions.
CheckboxToggleWidget
(**kw)¶ Bases:
deform.widget.CheckboxWidget
Renders an
<input type="checkbox"/>
widget.Attributes/Arguments
- true_val
- The value which should be returned during deserialization if
the box is checked. Default:
true
. - false_val
- The value which should be returned during deserialization if
the box was left unchecked. Default:
false
. - template
- The template name used to render the widget. Default:
checkbox
. - readonly_template
- The template name used to render the widget in read-only mode.
Default:
readonly/checkbox
.
true_target
The item that should be displayed on true valuefalse_target
The item that should be displayed on false value-
false_target
= ''¶
-
false_val
= 'false'¶
-
readonly_template
= 'deform_extensions:templates/checkbox_toggle.pt'¶
-
requirements
= (('checkbox_toggle', None),)¶
-
serialize
(field, cstruct, **kw)¶
-
template
= 'deform_extensions:templates/checkbox_toggle.pt'¶
-
true_target
= ''¶
-
true_val
= 'true'¶
-
class
deform_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 inputAttributes/Arguments
- size
- The size, in columns, of the text input field. Defaults to
None
, meaning that thesize
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.pt'¶
-
requirements
= (('modernizr', None), ('jqueryui', None), ('custom_dates', None))¶
-
serialize
(field, cstruct, readonly=False)¶
-
size
= None¶
-
template
= 'deform_extensions:templates/dateinput.pt'¶
-
class
deform_extensions.
CustomDateTimeInputWidget
(*args, **kwargs)¶ Bases:
deform_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 thesize
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.pt'¶
-
requirements
= (('modernizr', None), ('jqueryui', None), ('datetimepicker', None), ('custom_dates', None))¶
-
serialize
(field, cstruct, readonly=False)¶
-
size
= None¶
-
style
= None¶
-
template
= 'deform_extensions:templates/datetimeinput.pt'¶
-
type_name
= 'datetime'¶
-
class
deform_extensions.
DisabledInput
(**kw)¶ Bases:
deform.widget.Widget
A non editable input
-
deserialize
(field, pstruct)¶
-
serialize
(field, cstruct=None, readonly=True)¶
-
template
= 'deform_extensions:templates/disabledinput.pt'¶
-
-
class
deform_extensions.
GridFormWidget
(**kw)¶ Bases:
deform_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_extensions:templates/grid_form.pt'¶
-
template
= 'deform_extensions:templates/grid_form.pt'¶
-
-
class
deform_extensions.
GridMappingWidget
(**kw)¶ Bases:
deform_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( 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
You can also pass StaticWidget instances in both cases This way static html datas can be inserted in forms
NAMED_GRID = ( (('title', 3), ), ( (StaticWidget("<div>Hello</div>"), 6), (None, 2), ('lon_coord', 2), ('lat_coord', 2) ), ) GRID = ( ((3, True), ), ( (6, StaticWidget("<div>Hello</div>")), (2, False), (2, True), (2, True) ), )
-
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_extensions.
HiddenLocalizationWidget
(**kw)¶ Bases:
deform.widget.TextInputWidget
A hidden version
-
readonly_template
= 'deform_extensions:templates/hidden_localization.pt'¶
-
template
= 'deform_extensions:templates/hidden_localization.pt'¶
-
-
class
deform_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_extensions.
InlineMappingSchema
(*arg, **kw)¶ Bases:
colander.Schema
Schema providing inline rendering of form elements
-
widget
= <deform_extensions.InlineMappingWidget object>¶
-
-
class
deform_extensions.
InlineMappingWidget
(**kw)¶ Bases:
deform.widget.MappingWidget
The custom widget we use to render our mapping
-
item_template
= 'deform_extensions:templates/inline_mapping_item.pt'¶
-
readonly_item_template
= 'deform_extensions:templates/inline_mapping_item.pt'¶
-
readonly_template
= 'deform_extensions:templates/inline_mapping.pt'¶
-
template
= 'deform_extensions:templates/inline_mapping.pt'¶
-
-
class
deform_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_extensions:templates/localization.pt'¶
-
template
= 'deform_extensions:templates/localization.pt'¶
-
-
class
deform_extensions.
RadioChoiceToggleWidget
(**kw)¶ Bases:
deform.widget.RadioChoiceWidget
Renders a sequence of
<input type="radio"/>
buttons based on a predefined set of values.Attributes/Arguments
- values
- A sequence of three-tuples (the first value must be of type
string, unicode or integer, the second value must be string or
unicode) indicating allowable, displayed values, e.g.
( ('true', 'True', 'otherformelement1'), ('false', 'False', 'otherformelement2') )
. The first element is the value that will be submitted by the form The second is the display value. The third element in the tuple is the colande name of the form item that will be shown when the radio is checked if the void string ‘’ is provided, only all other elements will be hidden. - template
- The template name used to render the widget. Default:
radio_choice_toggle
. - null_value
- The value used to replace the
colander.null
value when it is passed to theserialize
ordeserialize
method. Default: the empty string. - inline
- If true, choices will be rendered on a single line. Otherwise choices will be rendered one per line. Default: false.
-
readonly_template
= 'deform_extensions:templates/radio_choice_toggle.pt'¶
-
requirements
= (('radio_choice_toggle', None),)¶
-
serialize
(field, cstruct, **kw)¶
-
template
= 'deform_extensions:templates/radio_choice_toggle.pt'¶
-
values
= ()¶
-
class
deform_extensions.
StaticWidget
(html_str, width=1)¶ Bases:
deform.widget.Widget
Static widget used to insert static html in grids
-
render_template
(template)¶ Return a div of class col-md-<width>
-
-
class
deform_extensions.
TableFormWidget
(**kw)¶ Bases:
deform_extensions.TableMappingWidget
-
readonly_template
= 'deform_extensions:templates/grid_form.pt'¶
-
template
= 'deform_extensions:templates/grid_form.pt'¶
-
-
class
deform_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_extensions:templates/grid_mapping_item.pt'¶
-
num_cols
= 12¶
-
readonly_item_template
= 'deform_extensions:templates/grid_mapping_item.pt'¶
-
readonly_template
= 'deform_extensions:templates/grid_mapping.pt'¶
-
template
= 'deform_extensions:templates/grid_mapping.pt'¶
-
-
class
deform_extensions.
VoidWidget
(width=1)¶ Bases:
deform.widget.Widget
Void widget used to fill our grid
-
render_template
(template)¶ Return a div of class col-md-<width>
-
-
deform_extensions.
add_resources_to_registry
()¶ Add resources to the deform registry
-
deform_extensions.
gen_random_string
(size=15)¶ Generate random string
size
size of the resulting string
-
deform_extensions.
grouper
(iterable, items, fillvalue=None)¶ Collect data into fixed-length chunks or blocks
e.g:
grouper(‘ABCDEFG’, 3, ‘x’) –> ABC DEF GxxGot it from https://docs.python.org/2/library/itertools.html#recipes
-
deform_extensions.
includeme
(config)¶
-
deform_extensions.
random_tag_id
(size=15)¶ Return a random string supposed to be used as tag id
-
deform_extensions.
set_default_widgets
()¶ Set custom date and datetime input widgets for a better user-experience