Add better support for "make import batch from file" pattern

This commit is contained in:
Lance Edgar 2018-11-22 20:26:28 -06:00
parent 0375d66b91
commit 4fa9ab3c6e
6 changed files with 80 additions and 6 deletions

View file

@ -2,7 +2,7 @@
################################################################################
#
# Rattail -- Retail Software Framework
# Copyright © 2010-2017 Lance Edgar
# Copyright © 2010-2018 Lance Edgar
#
# This file is part of Rattail.
#
@ -28,4 +28,4 @@ from __future__ import unicode_literals, absolute_import
from . import types
from . import widgets
from .core import Form
from .core import Form, SimpleFileImport

View file

@ -881,3 +881,21 @@ class FieldList(list):
def insert_after(self, field, newfield):
i = self.index(field)
self.insert(i + 1, newfield)
@colander.deferred
def upload_widget(node, kw):
request = kw['request']
tmpstore = SessionFileUploadTempStore(request)
return dfwidget.FileUploadWidget(tmpstore)
class SimpleFileImport(colander.Schema):
"""
Schema for simple file import. Note that you must bind your ``request``
object to this schema, i.e.::
schema = SimpleFileImport().bind(request=request)
"""
filename = colander.SchemaNode(deform.FileData(),
widget=upload_widget)