A complement to deform_bootstrap, which offers Twitter Bootstrap compatible widgets, templates and styles for the deform form library.
Extra features for deform_bootstrap
Our alterations to the templates are in the “templates” subdirectory.
Here are the changes we’ve made:
All this has been tested against deform_bootstrap 0.2.8.
Take a look on static/deform_bootstrap_extra.css – it has a few improvements on bootstrap’s CSS so it works better with deform. The file has comments.
If you use the Pyramid web framework, here is a great little abstract base class for views that use deform: BaseDeformView. Check it out!
Forms containing all inputs with the same size are extremely boring to look at. When the widths of the inputs vary, not only the user gets a better idea of how much to type in them, but the screen looks much more interesting and easier to scan visually.
The lengthen() function calculates input width based on the maxlength (which can optionally be inferred from a SQLAlchemy model property). Example usage:
from deform_bootstrap_extra.helpers import lengthen import colander as c class ContactSchema(CSRFSchema): name = c.SchemaNode(c.Str(), title=_("Name"), missing=None, **lengthen(Contact.name)) # this is a model property
This Colander validator only accepts a time in the future. Example:
from deform_bootstrap_extra.schema import from_now_on import colander as c class PromotionSchema(CSRFSchema): scheduled = c.SchemaNode(c.DateTime(default_tzinfo=None), missing=c.null, title=_("Schedule"), validator=from_now_on) (...) sch = PromotionSchema().bind(request=self.request, now=datetime.utcnow())
A schema type that can represent true, false and null. Example:
from deform_bootstrap_extra.schema import Trilean import colander as c import deform.widget as w class ContactSchema(CSRFSchema): (...) male = c.SchemaNode(Trilean(), title=_("Sex"), missing=None, widget=w.SelectWidget(values=[ (c.null, _("- Choose -")), ('false', _("Female")), ('true', _("Male")), ]))
Our preferred way of enabling the whole stack is this:
# DO NOT include('deform_bootstrap') config.include('deform_bootstrap_extra')
This sets deform up for i18n (configuring a translator function and pointing colander and deform locale directories) and gives its template loader the correct directory hierarchy, so it will search for templates first in deform_bootstrap_extra, then in deform_bootstrap, finally in deform.
You can help development at https://github.com/nandoflorestan/deform_bootstrap_extra