zoom.fields module

zoom.Fields

class zoom.fields.BasicImageField(label='', *validators, **keywords)

Bases: zoom.fields.Field

Image Field

>>> f = BasicImageField('Photo')
>>> f.initialize(None)
>>> f.value
>>> f.name
'photo'
>>> i = BasicImageField('Photo')
>>> i.initialize({'photo': b'data blob', 't':12})
>>> i.value
b'data blob'
>>> i.display_value()
'<img alt="Photo" class="image-field-image" src="image?name=photo" />'
alt = None
assign(value)

Assign a value to a BasicImageField

css_class = 'image-field'
default = None
display_value()

Display BasicImageField value

BasicImageFields rely on the controller of the current resource providing an image method so that when it wants to display the associted image, it uses a standard img field which calls back to the app to get the image.

evaluate()

Evaluate a BasicImageField

no_image_url = '/static/zoom/images/no_image.png'
requires_multipart_form()

Returns True because images require multipart forms

update(**values)

Update the ImageField field values

We override the superclass here because we need behaviour specific to how image fields arrive from forms.

updated_value = None
url = None
value = None
widget()

Returns the BasicImageField widget

BasicImageField use an HTML input of type “file” to collect the filename of the image to be uploaded.

If the field aready has a value, the BasicImageField also provides a view of the current image with a link for deleting the current image. BasicImageField relies on the current controller to provide the delete-image method.

class zoom.fields.BirthdateField(label='', *validators, **keywords)

Bases: zoom.fields.DateField

css_class = 'birthdate_field'
maxlength = 12
size = 12
class zoom.fields.Button(caption='Save', **keywords)

Bases: zoom.fields.Field

Button field.

>>> Button('Save').show()
''
>>> Button('Save').edit()
'<input class="button" type="submit" id="save_button" name="save_button" value="Save" />'
>>> Button('Save', cancel='/app/cancel').edit()
'<input class="button" type="submit" id="save_button" name="save_button" value="Save" />&nbsp;<a href="/app/cancel">cancel</a>'
as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
edit()

edit the field

evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

show()

show the field

class zoom.fields.ButtonField(caption='Save', **keywords)

Bases: zoom.fields.Button

Button field.

>>> ButtonField('Save').show()
''
>>> print(ButtonField('Save').edit())
<div class="field">
  <div class="field_label">&nbsp;</div>
  <div class="field_edit"><input class="button" type="submit" id="save_button" name="save_button" value="Save" /></div>
</div>
edit()

edit the field

evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

class zoom.fields.Buttons(captions=['Save'], **keywords)

Bases: zoom.fields.Field

>>> Buttons(['Save','Publish','Delete']).show()
''
>>> Buttons(['Save','Publish']).widget()
'<input class="button" type="submit" id="save_button" name="save_button" value="Save" />&nbsp;<input class="button" type="submit" id="publish_button" name="publish_button" value="Publish" />'
>>> Buttons(['Save'], cancel='/app/id').widget()
'<input class="button" type="submit" id="save_button" name="save_button" value="Save" />&nbsp;<a href="/app/id">cancel</a>'
as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
edit()

edit the field

evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

show()

show the field

widget()

returns the field widget

class zoom.fields.ButtonsField(captions=['Save'], **keywords)

Bases: zoom.fields.Buttons

Buttons field.

>>> ButtonsField('Save').show()
''
>>> print(ButtonsField(['Save','Publish']).edit())
<div class="field">
  <div class="field_label">&nbsp;</div>
  <div class="field_edit"><input class="button" type="submit" id="save_button" name="save_button" value="Save" />&nbsp;<input class="button" type="submit" id="publish_button" name="publish_button" value="Publish" /></div>
</div>
edit()

edit the field

class zoom.fields.CheckboxField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Checkbox Field

>>> CheckboxField('Done').display_value()
'no'
>>> CheckboxField('Done', value=True).display_value()
'yes'
>>> CheckboxField('Done').widget()
'<input class="checkbox_field" type="checkbox" id="done" name="done" />'
>>> f = CheckboxField('Done', value=True)
>>> f.widget()
'<input checked class="checkbox_field" type="checkbox" id="done" name="done" />'
>>> f.validate(**{'DONE': 'on'})
True
>>> f.evaluate()
{'done': True}
>>> f = CheckboxField('Done')
>>> f.widget()
'<input class="checkbox_field" type="checkbox" id="done" name="done" />'
>>> f.evaluate()
{'done': None}
>>> f.validate(**{})
True
>>> f.evaluate()
{'done': None}
>>> f = CheckboxField('Done')
>>> f.widget()
'<input class="checkbox_field" type="checkbox" id="done" name="done" />'
>>> f.evaluate()
{'done': None}
>>> f.validate(**{'DONE': 'on'})
True
>>> f.evaluate()
{'done': True}
>>> f = CheckboxField('Done', options=['yes','no'], value=False)
>>> f
<Field name='done' value=False>
>>> f.validate(**{'done': True})
True
>>> f
<Field name='done' value=True>
>>> f.validate(**{'DoNE': False})
True
>>> f
<Field name='done' value=False>
>>> f.validate(**{'done': 'on'})
True
>>> f
<Field name='done' value='on'>
>>> f.display_value()
'yes'
>>> f.evaluate()
{'done': True}
>>> f = CheckboxField('Done', options=['yep','nope'], default=True)
>>> f.evaluate()
{'done': True}
>>> f.widget()
'<input checked class="checkbox_field" type="checkbox" id="done" name="done" />'
>>> f.update(other='test')
>>> f.widget()
'<input class="checkbox_field" type="checkbox" id="done" name="done" />'
>>> f = CheckboxField('Done', options=['yep','nope'])
>>> f.evaluate()
{'done': None}
>>> f.validate(**{'OTHERDATA': 'some value'})
True
>>> f.evaluate()
{'done': False}
>>> CheckboxField('Done', options=['yep','nope']).display_value()
'nope'
>>> CheckboxField('Done', options=['yep','nope'], default=False).display_value()
'nope'
>>> CheckboxField('Done', options=['yep','nope'], default=True).display_value()
'nope'
>>> CheckboxField('Done', options=['yep','nope'], default=True).evaluate()
{'done': True}
>>> CheckboxField('Done', options=['yep','nope'], default=True, value=False).display_value()
'nope'
>>> CheckboxField('Done', options=['yep','nope'], value=True).display_value()
'yep'
>>> CheckboxField('Done', options=['yep','nope'], value=False).evaluate()
{'done': False}
>>> CheckboxField('Done', options=['yep','nope'], value='True').value
'True'
assign(value)

assign a value to the field

default = None
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

options = ['yes', 'no']
show()

show the field

truthy = [True, 'True', 'yes', 'on']
update(**values)

Update field.

>>> name_field = Field('Name', value='Sam')
>>> name_field.value
'Sam'
>>> name_field.update(city='Vancouver')
>>> name_field.value
'Sam'
>>> name_field.update(name='Joe')
>>> name_field.value
'Joe'
>>> name_field.update(NaMe='Adam')
>>> name_field.value
'Adam'
value = None
widget()

returns the field widget

class zoom.fields.CheckboxesField(label='', *validators, **keywords)

Bases: zoom.fields.Field

Checkboxes field.

>>> cb = CheckboxesField('Select', value='One', values=['One','Two','Three'], hint='test hint')
>>> print(cb.widget())
<ul class="checkbox_field">
<li><input checked class="checkbox_field" type="checkbox" id="select" name="select" value="One" /><div>One</div></li>
<li><input class="checkbox_field" type="checkbox" id="select" name="select" value="Two" /><div>Two</div></li>
<li><input class="checkbox_field" type="checkbox" id="select" name="select" value="Three" /><div>Three</div></li>
</ul>
show()

show the field

widget()

returns the field widget

class zoom.fields.ChosenMultiselectField(*a, **k)

Bases: zoom.fields.MultiselectField

Chosen Multiselect field.

>>> from zoom.component import Component
>>> f = ChosenMultiselectField('Choose', options=['One','Two','Three'], hint='test hint')
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', options=['One','Two','Three'], hint='test hint', placeholder='my placeholder')
>>> print(f.widget())
<select data-placeholder="my placeholder" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', value='2', options=['One', 'Two', 'Three'])
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="One">One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', value='Two', options=['One', 'Two', 'Three'])
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="One">One</option>
<option value="Two" selected>Two</option>
<option value="Three">Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', value='2', options=[('One', '1'), ('Two', '2'), ('Three', '3')])
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="1">One</option>
<option value="2" selected>Two</option>
<option value="3">Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', value='Two', options=[('One', '1'), ('Two', '2'), ('Three', '3')])
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="1">One</option>
<option value="2" selected>Two</option>
<option value="3">Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', value=['Two', 3], options=[('One', '1'), ('Two', '2'), ('Three', '3')])
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="1">One</option>
<option value="2" selected>Two</option>
<option value="3" selected>Three</option>
</select>
>>> f = ChosenMultiselectField('Choose', value=['One', 3], options=[('One', 1), ('Two', 2), ('Three', 3)])
>>> print(f.widget())
<select data-placeholder="Select Choose" multiple="multiple" class="chosen" name="choose" id="choose">
<option value="1" selected>One</option>
<option value="2">Two</option>
<option value="3" selected>Three</option>
</select>
css_class = 'chosen'
select_layout = '<select data-placeholder="{}" multiple="multiple" class="{}" name="{}" id="{}">\n'
widget()

returns the field widget

class zoom.fields.ChosenSelectField(*a, **k)

Bases: zoom.fields.PulldownField

css_class = 'chosen'
libs = ['/static/zoom/chosen/chosen.jquery.js']
select_layout = '<select data-placeholder="{place}" class="{classed}" name="{name}" id="{name}">\n'
styles = ['/static/zoom/chosen/chosen.css']
class zoom.fields.DataURIAttachmentsField(label='', *validators, **keywords)

Bases: zoom.fields.Field

An Attachments field - DEPRECATED

this field stores the data within the database this field uses dropzone.js heavily the results are shown via a Data URI

this field stores the data within the database this field uses dropzone.js heavily the results are shown via a Data URI multiple dropzones supported by assuming you will bind ONLY one to the form

and the others to an element via the “selector” configuration option

TODO: with multiple dropzones, support submit when the master/form is empty This field makes some assumptions about what you want todo:

  • this field uses dropzone.js
  • the field expects you want todo a native form submission (once vs. multiple ajax calls)
  • this field stores the data within the database
  • the results are shown via a Data URI which is not always optimal
  • it looks like dropzone.js only adds the form fields when dropzone is bound
    to a form (i.e. binding to dropzone within a form skips this - assumes xhr)
  • due to assumption to mimic native form, the data makes round trips to/from server
>>> icon = DataURIAttachmentsField('Icon')
>>> icon.requires_multipart_form()
True
>>> icon.assign(None)
>>> assert icon.value == icon.default
>>> class PsuedoFile(object):
...     @property
...     def name(self):
...         return 'field_name'
...     @property
...     def filename(self):
...         return 'filename.png'
...     @property
...     def value(self):
...         return b''
>>> icon.assign([PsuedoFile(), PsuedoFile()])
>>> assert isinstance(icon.value, list)
>>> icon.value
[['field_name', ['filename.png', '']], ['field_name', ['filename.png', '']]]
as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
assign(value={})

assign a value to the field

capitalize

return the field id capitalized

classed = 'dropzone nojs'
configuration

configure the Dropzone .js assets

this field is designed to work within an existing/native form. As such, we turn off the auto processing of the queue (AJAX push) to bulk send the form all at once.

css = '<link href="/static/zoom/dropzone/dropzone.min.css" rel="stylesheet" type="text/css" />'
datauri(image)

return the data URI string

default = []
display_value()

web based display view of the field

edit()

edit the field

maximum_files = 5
mockFile

return the saved file - this is a .js call and injected into the .js

no_image_url = 'https://placehold.it/350x150'
requires_multipart_form()

return True if a multipart form is required for this field

script = ['<script type="text/javascript" src="/static/zoom/dropzone/dropzone.min.js"></script>', '<script type="text/javascript">Dropzone.autoDiscover = false;</script>']
selector = '#zoom_form'
update(**values)

update the field

widget()

return the dropzone widget

class zoom.fields.DataURIImageField(label='', *validators, **keywords)

Bases: zoom.fields.DataURIAttachmentsField

An Attachments field making use of a Data URI where we limit to a single file

maximum_files = 1
zoom.fields.DataURIImagesField

alias of zoom.fields.DataURIAttachmentsField

class zoom.fields.DateField(label='', *validators, **keywords)

Bases: zoom.fields.Field

Date Field

DatField values can be either actual dates (datetime.date) or string representations of dates. Values coming from databases or from code will typically be dates, while dates coming in from forms will typically be strings.

DateFields always evaluate to date types and always display as string representations of those dates formatted according to the specified format.

>>> DateField("Start Date").widget()
'<input class="date_field" type="text" id="start_date" maxlength="12" name="start_date" value="" />'
>>> from datetime import date, datetime
>>> f = DateField("Start Date")
>>> f.display_value()
''
>>> f.assign('')
>>> f.display_value()
''
>>> f = DateField("Start Date", value=date(2015,1,1))
>>> f.value
datetime.date(2015, 1, 1)
>>> f = DateField("Start Date", value=datetime(2015,1,1))
>>> f.value
datetime.datetime(2015, 1, 1, 0, 0)
>>> f.evaluate()
{'start_date': datetime.date(2015, 1, 1)}
>>> f.assign('Jan 01, 2015') # forms assign with strings
>>> f.display_value()
'Jan 01, 2015'
>>> f.evaluate()
{'start_date': datetime.date(2015, 1, 1)}
>>> f.assign('2015-12-31') # forms assign with strings
>>> f.display_value()
'Dec 31, 2015'
>>> f.evaluate()
{'start_date': datetime.date(2015, 12, 31)}
>>> f.assign(date(2015,1,31))
>>> f.display_value()
'Jan 31, 2015'
>>> f.assign('TTT 01, 2015')
>>> f.display_value()
'TTT 01, 2015'
>>> failed = False
>>> try:
...     f.evaluate()
... except ValueError:
...     failed = True
>>> failed
True
>>> DateField("Start Date", value=date(2015,1,1)).widget()
'<input class="date_field" type="text" id="start_date" maxlength="12" name="start_date" value="Jan 01, 2015" />'
alt_input_format = '%Y-%m-%d'
as_searchable()

Return searchable parts of field

>>> from datetime import date, datetime
>>> f = DateField("Start Date")
>>> f.assign(date(2015,1,31))
>>> f.display_value()
'Jan 31, 2015'
>>> f.as_searchable()
{'2015-01-31 01-31-2015 Saturday January 31 2015'}
css_class = 'date_field'
default = None
display_value(alt_format=None)

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

format = '%b %d, %Y'
input_format = '%b %d, %Y'
max = None
maxlength = 12
min = None
search_fmt = '{:%Y-%m-%d %m-%d-%Y %A %B %-d %Y}'
show()

show the field

size = 12
validators = [<zoom.validators.DateValidator object>]
value = None
widget()

returns the field widget

class zoom.fields.DecimalField(label='', *validators, **keywords)

Bases: zoom.fields.NumberField

Decimal Field

>>> DecimalField('Count',value="2.1").display_value()
'2.1'
>>> DecimalField('Count', value=Decimal('10.24')).widget()
'<input class="decimal_field" type="text" id="count" maxlength="10" name="count" size="10" value="10.24" />'
>>> DecimalField('Count').widget()
'<input class="decimal_field" type="text" id="count" maxlength="10" name="count" size="10" value="" />'
>>> n = DecimalField('Size')
>>> n.assign('2.1')
>>> n.value
Decimal('2.1')
>>> n.assign(0)
>>> n.value
Decimal('0')
>>> n.assign('0')
>>> n.value
Decimal('0')
>>> n.assign('2.1')
>>> n.value
Decimal('2.1')
>>> n.assign('')
>>> n.evaluate()
{'size': None}
>>> DecimalField('Hours').evaluate()
{'hours': 0}
converter

alias of decimal.Decimal

css_class = 'decimal_field'
maxlength = 10
size = 10
value = 0
class zoom.fields.EditField(label='', *validators, **keywords)

Bases: zoom.fields.MemoField

Large textedit.

>>> EditField('Notes').widget()
'<textarea class="edit_field" height="6" id="notes" name="notes" size="10"></textarea>'
css_class = 'edit_field'
edit()

edit the field

height = 6
size = 10
value = ''
widget()

returns the field widget

class zoom.fields.EmailField(label, *validators, **keywords)

Bases: zoom.fields.TextField

Email field

>>> EmailField('Email').widget()
'<input class="text_field" id="email" maxlength="60" name="email" size="30" type="text" value="" />'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
maxlength = 60
size = 30
class zoom.fields.Field(label='', *validators, **keywords)

Bases: object

Field base class

as_dict()
as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
assign(value)

assign a value to the field

browse = True
clean(*args, **kwargs)

Update (sometimes ammended values) and validate a field.

>>> from zoom.validators import Cleaner, required
>>> upper = Cleaner(str.upper)
>>> name_field = Field('Name', upper, required)
>>> name_field.clean(city='Vancouver')
False
>>> name_field.validate(name='Vancouver')
True
>>> name_field.value
'Vancouver'
>>> name_field.clean(name='Vancouver')
True
>>> name_field.value
'VANCOUVER'
default = ''
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
edit()

edit the field

evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

field_layout = <zoom.fields.FieldLayout object>
hint = ''
initialize(*a, **k)

Initialize field value.

Set field value according to value passed in as parameter or if there is not value for this field, set it to the default value for the field.

>>> f = Field('test', default='zero')
>>> f.initialize(test='one')
>>> f.value
'one'
>>> r = dict(test='two')
>>> f.initialize(r)
>>> f.value
'two'
>>> r = dict(not_test='two')
>>> f.initialize(r)
>>> f.value
'zero'
label = ''
layout(label, content, edit=True)
msg = ''
options = []
placeholder = None
render_hint()

Render hint.

>>> name_field = Field('Name', hint='Full name')
>>> name_field.render_hint()
'<span class="hint">Full name</span>'
render_msg()

Render validation error message.

>>> from zoom.validators import required
>>> name_field = Field('Name', required)
>>> name_field.update(NAME='')
>>> name_field.valid()
False
>>> name_field.render_msg()
'<span class="wrong">required</span>'
requires_multipart_form()

return True if a multipart form is required for this field

show()

show the field

update(**values)

Update field.

>>> name_field = Field('Name', value='Sam')
>>> name_field.value
'Sam'
>>> name_field.update(city='Vancouver')
>>> name_field.value
'Sam'
>>> name_field.update(name='Joe')
>>> name_field.value
'Joe'
>>> name_field.update(NaMe='Adam')
>>> name_field.value
'Adam'
valid()

Validate field value.

>>> from zoom.validators import required
>>> name_field = Field('Name',required)
>>> name_field.update(NAME='Fred')
>>> name_field.valid()
True
>>> name_field.update(NAME='')
>>> name_field.valid()
False
>>> name_field.msg
'required'
validate(*a, **k)

Update and validate a field.

>>> from zoom.validators import required
>>> name_field = Field('Name',required)
>>> name_field.validate(city='Vancouver')
False
>>> name_field.validate(name='Fred')
True
>>> name_field.value
'Fred'
validators = []
value = ''
visible = True
widget()

returns the field widget

wrap = ' nowrap'
class zoom.fields.FieldIterator(fields)

Bases: object

class zoom.fields.FieldLayout

Bases: object

edit(field)
field_template = '<div class="field">\n <div class="field_label">{label}</div>\n <div class="field_{mode}">{content}</div>\n</div>\n'
hint_template = '<table class="transparent">\n <tr>\n <td{wrap}>{widget}</td>\n <td>\n <div class="hint">{hints}</div>\n </td>\n </tr>\n</table>\n'
class zoom.fields.Fields(*args)

Bases: object

A collection of field objects.

>>> fields = Fields(TextField('Name'), PhoneField('Phone'))
>>> print(fields.edit())
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_edit"><table class="transparent">
    <tr>
        <td nowrap><input class="text_field" id="name" maxlength="40" name="name" size="40" type="text" value="" /></td>
        <td>
            <div class="hint"></div>
        </td>
    </tr>
</table>
</div>
</div>
<div class="field">
  <div class="field_label">Phone</div>
  <div class="field_edit"><table class="transparent">
    <tr>
        <td nowrap><input class="text_field" id="phone" name="phone" size="20" type="text" value="" /></td>
        <td>
            <div class="hint"></div>
        </td>
    </tr>
</table>
</div>
</div>
>>> from zoom.utils import pp
>>> fields = Fields(TextField('Name', value='Amy'), PhoneField('Phone', value='2234567890'))
>>> pp(fields.as_dict())
{
  'name' ...........: <Field name='name' value='Amy'>
  'phone' ..........: <Field name='phone' value='2234567890'>
}
>>> fields = Fields(TextField('Name'), MemoField('Notes'))
>>> fields.validate({'name': 'Test'})
True
>>> d = fields.evaluate()
>>> d['name']
'Test'
>>> len(d['notes'])
0
>>> fields.validate({'notes': 'here are some notes'})
True
>>> d = fields.evaluate()
>>> len(d['notes'])
19
>>> pp(fields.as_dict())
{
  'name' ...........: <Field name='name' value='Test'>
  'notes' ..........: <Field name='notes' value='here are some notes'>
}
>>> record = dict(name='Adam', notes='no text here')
>>> pp(record)
{
  "name": "Adam",
  "notes": "no text here"
}
>>> record.update(fields)
>>> record['name']
'Test'
>>> len(record['notes'])
19
as_dict()
as_list()
>>> fields = Fields(TextField('Name', value='Amy'), PhoneField('Phone', value='2234567890'))
>>> fields.as_list()
[<Field name='name' value='Amy'>, <Field name='phone' value='2234567890'>]
as_searchable()

Return fields as a set of searchable items

>>> from zoom.utils import pp
>>> fields = Fields(
...     TextField('Name', value='Amy'),
...     PhoneField('Phone', value='2234567890'),
...     DateField('Birthdate', value=datetime.date(1980,1,1)),
...     MultiselectField(
...         'Type',
...         value=['One','dos'],
...         options=[('One','uno'),('Two','dos')]
...     )
... )
>>> pp(sorted(map(str, fields.as_searchable())))
[
  "1980-01-01 01-01-1980 Tuesday January 1 1980",
  "2234567890",
  "Amy",
  "One",
  "Two"
]
clean(*args, **kwargs)
display_value()
>>> from zoom.utils import pp
>>> fields = Fields(TextField('Name', value='Amy'), PhoneField('Phone', value='2234567890'))
>>> pp(fields.display_value())
{
  "name": "Amy",
  "phone": "2234567890"
}
edit()
evaluate()
>>> from zoom.utils import pp
>>> fields = Fields(TextField('Name', value='Amy'), PhoneField('Phone', value='2234567890'))
>>> pp(fields.evaluate())
{
  "name": "Amy",
  "phone": "2234567890"
}
initialize(*a, **k)

Initialize Field values

>>> from zoom.utils import pp
>>> fields = Fields(TextField('Name', value='Amy'), PhoneField('Phone', value='2234567890'))
>>> fields.initialize(phone='987654321')
>>> pp(fields.as_dict())
{
  'name' ...........: <Field name='name' value=''>
  'phone' ..........: <Field name='phone' value='987654321'>
}
requires_multipart_form()
show()
update(*a, **k)

Update Field values

>>> from zoom.utils import pp
>>> fields = Fields(TextField('Name', value='Amy'), PhoneField('Phone', value='2234567890'))
>>> fields.update(phone='987654321')
>>> pp(fields.as_dict())
{
  'name' ...........: <Field name='name' value='Amy'>
  'phone' ..........: <Field name='phone' value='987654321'>
}
valid()
validate(*a, **k)
class zoom.fields.Fieldset(label, fields, hint='')

Bases: zoom.fields.Fields

A collection of field objects with an associated label.

>>> print(Section('Personal',[TextField('Name',value='Joe')]).show())
<h2>Personal</h2>
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_show">Joe</div>
</div>
edit()
render_hint()
show()
class zoom.fields.FileField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

>>> FileField('Document').widget()
'<input class="file_field" id="document" name="document" type="file" value="None" />'
assign(value)

assign a value to the field

css_class = 'file_field'
default = 'None'
requires_multipart_form()

return True if a multipart form is required for this field

value = 'None'
class zoom.fields.FloatField(label='', *validators, **keywords)

Bases: zoom.fields.NumberField

Float Field

>>> FloatField('Count', value=2.1).display_value()
'2.1'
>>> FloatField('Count').widget()
'<input class="float_field" type="text" id="count" maxlength="10" name="count" size="10" value="" />'
>>> n = FloatField('Size')
>>> n.assign(2.1)
>>> n.value
2.1
>>> n.assign(0)
>>> n.value
0.0
>>> n.assign('0')
>>> n.value
0.0
>>> n.assign('2.1')
>>> n.value
2.1
>>> n.assign('')
>>> n.evaluate()
{'size': None}
converter

alias of builtins.float

css_class = 'float_field'
evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

maxlength = 10
size = 10
value = 0
class zoom.fields.Hidden(label='', *validators, **keywords)

Bases: zoom.fields.Field

Hidden field.

>>> Hidden('Hide Me').show()
''
>>> Hidden('Hide Me', value='test').edit()
'<input type="hidden" id="hide_me" name="hide_me" value="test" />'
edit()

edit the field

visible = False
zoom.fields.ImageField

alias of zoom.fields.BasicImageField

class zoom.fields.ImagesField(label='', *validators, **keywords)

Bases: zoom.fields.Field

Display a drag and drop multiple image storage field

this field is experimental - may change for a while yet

>>> ImagesField('Photo')
<Field name='photo' value=None>
default = '0f3c648630874d50adb45308a5300021'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
show()

show the images field

url = ''
value = None
widget()

returns the field widget

wrap = ''
class zoom.fields.IntegerField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Integer Field

>>> IntegerField('Count', value=2).display_value()
'2'
>>> IntegerField('Count').widget()
'<input class="number_field" id="count" maxlength="10" name="count" size="10" type="text" value="" />'
>>> n = IntegerField('Size')
>>> n.assign('2')
>>> n.value
2
>>> n.evaluate()
{'size': 2}
>>> n = IntegerField('Size', units='meters')
>>> n.assign('22234')
>>> n.value
22234
>>> n.display_value()
'22,234 meters'
>>> n.assign('')
>>> n.evaluate()
{'size': ''}
as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
assign(value)

assign a value to the field

css_class = 'number_field'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
maxlength = 10
size = 10
units = ''
value = 0
class zoom.fields.MarkdownEditField(label='', *validators, **keywords)

Bases: zoom.fields.EditField

Large markdown edit field

>>> MarkdownEditField('Notes').widget()
'<textarea class="edit_field" height="6" id="notes" name="notes" size="10"></textarea>'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
class zoom.fields.MarkdownField(label='', *validators, **keywords)

Bases: zoom.fields.MemoField

>>> f = MarkdownField('Notes', value='test **one** 23')
>>> f.display_value()
'<p>test <strong>one</strong> 23</p>'
>>> target = (
...     '<div class="field">\n'
...     '  <div class="field_label">Notes</div>\n'
...     '  <div class="field_edit"><textarea class="memo_field" cols="60" id="notes" name="notes" rows="6" size="10">test **one** 23</textarea></div>\n'
...     '</div>\n'
... )
>>> f.edit() == target
True
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
class zoom.fields.MarkdownText(text)

Bases: object

a markdown text object that can be placed in a form like a field

>>> f = MarkdownText('One **bold** statement')
>>> f.edit()
'<p>One <strong>bold</strong> statement</p>'
edit()

display the markdown as text, even in edit mode

evaluate()

return the value

Not a field so doesn’t return a value

class zoom.fields.MemoField(label='', *validators, **keywords)

Bases: zoom.fields.Field

Edit a paragraph of text.

>>> print(MemoField('Notes').widget())
<textarea class="memo_field" cols="60" id="notes" name="notes" rows="6" size="10"></textarea>
cols = 60
css_class = 'memo_field'
edit()

edit the field

height = 6
rows = 6
show()

show the field

size = 10
value = ''
widget()

returns the field widget

class zoom.fields.MoneyField(label='', *validators, **keywords)

Bases: zoom.fields.DecimalField

Money Field

>>> f = MoneyField("Amount")
>>> f.widget()
'<div class="input-group"><span class="input-group-addon">$</span><input class="decimal_field" type="text" id="amount" maxlength="10" name="amount" size="10" value="" /></div>'
>>> f.display_value()
'$0.00'
>>> f.assign(Decimal(1000))
>>> f.display_value()
'$1,000.00'
>>> from platform import system
>>> l = system()=='Windows' and 'eng' or 'en_GB.utf8'
>>> f = MoneyField("Amount", locale=l)
>>> f.display_value()
'\xa30.00'
>>> f.assign(Decimal(1000))
>>> f.display_value()
'\xa31,000.00'
>>> print(f.show())
<div class="field">
  <div class="field_label">Amount</div>
  <div class="field_show">£1,000.00</div>
</div>
>>> f.widget()
'<div class="input-group"><span class="input-group-addon">£</span><input class="decimal_field" type="text" id="amount" maxlength="10" name="amount" size="10" value="1000" /></div>'
>>> f.units = 'per month'
>>> f.display_value()
'\xa31,000.00 per month'
>>> f.units = ''
>>> f.display_value()
'\xa31,000.00'
>>> f.assign('')
>>> f.display_value()
''
>>> f.assign('0')
>>> f.display_value()
'\xa30.00'
>>> f.assign(' ')
>>> f.display_value()
''
>>> f = MoneyField("Amount", placeholder='0')
>>> f.widget()
'<div class="input-group"><span class="input-group-addon">$</span><input class="decimal_field" type="text" id="amount" maxlength="10" name="amount" placeholder="0" size="10" value="" /></div>'
>>> f = MoneyField("Amount", symbol='£', value=1)
>>> f.widget()
'<div class="input-group"><span class="input-group-addon">£</span><input class="decimal_field" type="text" id="amount" maxlength="10" name="amount" size="10" value="1" /></div>'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
locale = None
symbol = '$'
widget()

returns the field widget

class zoom.fields.MultiselectField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Multiselect Field

>>> MultiselectField('Type',value='One',options=['One','Two']).display_value()
'One'
>>> f = MultiselectField('Type', default='One', options=['One','Two'])
>>> f.evaluate()
{'type': []}
>>> f.display_value()
''
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="One" selected>One</option>
<option value="Two">Two</option>
</select>
>>> f.value
>>> f.assign([])
>>> f.value
[]
>>> f.evaluate()
{'type': []}
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="One">One</option>
<option value="Two">Two</option>
</select>
>>> f= MultiselectField('Type',value='One',options=['One','Two'])
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="One" selected>One</option>
<option value="Two">Two</option>
</select>
>>> f = MultiselectField('Type',value=['One','Three'],options=['One','Two','Three'])
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="One" selected>One</option>
<option value="Two">Two</option>
<option value="Three" selected>Three</option>
</select>
>>> f = MultiselectField('Type',default=['One'],options=['One','Two','Three'])
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="One" selected>One</option>
<option value="Two">Two</option>
<option value="Three">Three</option>
</select>
>>> f = MultiselectField('Type',default=['One','Two'],options=['One','Two','Three'])
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="One" selected>One</option>
<option value="Two" selected>Two</option>
<option value="Three">Three</option>
</select>
>>> f = MultiselectField('Type',value='One',options=[('One','uno'),('Two','dos')])
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="uno" selected>One</option>
<option value="dos">Two</option>
</select>
>>> f.value
['uno']
>>> f.evaluate()
{'type': ['uno']}
>>> f.value = ['One']
>>> f.value
['One']
>>> f.evaluate()
{'type': ['uno']}
>>> f.update(**{'type':['dos']})
>>> f.value
['dos']
>>> f.evaluate()
{'type': ['dos']}
>>> f = MultiselectField('Type',value='uno',options=[('One','uno'),('Two','dos')])
>>> f.display_value()
'One'
>>> f = MultiselectField('Type',value='uno',options=[('One','uno'),('One','dos')])
>>> f.display_value()
'One'
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option value="uno" selected>One</option>
<option value="dos">One</option>
</select>
>>> f = MultiselectField('Type',value=['One','dos'],options=[('One','uno'),('Two','dos')])
>>> f.display_value()
'One; Two'
>>> f.evaluate()
{'type': ['uno', 'dos']}
>>> sorted(f.as_searchable())
['One', 'Two']
>>> f = MultiselectField('Type',value=['One'],options=[('One','uno'),('Two','dos')])
>>> f.display_value()
'One'
>>> f.evaluate()
{'type': ['uno']}
>>> f = MultiselectField('Type', options=[('One','uno'),('Two','dos')])
>>> f.initialize({'type': 'One'})
>>> f.evaluate()
{'type': ['uno']}
>>> f = MultiselectField('Type',value=['uno','dos'],options=[('One','uno'),('Two','dos')])
>>> f.display_value()
'One; Two'
>>> f.evaluate()
{'type': ['uno', 'dos']}
>>> f.option_style('zero','nada')
''
>>> s = lambda label, value: value.startswith('d') and 's1' or 's0'
>>> f = MultiselectField('Type',value=['uno','dos'],options=[('One','uno'),('Two','dos')], styler=s)
>>> print(f.widget())
<select multiple="multiple" class="multiselect" name="type" id="type">
<option class="s0" value="uno" selected>One</option>
<option class="s1" value="dos" selected>Two</option>
</select>
>>> f.styler('test','dos')
's1'
>>> f.option_style('zero','nada')
'class="s0" '

# test for iterating over a string vs. a sequence type (iteration protocol) >>> m1 = MultiselectField(‘Type’, default=‘11’, options=[(‘One’,‘1’),(‘Two’,‘2’),(‘Elves’,‘11’),]).widget() >>> m2 = MultiselectField(‘Type’, default=(‘11’,), options=[(‘One’,‘1’),(‘Two’,‘2’),(‘Elves’,‘11’),]).widget() >>> assert m1 == m2

as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
assign(new_value)

assign a value to the field

css_class = 'multiselect'
default = []
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

option_style(label, value)
styler = None
update(**values)

Update field.

>>> name_field = Field('Name', value='Sam')
>>> name_field.value
'Sam'
>>> name_field.update(city='Vancouver')
>>> name_field.value
'Sam'
>>> name_field.update(name='Joe')
>>> name_field.value
'Joe'
>>> name_field.update(NaMe='Adam')
>>> name_field.value
'Adam'
value = None
widget()

returns the field widget

class zoom.fields.NumberField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Number Field

>>> NumberField('Size', value=2).display_value()
'2'
>>> NumberField('Size').widget()
'<input class="number_field" type="text" id="size" maxlength="10" name="size" size="10" value="" />'
>>> n = NumberField('Size')
>>> n.assign('2')
>>> n.value
2
>>> n = NumberField('Size', units='units')
>>> n.assign('2,123')
>>> n.value
2123
>>> n.evaluate()
{'size': 2123}
>>> n.display_value()
'2,123 units'
>>> n.assign(None)
>>> n.value == None
True
>>> n.display_value()
''
as_searchable()

Return searchable parts of field

>>> name_field = Field('Name', default='default test')
>>> name_field.as_searchable()
{'default test'}
>>> name_field = Field('Name', value='test')
>>> name_field.as_searchable()
{'test'}
>>> name_field = Field('Age', value=10)
>>> name_field.as_searchable()
{'10'}
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.as_searchable()
{'こんにちは'}
>>> name_field.visible = False
>>> name_field.as_searchable()
set()
>>> EmailField('Email', value='test@testco.com').as_searchable()
{'test@testco.com'}
assign(value)

assign a value to the field

converter

alias of builtins.int

css_class = 'number_field'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

maxlength = 10
size = 10
units = ''
widget()

returns the field widget

class zoom.fields.PasswordField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Password Field

>>> PasswordField('Password').show()
''
>>> PasswordField('Password').widget()
'<input class="text_field" id="password" maxlength="40" name="password" size="40" type="password" value="" />'
maxlength = 40
show()

show the field

size = 40
class zoom.fields.PhoneField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Phone field

>>> PhoneField('Phone').widget()
'<input class="text_field" id="phone" name="phone" size="20" type="text" value="" />'
size = 20
validators = [<zoom.validators.RegexValidator object>]
class zoom.fields.PostalCodeField(label='Postal Code', *validators, **keywords)

Bases: zoom.fields.TextField

Postal code field

>>> PostalCodeField('Postal Code').widget()
'<input class="text_field" id="postal_code" maxlength="7" name="postal_code" size="7" type="text" value="" />'
maxlength = 7
size = 7
class zoom.fields.PulldownField(*a, **k)

Bases: zoom.fields.TextField

Pulldown Field

>>> from zoom.component import Component
>>> PulldownField('Type',value='One',options=['One','Two']).display_value()
'One'
>>> print(PulldownField('Type',value='One',options=['One','Two']).widget())
<select class="pulldown" name="type" id="type">
<option value="One" selected>One</option>
<option value="Two">Two</option>
</select>
>>> print(PulldownField('Type',options=['One','Two']).widget())
<select class="pulldown" name="type" id="type">
<option value=""></option>
<option value="One">One</option>
<option value="Two">Two</option>
</select>
>>> f = PulldownField('Type', options=[('',''),('One',1),('Two',2)])
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value="" selected></option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
>>> f.assign(2)
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value=""></option>
<option value="1">One</option>
<option value="2" selected>Two</option>
</select>
>>> f.assign('2')
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value=""></option>
<option value="1">One</option>
<option value="2" selected>Two</option>
</select>
>>> f = PulldownField('Type', options=[('',''),('One','1'),('Two','2')])
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value="" selected></option>
<option value="1">One</option>
<option value="2">Two</option>
</select>
>>> f.assign(2)
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value=""></option>
<option value="1">One</option>
<option value="2" selected>Two</option>
</select>
>>> f.assign('2')
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value=""></option>
<option value="1">One</option>
<option value="2" selected>Two</option>
</select>
>>> f = PulldownField('Type',value='One',options=[('One','uno'),('Two','dos')])
>>> print(f.widget())
<select class="pulldown" name="type" id="type">
<option value="uno" selected>One</option>
<option value="dos">Two</option>
</select>
>>> f.value
'uno'
>>> f.evaluate()
{'type': 'uno'}
>>> f.value = 'One'
>>> f.value
'One'
>>> f.evaluate()
{'type': 'uno'}
>>> f.update(**{'tYpe':'dos'})
>>> f.value
'dos'
>>> f.evaluate()
{'type': 'dos'}
>>> f = PulldownField('Type',value='uno',options=[('One','uno'),('Two','dos')])
>>> f.display_value()
'One'
>>> f = PulldownField('Type',default='uno',options=[('One','uno'),('Two','dos')])
>>> f.display_value()
'One'
>>> f.evaluate()
{'type': 'uno'}
>>> p = PulldownField('Date', name='TO_DATE', options=[('JAN','jan'), ('FEB','feb'),], default='feb')
>>> p.evaluate()
{'TO_DATE': 'feb'}
>>> p.display_value()
'FEB'
assign(new_value)

assign a value to the field

css_class = 'pulldown'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
evaluate()

Evaluate field value.

Return the value of the field expressed as key value pair (dict) ususally to be combined with other fields in the native type where the value is the native data type for the field type.

libs = []
select_layout = '<select class="{classed}" name="{name}" id="{name}">\n'
styles = []
value = None
widget()

returns the field widget

class zoom.fields.RadioField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Radio Field

>>> RadioField('Choice', value='One', values=['One','Two']).display_value()
'One'
>>> print(RadioField('Choice', value='One', values=['One','Two']).widget())
<span class="radio"><input checked class="radio" name="choice" type="radio" value="One" />One</span>
<span class="radio"><input class="radio" name="choice" type="radio" value="Two" />Two</span>
>>> r = RadioField('Choice',value='1',values=[('One','1'),('Two','2')])
>>> print(r.widget())
<span class="radio"><input checked class="radio" name="choice" type="radio" value="1" />One</span>
<span class="radio"><input class="radio" name="choice" type="radio" value="2" />Two</span>
>>> r.assign('1')
>>> r.evaluate()
{'choice': '1'}
>>> r.display_value()
'One'
>>> r.assign('2')
>>> r.evaluate()
{'choice': '2'}
>>> r.display_value()
'Two'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
values = []
widget()

returns the field widget

class zoom.fields.RangeSliderField(label='', *validators, **keywords)

Bases: zoom.fields.IntegerField

jQuery UI Range Slider

>>> r = RangeSliderField('Price', min=0, max=1500)
>>> r.assign(0)
>>> r.value
(0, 1500)
>>> r.assign((10, 20))
>>> r.value
(10, 20)
>>> r.assign('10,20')
>>> r.value
(10, 20)
>>> isinstance(r.widget(), zoom.Component)
True
>>> isinstance(r.display_value(), str)
True
assign(v)

assign a value to the field

css_class = 'range-slider'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
js = '\n $( "#%(name)s" ).slider({\n range: true,\n min: %(tmin)s,\n max: %(tmax)s,\n values: [ %(minv)s, %(maxv)s ],\n change: function( event, ui ) {\n var v = ui.values,\n t = v[0] + \',\' + v[1];\n $("input[name=\'%(name)s\']").val(t);\n %(formatter)s\n $( "div[data-id=\'%(name)s\'] span:nth-of-type(1)" ).html( formatter(ui.values[ 0 ]) );\n $( "div[data-id=\'%(name)s\'] span:nth-of-type(2)" ).html( formatter(ui.values[ 1 ]) );\n },\n slide: function( event, ui ) {\n var v = ui.values;\n %(formatter)s\n $( "div[data-id=\'%(name)s\'] span:nth-of-type(1)" ).html( formatter(ui.values[ 0 ]) );\n $( "div[data-id=\'%(name)s\'] span:nth-of-type(2)" ).html( formatter(ui.values[ 1 ]) );\n }\n });\n $("#%(name)s").slider("values", $("#%(name)s").slider("values")); // set formatted label\n '
js_formatter = 'var formatter = function(v) { return v;};'
max = 10
min = 0
show_labels = True
widget()

returns the field widget

class zoom.fields.Section(label, fields, hint='')

Bases: zoom.fields.Fields

A collection of field objects with an associated label.

>>> print(Section('Personal',[TextField('Name',value='Joe')]).show())
<h2>Personal</h2>
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_show">Joe</div>
</div>
edit()
name
render_hint()
show()
class zoom.fields.TextField(label='', *validators, **keywords)

Bases: zoom.fields.Field

Text Field

>>> print(TextField('Name', value="John Doe").show())
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_show">John Doe</div>
</div>
>>> print(TextField('Name',value='John Doe').widget())
<input class="text_field" id="name" maxlength="40" name="name" size="40" type="text" value="John Doe" />
>>> print(TextField('Name',value="Dan").show())
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_show">Dan</div>
</div>
>>> print(TextField('Name',default="Dan").show())
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_show">Dan</div>
</div>
>>> TextField('Name', hint="required").widget()
'<input class="text_field" id="name" maxlength="40" name="name" size="40" type="text" value="" />'
>>> TextField('Name', placeholder="Jack").widget()
'<input class="text_field" id="name" maxlength="40" name="name" placeholder="Jack" size="40" type="text" value="" />'
>>> f = TextField('Title')
>>> f.update(**{"TITLE": "Joe's Pool Hall"})
>>> f.value
"Joe's Pool Hall"
>>> f.evaluate()
{'title': "Joe's Pool Hall"}
css_class = 'text_field'
maxlength = 40
size = 40
widget()

returns the field widget

class zoom.fields.TwitterField(label='', *validators, **keywords)

Bases: zoom.fields.TextField

Twitter field

>>> TwitterField('Twitter').widget()
'<input class="text_field" id="twitter" name="twitter" type="text" value="" />'
>>> TwitterField('Twitter', value='dsilabs').display_value()
'<a target="_window" href="http://www.twitter.com/dsilabs">@dsilabs</a>'
display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
class zoom.fields.URLField(label, *validators, **keywords)

Bases: zoom.fields.TextField

URL Field

>>> URLField('Website', default='www.google.com').display_value()
'<a target="_window" href="http://www.google.com">http://www.google.com</a>'
>>> f = URLField('Website', default='www.google.com')
>>> f.assign('www.dsilabs.ca')
>>> f.display_value()
'<a target="_window" href="http://www.dsilabs.ca">http://www.dsilabs.ca</a>'
>>> f = URLField('Website', default='www.google.com')
>>> f.assign('http://www.dsilabs.ca')
>>> f.display_value()
'<a target="_window" href="http://www.dsilabs.ca">http://www.dsilabs.ca</a>'
>>> f = URLField('Website', default='www.google.com', trim=True)
>>> f.assign('http://www.dsilabs.ca/')
>>> f.display_value()
'<a target="_window" href="http://www.dsilabs.ca">www.dsilabs.ca</a>'
>>> f = URLField('Website', default='www.google.com')
>>> f.assign('https://www.dsilabs.ca/')
>>> f.display_value()
'<a target="_window" href="https://www.dsilabs.ca/">https://www.dsilabs.ca/</a>'
>>> f = URLField('Website', default='www.google.com', trim=True)
>>> f.assign('https://www.dsilabs.ca/')
>>> f.display_value()
'<a target="_window" href="https://www.dsilabs.ca">www.dsilabs.ca</a>'
assign(value)

assign a value to the field

display_value()

Display field value.

>>> name_field = Field('Name', default='default test')
>>> name_field.display_value()
'default test'
>>> name_field = Field('Name', value='test')
>>> name_field.display_value()
'test'
>>> name_field = Field('Name', value='こんにちは')
>>> name_field.display_value()
'こんにちは'
>>> name_field.visible = False
>>> name_field.display_value()
''
maxlength = 120
size = 60
trim = False
zoom.fields.args_to_dict(values=None, **kwargs)

convert args to a dict

Allows developers to pass field values to fields either as a dict or as a set of keyword arguments, whichever makes the most sense for their code.

This is currently only used for clean() but could potentially be used in a number of other places in this modudle where the same pattern shows up. Erring on the side of caution for now.

>>> args_to_dict()
{}
>>> args_to_dict({})
{}
>>> args_to_dict({'name': 'Pat'})
{'name': 'Pat'}
>>> from zoom.utils import pp
>>> pp(args_to_dict(**{'name': 'Pat', 'age': 10}))
{
  "age": 10,
  "name": "Pat"
}
>>> try:
...    args_to_dict({'name': 'Pat'}, 'bad value', age=10)
... except TypeError as e:
...    expected = 'args_to_dict() takes' in str(e)
>>> expected
True
zoom.fields.layout_field(label, content, edit=True)

Layout a field (usually as part of a form).

>>> print(
...     layout_field(
...         'Name',
...         '<input type=text value="John Doe">',
...         True
...     )
... )
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_edit"><input type=text value="John Doe"></div>
</div>
>>> print(layout_field('Name', 'John Doe', False))
<div class="field">
  <div class="field_label">Name</div>
  <div class="field_show">John Doe</div>
</div>
zoom.fields.locate_view(name)