gavo.formal.widget module

Widgets are small components that render form fields for inputing data in a certain format.

Caution: the args argument in the widgets’ render methods is a disaster in python3 – it maps from bytes when there are errors (it’s a t.w Request.args), from string otherwise (it’s a formal-internal thing). And don’t get me started on its values.

class gavo.formal.widget.Checkbox(original)[source]

Bases: object

A checkbox input field.

<input type=”checkbox” … />

processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.CheckboxMultiChoice(original, options=None, lots=False, emphasized=frozenset({}))[source]

Bases: Element

Multiple choice list, rendered as a list of checkbox fields.

lots enters blanks between the items (which allows a bit more flexibility in styling the stuff).

emphasized can be a set of item titles that should additionally get an emphasized css class.

Default is a whitespace-spearated enumeration for now.

options = None
processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]

Implement L{IRenderable} to allow one L{Element} to be embedded in another’s template or rendering output.

(This will simply load the template from the C{loader}; when used in a template, the flattening engine will keep track of this object separately as the object to lookup renderers on and call L{Element.renderer} to look them up. The resulting object from this method is not directly associated with this L{Element}.)

renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.CheckedPassword(original)[source]

Bases: object

Two password entry fields that must contain the same value to validate.

processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.DatePartsInput(original, dayFirst=None, twoCharCutoffYear=None)[source]

Bases: object

A date entry widget that uses three <input> elements for the day, month and year parts.

The default entry format is the US (month, day, year) but can be switched to the more common (day, month, year) by setting the dayFirst attribute to True.

By default the widget is designed to only accept unambiguous years, i.e. the user must enter 4 character dates.

Many people find it convenient or even necessary to allow a 2 character year. This can be allowed by setting the twoCharCutoffYear attribute to an integer value between 0 and 99. Anything greater than or equal to the cutoff year will be considered part of the 20th century (1900 + year); anything less the cutoff year is a 21st century (2000 + year) date.

A typical twoCharCutoffYear value is 70 (i.e. 1970). However, that value is somewhat arbitrary. It’s the year that time began according to the PC, but it doesn’t mean much to your non-techie user.

dayFirst:

Make the day the first input field, i.e. day, month, year

twoCharCutoffYear:

Allow 2 char years and set the year where the century flips between 20th and 21st century.

default can be whitespace-separated parts.

dayFirst = False
processInput(request, key, args, default=None)[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
twoCharCutoffYear = None
class gavo.formal.widget.DatePartsSelect(original, dayFirst=None, yearFrom=None, yearTo=None, months=None, noneOption=<object object>)[source]

Bases: object

A date entry widget that uses three <input> elements for the day, month and year parts.

The default entry format is the US (month, day, year) but can be switched to the more common (day, month, year) by setting the dayFirst attribute to True.

The start and end year can be passed through but default to 1970 and 2070.

The months default to non-zero prefixed numerics but can be passed as a list of label, value pairs

default can be whitespace-separated parts here.

dayFirst = False
days = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12), (13, 13), (14, 14), (15, 15), (16, 16), (17, 17), (18, 18), (19, 19), (20, 20), (21, 21), (22, 22), (23, 23), (24, 24), (25, 25), (26, 26), (27, 27), (28, 28), (29, 29), (30, 30), (31, 31)]
months = [(1, 1), (2, 2), (3, 3), (4, 4), (5, 5), (6, 6), (7, 7), (8, 8), (9, 9), (10, 10), (11, 11), (12, 12)]
noneOption = ('', '')
processInput(request, key, args, default=None)[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
yearFrom = 1970
yearTo = 2070
class gavo.formal.widget.FileUpload(original)[source]

Bases: object

NOTE: You have use something like twistedpatch.MPRequest as your site’s requestFactory to make this work.

processInput(request, key, args, default=None)[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.Hidden(original)[source]

Bases: object

A hidden form field.

inputType = 'hidden'
processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.MMYYDatePartsInput(original, cutoffYear=None)[source]

Bases: object

Two input fields for entering the month and year.

default can be a year and month separated by whitespace.

cutoffYear = 70
processInput(request, key, args, default=None)[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.Password(original)[source]

Bases: TextInput

A text input field that hides the text.

<input type=”password” … />

inputType = 'password'
showValueOnFailure = False
class gavo.formal.widget.RadioChoice(original, options=None, noneOption=<object object>)[source]

Bases: ChoiceBase

A list of options in the form of radio buttons.

<div class=”radiobutton”><input type=”radio” … value=”…”/><label>…</label></div>

render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.SelectChoice(original, options=None, noneOption=<object object>)[source]

Bases: ChoiceBase

A drop-down list of options.

noneOption = ('', '')
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
class gavo.formal.widget.SelectOtherChoice(original, options=None, otherOption=None)[source]

Bases: object

A <select> widget that includes an “Other …” option. When the other option is selected an <input> field is enabled to allow free text entry.

Unlike SelectChoice, the options items are not a (value,label) tuple because that makes no sense with the free text entry facility.

TODO:
  • Make the Other option configurable in the JS

  • Refactor, refactor, refactor

noneOption = ('', '')
options = None
otherOption = ('...', 'Other ...')
processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
template = None
class gavo.formal.widget.TextArea(original, cols=None, rows=None)[source]

Bases: object

A large text entry area that accepts newline characters.

<textarea>…</textarea>

cols = 48
processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
rows = 6
class gavo.formal.widget.TextAreaList(original, cols=None, rows=None)[source]

Bases: object

A text area that allows a list of values to be entered, one per line. Any empty lines are discarded.

cols = 48
processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
rows = 6
class gavo.formal.widget.TextInput(original)[source]

Bases: object

A text input field.

<input type=”text” … />

inputType = 'text'
placeholder = None
processInput(request, key, args, default='')[source]
render(request, key, args, errors)[source]
renderImmutable(request, key, args, errors)[source]
showValueOnFailure = True