Changeset 1428 in products
- Timestamp:
- Dec 6, 2009 10:06:45 AM (17 years ago)
- Location:
- quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier/quintagroup/transmogrifier
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier/quintagroup/transmogrifier/binary.py
r1389 r1428 9 9 10 10 from collective.transmogrifier.interfaces import ISection, ISectionBlueprint 11 from collective.transmogrifier.utils import defaultMatcher 11 from collective.transmogrifier.utils import defaultMatcher, Condition 12 12 13 13 class FileExporterSection(object): … … 24 24 #self.excludekey = defaultMatcher(options, 'exclude-key', name, 'excluded_fields') 25 25 self.excludekey = options.get('exclude-key', '_excluded_fields').strip() 26 26 27 self.exclude_fieldtypes = filter(None, [i.strip() for i in 28 options.get('exclude-fieldtypes', '').splitlines()]) 27 29 self.doc = minidom.Document() 30 self.condition = Condition(options.get('condition', 'python:True'), 31 transmogrifier, name, options) 28 32 29 33 def __iter__(self): … … 45 49 for field in schema.keys(): 46 50 if obj.isBinary(field): 51 binary_field_names.append(field) 52 if not self.condition(item, context=obj, fname=field): 53 continue 54 # ftype = schema[field].getType() 55 # if ftype in self.exclude_fieldtypes: 56 # print '################################ Skipped %s:%s:%s field extraction' % (path, field, ftype) 57 # continue 47 58 fname, ct, data = self.extractFile(obj, field) 48 binary_field_names.append(field)49 59 if data == '': 50 60 # empty file fields have no data and we skip them … … 141 151 self.contextkey = defaultMatcher(options, 'context-key', name, 'import_context') 142 152 153 self.condition = Condition(options.get('condition', 'python:True'), 154 transmogrifier, name, options) 155 143 156 def __iter__(self): 144 157 for item in self.previous: … … 169 182 if data is None: 170 183 continue 184 if not self.condition(item, context=obj, fname=field, 185 filename=fname, data=data, mimetype=ct): 186 continue 171 187 mutator = obj.getField(field).getMutator(obj) 172 188 mutator(data, filename=fname, mimetype=ct) -
quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier/quintagroup/transmogrifier/binary.txt
r1426 r1428 17 17 section. 18 18 19 Also this section provides condition option which, if specified, exports/imports 20 this or another binary field only if condition expression evaluates to true. 21 19 22 >>> import pprint 20 23 >>> binary = """ … … 32 35 ... [fileexporter] 33 36 ... blueprint = quintagroup.transmogrifier.fileexporter 37 ... condition = python:fname != 'image' 34 38 ... 35 39 ... [dataprinter] … … 74 78 75 79 TODO: write test for getting data for fields from import context 80 81 The ``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 =================== ========================================================== -
quintagroup.transmogrifier/branches/plone-2.1/quintagroup.transmogrifier/quintagroup/transmogrifier/tests.py
r1380 r1428 824 824 return 'binary data' 825 825 else: 826 return ' '826 return 'image' 827 827 828 828 def getMutator(self, obj):
Note: See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/trac/chrome/common/qtrac_logo.png)