Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_sequence_wiget_is_set(self):
from deform.widget import SequenceWidget
inst = self.make_one()
assert isinstance(inst.widget, SequenceWidget)
@view_config(renderer='templates/form.pt', name='sequence_of_constrained_len')
@demonstrate('Sequence of Constrained Min and Max Lengths')
def sequence_of_constrained_len(self):
class Names(colander.SequenceSchema):
name = colander.SchemaNode(colander.String())
class Schema(colander.Schema):
names = Names(
validator = colander.Length(2, 4),
title = 'At Least 2 At Most 4 Names',
widget=deform.widget.SequenceWidget(
min_len=2,
max_len=4)
)
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
return self.render_form(form)
colander.String(),
title=_('Description'),
description=_('Optional group description'),
validator=colander.Length(max=GROUP_DESCRIPTION_MAX_LENGTH),
widget=TextAreaWidget(rows=3, max_length=GROUP_DESCRIPTION_MAX_LENGTH),
missing=None
)
origins = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(colander.String(),
name='origin',
validator=colander.url),
title=_('Scope Origins'),
hint=_('Origins where this group appears (e.g. "https://example.com")'),
widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1),
validator=colander.Length(min=1, min_err=_('At least one origin must be specified'))
)
members = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(colander.String(),
name='member',
validator=member_exists_validator),
title=_('Members'),
hint=_('Add more members by their username to this group'),
widget=SequenceWidget(add_subitem_text_template=_('Add member')),
missing=None
)
document = registry.content.create('Document', **appstruct)
document.__creator__ = oid_of(self.request.user)
self.context[name] = document
return HTTPFound(
self.request.mgmt_path(self.context, '@@contents'))
class Person(colander.Schema):
name = colander.SchemaNode(colander.String())
age = colander.SchemaNode(colander.Integer(),
validator=colander.Range(0,200))
class People(colander.SequenceSchema):
person = Person()
class Schema(colander.Schema):
people = People(
widget=deform.widget.SequenceWidget(orderable=True)
)
@mgmt_view(
context=IFolder,
name='paulie',
tab_title='Add Document',
permission='sdi.add-content',
renderer='substanced.sdi:templates/form.pt',
tab_condition=False,
)
class PaulieView(FormView):
title = 'Paulie Form'
schema = Schema()
buttons = ('add',)
#from substanced.sdi import LEFT, RIGHT
name='origin',
validator=colander.url),
title=_('Scope Origins'),
hint=_('Origins where this group appears (e.g. "https://example.com")'),
widget=SequenceWidget(add_subitem_text_template=_('Add origin'), min_len=1),
validator=colander.Length(min=1, min_err=_('At least one origin must be specified'))
)
members = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(colander.String(),
name='member',
validator=member_exists_validator),
title=_('Members'),
hint=_('Add more members by their username to this group'),
widget=SequenceWidget(add_subitem_text_template=_('Add member')),
missing=None
)
@view_config(renderer='templates/form.pt',
name='sequence_of_fileuploads_with_initial_item')
@demonstrate('Sequence of File Upload Widgets (With Initial Item)')
def sequence_of_fileuploads_with_initial_item(self):
class Sequence(colander.SequenceSchema):
upload = colander.SchemaNode(
deform.FileData(),
widget=deform.widget.FileUploadWidget(tmpstore)
)
class Schema(colander.Schema):
uploads = Sequence()
schema = Schema()
form = deform.Form(schema, buttons=('submit',))
form['uploads'].widget = deform.widget.SequenceWidget(min_len=1)
return self.render_form(form, success=tmpstore.clear)
),
widget=CheckboxWidget(css_class="form-checkbox--inline"),
missing=False,
)
scopes = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(
colander.String(), name="scope", validator=url_with_origin_validator
),
title=_("Scopes"),
hint=_(
"Define where this group appears. A document's URL must start with one or more"
" of the entered scope strings (e.g. 'http://www.example.com')"
),
widget=SequenceWidget(add_subitem_text_template=_("Add scope"), min_len=1),
validator=colander.Length(
min=1, min_err=_("At least one scope must be specified")
),
)
members = colander.SequenceSchema(
colander.Sequence(),
colander.SchemaNode(
colander.String(), name="member", validator=member_exists_validator
),
title=_("Members"),
hint=_("Add more members by their username to this group"),
widget=SequenceWidget(add_subitem_text_template=_("Add member")),
missing=None,
)
"""Schema."""
# Pyramid
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):