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_create_add_upload_widget_if_request(self, inst, request_):
from deform.widget import FileUploadWidget
inst = inst.bind(request=request_)
assert isinstance(inst.widget, FileUploadWidget)
"""
req = kw['request']
choices = csv_file_columns(req)
return deform.widget.SelectWidget(
values=choices,
multiple=True
)
class UploadSchema(Schema):
# title = SchemaNode(String())
upload = SchemaNode(
deform.FileData(),
widget=deform.widget.FileUploadWidget(tmpstore)
)
class TopicExtractionSchema(Schema):
topics = SchemaNode(
Int(),
default=10,
title="Number of topics to extract"
)
num_docs = SchemaNode(
Int(),
default=100,
title="Max number of documents to process"
)
ngrams = SchemaNode(
Int(),
def image_upload_widget(node, kw):
request = kw['request']
tmpstore = ImageUploadTempStore(request)
widget = deform.widget.FileUploadWidget(tmpstore)
widget.template = 'image_upload'
return widget
@view_config(renderer='templates/form.pt', name='sequence_of_fileuploads')
@demonstrate('Sequence of File Upload Widgets')
def sequence_of_fileuploads(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',))
return self.render_form(form, success=tmpstore.clear)
def file_upload_widget(node, kw):
if kw.get('loading'):
return None
request = kw['request']
tmpstore = FileUploadTempStore(request)
widget = deform.widget.FileUploadWidget(tmpstore)
widget.template = 'substanced.file:templates/fileupload.pt'
return widget
def form_view(request):
# Create a schema; when the form is submitted, we want to assert
# that the name must match the title; we use a validator for the
# entire form by assigning it a validator
schema = MySchema(validator=validate_form)
# Create a form; it will have a single button named submit.
myform = form.Form(schema, buttons=('submit',))
# Associate widgets with fields in the form
myform['password'].widget = widget.CheckedPasswordWidget()
myform['title'].widget = widget.TextInputWidget(size=40)
myform['color'].widget = widget.RadioChoiceWidget(
values=(('red', 'Red'),('green', 'Green'),('blue', 'Blue')))
myform['uploads']['file'].widget = widget.FileUploadWidget(memory)
# Handle the request
if 'submit' in request.POST:
# This was a form submission
fields = request.POST.items()
try:
converted = myform.validate(fields)
except exception.ValidationFailure, e:
# Validation failed
return {'form':e.render()}
# Validation succeeded
return {'form':pprint.pformat(converted)}
# This was not a form submission; render the form "normally".
appstruct = {'name':'Fred',
'series':{'name':'series 1',
@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)
def FileSchema(tmpstore, title_missing=None):
class FileSchema(ContentSchema):
file = SchemaNode(
FileData(),
title=_("File"),
widget=FileUploadWidget(tmpstore),
validator=validate_file_size_limit,
)
# noinspection PyUnusedLocal
def set_title_missing(node, kw):
if title_missing is not None:
node["title"].missing = title_missing
return FileSchema(after_bind=set_title_missing)