Ignore:
Timestamp:
9 Jun 2011, 22:49:24 (14 years ago)
Author:
uli
Message:

Remove IFileRetrieval-based parts of test. We do not support
IFileRetrieval currently.

Update docs a bit.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/image/README.txt

    r6066 r6310  
    1 waeup.sirp.image fields
    2 =======================
     1waeup.sirp.image -- handling image files
     2========================================
    33
    4 The image file widget is built on top of the ImageFile object::
     4The image file widget is built on top of the :class:`WAeUPImageFile` object::
    55
    66  >>> from waeup.sirp.image import WAeUPImageFile
     
    3434
    3535The WAeUPImageFile object normally stores the file data using ZODB
    36 persistence. Files can however also be stored by tramline.  If
    37 tramline is installed in Apache, the Tramline takes care of generating
    38 ids for files and storing the file on the filesystem directly. The ids
    39 are then passed as file data to be stored in the ZODB.
    40 
    41 Let's first enable tramline.
    42 
    43 The tramline directory structure is a directory with two subdirectories,
    44 one called 'repository' and the other called 'upload'::
    45 
    46   >>> import tempfile, os
    47   >>> dirpath = tempfile.mkdtemp()
    48   >>> repositorypath = os.path.join(dirpath, 'repository')
    49   >>> uploadpath = os.path.join(dirpath, 'upload')
    50   >>> os.mkdir(repositorypath)
    51   >>> os.mkdir(uploadpath)
    52 
    53 We create a TramlineFileRetrieval object knowing about this directory,
    54 and register it as a utility::
    55 
    56   >>> from hurry.file.file import TramlineFileRetrievalBase
    57   >>> class TramlineFileRetrieval(TramlineFileRetrievalBase):
    58   ...    def getTramlinePath(self):
    59   ...        return dirpath
    60   >>> retrieval = TramlineFileRetrieval()
    61   >>> component.provideUtility(retrieval, IFileRetrieval)
    62 
    63 Now let's store a file the way tramline would during upload::
    64 
    65   >>> f = open(os.path.join(repositorypath, '1'), 'wb')
    66   >>> f.write('test data')
    67   >>> f.close()
    68 
    69 The file with underlying name '1' (the data stored in the ZODB will be
    70 just '1') will now be created::
    71 
    72   >>> file = WAeUPImageFile('foo.jpg', '1')
    73 
    74 The data is now '1', referring to the real file::
    75 
    76   >>> file.data
    77   '1'
    78 
    79 Retrieving the file results in the real file::
    80  
    81   >>> f = file.file
    82   >>> f.read()
    83   'test data'
    84 
    85 We can also retrieve its size::
    86 
    87   >>> file.size
    88   9L
    89 
    90 Now let's disable tramline in our utility::
    91 
    92   >>> class TramlineFileRetrieval(TramlineFileRetrievalBase):
    93   ...     def getTramlinePath(self):
    94   ...        return dirpath
    95   ...     def isTramlineEnabled(self):
    96   ...        return False
    97   >>> component.provideUtility(TramlineFileRetrieval(), IFileRetrieval)
    98 
    99 We expect the same behavior as when tramline is not installed::
    100 
    101   >>> file = WAeUPImageFile('foo.jpg', 'data')
    102   >>> f = file.file
    103   >>> f.read()
    104   'data'
    105   >>> file.size
    106   4
    107 
     36persistence. For better efficiency, each file is stored in a Blob.
    10837`ImageFile` field
    10938-----------------
     
    14776But we can set them:
    14877
    149   >>> field = ImageFile(__name__='bar', title=u'Bar', 
     78  >>> field = ImageFile(__name__='bar', title=u'Bar',
    15079  ...                   min_size=5, max_size=12)
    15180
     
    174103  TooSmall: ('bar.jpg', '4 bytes (min: 5 bytes)')
    175104
    176 
    177 Clean up::
    178 
    179   >>> import shutil
    180   >>> shutil.rmtree(dirpath)
Note: See TracChangeset for help on using the changeset viewer.