def view_contactform(context, request): locale_name = get_locale_name(request) tmpstore = FileUploadTempStore(request) def file_size_limit(node, value): value['fp'].seek(0, 2) size = value['fp'].tell() value['fp'].seek(0) max_size = 10 if size > max_size * 1024 * 1024: msg = _('Maximum file size: ${size}MB', mapping={'size': max_size}) raise colander.Invalid(node, msg) def maybe_show_attachment(node, kw): if kw.get('maybe_show_attachment', True) is False: del node['attachment'] class SubmissionSchema(colander.MappingSchema): name = colander.SchemaNode(colander.String(), title=_("Full Name")) sender = colander.SchemaNode(colander.String(), validator=colander.Email(), title=_("E-Mail Address")) subject = colander.SchemaNode(colander.String(), title=_("Subject")) content = colander.SchemaNode(colander.String(), widget=TextAreaWidget(cols=40, rows=5), title=_("Your message")) attachment = colander.SchemaNode( FileData(), title=_('Attachment'), widget=FileUploadWidget(tmpstore), validator=file_size_limit, missing=None, ) _LOCALE_ = colander.SchemaNode(colander.String(), widget=HiddenWidget(), default=locale_name) schema = SubmissionSchema(after_bind=maybe_show_attachment) schema = schema.bind(maybe_show_attachment=context.show_attachment) form = Form(schema, buttons=[Button('submit', _('Submit'))]) appstruct = None rendered_form = None if 'submit' in request.POST: controls = request.POST.items() try: appstruct = form.validate(controls) mail_submission(context, request, appstruct) except ValidationFailure, e: appstruct = None rendered_form = e.render()
def schema_factory(self): tmpstore = FileUploadTempStore(self.request) class TableFileSchema(ContentSchema): file = colander.SchemaNode( deform.FileData(), title=_(u'File'), widget=deform.widget.FileUploadWidget(tmpstore), #validator=validate_file_size_limit, ) table_name = colander.SchemaNode( colander.String(), title=_(u"Table Name"), validator=validate_name, missing=None, ) return TableFileSchema()
def schema_factory(self): tmpstore = FileUploadTempStore(self.request) return FileSchema(tmpstore)
def schema_factory(self): tmpstore = FileUploadTempStore(self.request) return FileSchema(tmpstore, title_missing=null)
def make_one(self): from kotti.views.form import FileUploadTempStore return FileUploadTempStore(DummyRequest())
def schema_factory(self): # File uploads are stored in the session so that you don't need # to upload your file again if validation of another schema node # fails. tmpstore = FileUploadTempStore(self.request) return FileSchema(tmpstore)