File and image fields support on transmogrify.dexterity

Does anybody here know if transmogrify.dexterity supports file and image fields?

Package documentation says it doesn't but I want to be sure.

I was trying to import a WordPress site using transmogrify.wordpress: it's working with default Archetypes-based content types, and it's failing using plone.app.contenttypes.

Hector!

I've not use transmogrify.wordpress, but I'm sure it is possible - but you have to get the data in your pipeline dictionary "just so", to give you an idea, something like this worked for me a few years back:

# Set image data in external video (or anything with an image field)
[image-data]
blueprint = collective.transmogrifier.sections.inserter
key = string:image
value = python: {"data": modules['base64'].b64decode(item['_datafield_image']['data']),
                 "contenttype": item['_datafield_image']['content_type'],
                 "filename": item['_datafield_image']['filename']}
condition = python:item['_type']=='jowent.externalvideos.externalvideo'
#condition = python:item.has_key('_datafield_image')

# Set up picture image data in biography
[picture-data]
blueprint = collective.transmogrifier.sections.inserter
key = string:picture
value = python: {"data": modules['base64'].b64decode(item['_datafield_picture']['data']),
                 "contenttype": item['_datafield_picture']['content_type'],
                 "filename": item['_datafield_picture']['filename']}
condition = python:item.has_key('_datafield_picture')

# Apply all fields (including Blob ones setup above) to Dexterity objects (i.e. our inhouse content-types)
[dexterity-schemaupdater]
blueprint = transmogrify.dexterity.schemaupdater
1 Like

This PR is working locally with images https://github.com/collective/transmogrify.dexterity/pull/28/files

I'm waiting for some exception with other type of files or if everything is imported fine.

mmm, trying to decode your inserter seem that an image field in Dexterity's case needs to be feed with a dictionary with the following keys:

  • data: is the image data itself as a string
  • contenttype: the MIME type of the image
  • filename: the file name

I guess in the case of a file is the same but the field name must be file.

thanks! that was useful and reminds me why I hate the API inconsistencies among Archetypes and Dexterity.

@rodfersou your PR seems needless we need to get rid of the mimeencapsulator section in the transmogrifier and replace it with something that feeds the generator according what @djowett discovered.

also, we need to fix the documentation in transmogrify.dexterity.

I think you've got it. Sorry I don't have time to check thoroughly, but I know I got it working several times.

I'm glad dexterity moved on from Archetypes & yes I'd stay off changing t.dexterity unless you really need to.

Without any knowledge of trransmogrify, I still wonder:

Why can't one just download the file/image from wordpress and use alone.api.create to create the image ? (this is very straightforward with images on the file system)

some years ago we wrote a CSV importer from WordPress to Plone that helped us migrate the site of a customer at the time. I'm trying to reuse the same thing because we are migrating another WordPress site.

I was reading about other options yesterday and I found this one pretty interesting:

WordPress can export JSON OOTB and we can then write a script to push that into Plone; that sounds nice, the problem is we have no time for that right now

I was trying to save resources when I stumbled with the lack of documentation in transmogrify.dexterity and the difference on how things work with our default content types.

transmogrifier is a little bit crazy but works fine when you handle to understand and master it.

our pipeline, for instance, does many things as resolving to UUID on text fields linking to internal content, add related items, insert YouTube embedding code, and so on.