Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
@view_config(renderer='templates/form.pt', name='sequence_of_radiochoices')
@demonstrate('Sequence of Radio Choice Widgets')
def sequence_of_radiochoices(self):
choices = (('habanero', 'Habanero'), ('jalapeno', 'Jalapeno'),
('chipotle', 'Chipotle'))
class Peppers(colander.SequenceSchema):
pepper = colander.SchemaNode(
colander.String(),
validator=colander.OneOf([x[0] for x in choices]),
widget=deform.widget.RadioChoiceWidget(values=choices),
title='Pepper Chooser',
description='Select a Pepper')
class Schema(colander.Schema):
peppers = Peppers()
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)
def sequence_of_sequences(self):
class NameAndTitle(colander.Schema):
name = colander.SchemaNode(colander.String())
title = colander.SchemaNode(colander.String())
class NamesAndTitles(colander.SequenceSchema):
name_and_title = NameAndTitle(title='Name and Title')
class NamesAndTitlesSequences(colander.SequenceSchema):
names_and_titles = NamesAndTitles(title='Names and Titles')
class Schema(colander.Schema):
names_and_titles_sequence = NamesAndTitlesSequences(
title='Sequence of Sequences of Names and Titles')
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
outer = form['names_and_titles_sequence']
outer.widget = deform.widget.SequenceWidget(min_len=1)
outer['names_and_titles'].widget = deform.widget.SequenceWidget(
min_len=1)
return self.render_form(form)
import colander
# Deform
from deform.i18n import _
from . import widget
default_widget_makers = {
colander.Mapping: widget.MappingWidget,
colander.Sequence: widget.SequenceWidget,
colander.String: widget.TextInputWidget,
colander.Integer: widget.TextInputWidget,
colander.Float: widget.TextInputWidget,
colander.Decimal: widget.TextInputWidget,
colander.Boolean: widget.CheckboxWidget,
colander.Date: widget.DateInputWidget,
colander.DateTime: widget.DateTimeInputWidget,
colander.Tuple: widget.TextInputCSVWidget,
colander.Time: widget.TimeInputWidget,
colander.Money: widget.MoneyInputWidget,
colander.Set: widget.CheckboxChoiceWidget,
}
@colander.deferred
def deferred_csrf_value(node, kw):
return kw["request"].session.get_csrf_token()
class FileData(object):
"""
@view_config(renderer='templates/form.pt', name='mapping')
@demonstrate('Mapping Widget')
def mapping(self):
class Mapping(colander.Schema):
name = colander.SchemaNode(
colander.String(),
description='Content name')
date = colander.SchemaNode(
colander.Date(),
widget=deform.widget.DatePartsWidget(),
description='Content date')
class Schema(colander.Schema):
number = colander.SchemaNode(
colander.Integer())
mapping = Mapping()
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)
self.autocomplete = autocomplete
field.Field.__init__(self, schema, **kw)
_buttons = []
for button in buttons:
if isinstance(button, compat.string_types):
button = Button(button)
_buttons.append(button)
self.action = action
self.method = method
self.buttons = _buttons
self.formid = formid
self.use_ajax = use_ajax
self.ajax_options = Markup(ajax_options.strip())
form_widget = getattr(schema, "widget", None)
if form_widget is None:
form_widget = widget.FormWidget()
self.widget = form_widget