Class
zope.app.file.browser.file.FileAdd

View that adds a new File object based on a file upload.

>>> class FauxAdding(object):
...     def add(self, content):
...         self.content = content
...     def nextURL(self):
...         return 'next url'
>>> from zope.publisher.browser import TestRequest
>>> import StringIO
>>> sio = StringIO.StringIO("some data")
>>> sio.filename = 'abc.txt'

Let's make sure we can use the uploaded file name if one isn't specified by the user, and can use the content type when specified.

>>> request = TestRequest(form={'field.data': sio,
...                             'field.contentType': 'text/foobar',
...                             'UPDATE_SUBMIT': 'Add'})
>>> adding = FauxAdding()
>>> view = FileAdd(adding, request)
>>> view.errors()
''
>>> adding.content.contentType
'text/foobar'
>>> adding.content.data
'some data'
>>> request.form['add_input_name']
'abc.txt'

Now let's guess the content type, but also use a provided file name for adding the new content object:

>>> request = TestRequest(form={'field.data': sio,
...                             'field.contentType': '',
...                             'add_input_name': 'splat.txt',
...                             'UPDATE_SUBMIT': 'Add'})
>>> adding = FauxAdding()
>>> view = FileAdd(adding, request)
>>> view.errors()
''
>>> adding.content.contentType
'text/plain'
>>> request.form['add_input_name']
'splat.txt'

Base classes

Implemented Interfaces

There are no implemented interfaces.

Attributes/Properties

There are no attributes in this class.

Methods

Known Subclasses

There are no known subclasses.