Fields

class keg_elements.forms.MultiCheckboxField(*args, **kwargs)

A multiple-select, except displays a list of checkboxes.

class keg_elements.forms.RelationshipField(*args, **kwargs)

SelectField for relationships.

Args:

orm_cls (class): Model class of the relationship attribute. Used to query records for populating select options.

label_attr (str): Name of attribute on relationship class to use for select option labels.

fk_attr (str): Optional name of foreign key column of ORM class. If set to None, coerce values to instances of ORM class. Otherwise, coerce values to the attribute of ORM class the foreign key belongs to. Default is ‘id’.

query_filter (callable): Optional SA query filter criterion for querying select options. Can be a function that returns a filter criterion. Function is called with the RelationshipField instance it belongs to.

coerce (callable): Optional function used to coerce form values. By default, if fk_attr is set to None, values are coerced to instances of ORM class. Otherwise, the default select coersion is applied. Setting this overrides default behavior.

kwargs: Passed to SelectField.__init__.

Example::
class Bar(Model):

name = Column(Unicode(255)) foos = relationship(‘Foo’, foreign_keys=’foos.id’)

class Foo(Model):

name = Column(Unicode(255)) bar_id = Column(sa.ForeignKey(Bar.id)) bar = relationship(Bar, foreign_keys=bar_id)

class FooForm(ModelForm):

bar_id = RelationshipField(‘Bar Label’, Bar, ‘name’)

class keg_elements.forms.RelationshipMultipleField(*args, **kwargs)

SelectMultipleField for relationships. Args:

orm_cls (class): Model class of the relationship attribute. Used to query records for populating select options.

label_attr (str): Name of attribute on relationship class to use for select option labels.

query_filter (callable): Optional SA query filter criterion for querying select options. Can be a function that returns a filter criterion. Function is called with the RelationshipField instance it belongs to.

coerce (callable): Optional function used to coerce form values. By default, values are coerced to instances of ORM class. Setting this overrides default behavior.

kwargs: Passed to SelectMultipleField.__init__.

Example::
class Bar(Model):

name = Column(Unicode(255)) foos = relationship(‘Foo’, foreign_keys=’foos.id’)

class Foo(Model):

name = Column(Unicode(255)) bar_id = Column(sa.ForeignKey(Bar.id)) bar = relationship(Bar, foreign_keys=bar_id)

class BarForm(ModelForm):

foos = RelationshipMultipleField(‘Foos’, Foo, ‘name’)

iter_choices()

We should update how choices are iter to make sure that value from internal list or tuple should be selected.

pre_validate(form)

Don’t forget to validate also values from embedded lists.

process_data(value)

Process the Python data applied to this field and store the result.

This will be called during form construction by the form’s kwargs or obj argument.

Parameters:

value – The python object containing the value to process.

process_formdata(valuelist)

Process data received over the wire from a form.

This will be called during form construction with data supplied through the formdata argument.

Parameters:

valuelist – A list of strings to process.

class keg_elements.forms.RequiredBoolRadioField(*args, **kwargs)

A radio group field with true/false labels and a required validator.

Parameters:
  • true_label – Optional, defaults to Yes.

  • false_label – Optional, defaults to No.

  • validators – Optional. Any provided validators will be added to InputRequired.

class keg_elements.forms.SelectField(*args, **kwargs)

Provides helpful features above wtforms_components SelectField which it is based on:

  1. Adds a blank choice by default at the front of the choices. This results in your user being forced to select something if the field is required, which avoids initial defaulting of the first value in the field getting submitted.

  2. The coerce function used for the choices will automatically convert to int if possible, falling back to unicode if the value is not an integer.

class keg_elements.forms.SelectMultipleField(*args, **kwargs)

Provides helpful features above wtforms_components SelectMultipleField which it is based on:

The coerce function used for the choices will automatically convert to int if possible, falling back to unicode if the value is not an integer.

class keg_elements.forms.state_field.StateField(*args, **kwargs)

A U.S. States select field. Defaults to using short values (2 letter codes) for the stored value, and long labels for display.

Parameters:
  • short_values – use 2 letter state codes for the stored value. Defaults to True.

  • short_labels – use 2 letter state codes for the dropdown display. Defaults to False.