source: products/quintagroup.transmogrifier/trunk/quintagroup/transmogrifier/binary.txt @ 1454

Last change on this file since 1454 was 1446, checked in by piv, 14 years ago

merge from plone 2.1 branch: r2465-2483

File size: 3.3 KB
Line 
1File fields exporter and importer sections
2==========================================
3
4File fields importer and exporter sections are used to extract data from
5Archetypes file fields. The exporter section blueprint name is
6``quintagroup.transmogrifier.fileexporter`` and the importer section blueprint
7name is ``quintagroup.transmogrifier.fileimporter``.
8
9Exporter needs relative path to the object, that have file fields. Improter
10needs path and data for updating fields.
11
12Both sections has ``path-key`` option which specify key in item where path to
13object is stored (``_path`` is default) and ``files-key`` option that gives
14key where XML data will be or is stored. Exporter section also has ``exclude-key``
15option, that specifies key where list of file field names will be stored
16(default is ``_excluded_fields``). These list will be used in marshaller
17section.
18
19Also this section provides condition option which, if specified, exports/imports
20this or another binary field only if condition expression evaluates to true.
21
22>>> import pprint
23>>> binary = """
24... [transmogrifier]
25... pipeline =
26...     binarysource
27...     fileexporter
28...     fileimporter
29...     printer
30...     dataprinter
31...
32... [binarysource]
33... blueprint = quintagroup.transmogrifier.tests.binarysource
34...
35... [fileexporter]
36... blueprint = quintagroup.transmogrifier.fileexporter
37... condition = python:fname != 'image'
38...
39... [dataprinter]
40... blueprint = quintagroup.transmogrifier.tests.dataprinter
41... print =
42...     _files
43...     file-fields
44...     data
45...
46... [fileimporter]
47... blueprint = quintagroup.transmogrifier.fileimporter
48...
49... [printer]
50... blueprint = collective.transmogrifier.sections.tests.pprinter
51... """
52>>> registerConfig(u'quintagroup.transmogrifier.tests.marshall', binary)
53>>> transmogrifier(u'quintagroup.transmogrifier.tests.marshall') # doctest: +REPORT_NDIFF, +ELLIPSIS
54{}
55{'_path': 'not/existing/bar'}
56{'_path': 'spam/eggs/notatcontent'}
57{'_excluded_fields': ['image', 'file'],
58 '_files': {'archive.tar.gz': {'content_type': 'application/x-tar',
59                               'data': 'binary data',
60                               'name': 'archive.tar.gz'},
61            'file-fields': {'data': ...,
62                            'name': '.file-fields.xml'}},
63 '_path': 'spam/eggs/foo'}
64<?xml version="1.0" encoding="utf-8"?>
65<manifest>
66  <field name="file">
67    <filename>
68      archive.tar.gz
69    </filename>
70    <mimetype>
71      application/x-tar
72    </mimetype>
73  </field>
74</manifest>
75<BLANKLINE>
76>>> pprint.pprint(plone.updated)
77('archive.tar.gz', 'application/x-tar', 'binary data')
78
79TODO: write test for getting data for fields from import context
80
81The ``condition`` expression hass access to the following:
82
83=================== ==========================================================
84 ``item``            the current pipeline item
85 ``transmogrifier``  the transmogrifier
86 ``name``            the name of the splitter section
87 ``options``         the splitter options
88 ``modules``         sys.modules
89 ``context``         the current content object
90 ``fname``           the name of the field being processed
91 ``filename``        the file name binary field is loaded into (import only)
92 ``data``            data read from the file (import only)
93 ``mimetype``        data mimetype (import only)
94=================== ==========================================================
Note: See TracBrowser for help on using the repository browser.