collective / collective.exportimport

Export and import content and other data from and to Plone
GNU General Public License v2.0
15 stars 17 forks source link

language property exported with str and dict values #121

Open zopyx opened 2 years ago

zopyx commented 2 years ago

I have a Plone 5.2 AT site that exports most of the content with

 "language": "" 

and some content items as

    "language": {
        "title": "Deutsch",
        "token": "de"
    },

This leads to import errors such as

2022-04-18 14:24:26,230 WARNING [collective.exportimport.import_content:352][waitress-2] cannot deserialize http://nohost/eteaching/projekt/rechte/hochschulmitglieder-als-urheber: BadRequest([{'message': 'Constraint not satisfied', 'field': 'language', 'error': 'ValidationError'}])
mauritsvanrees commented 2 years ago

Is 'de' in the allowed languages of the new site?

petschki commented 2 years ago

In our current project, we have item language exported from Plone 4.3.20 as "language": "en" and if the target Plone Site doesn't allow en we get the deserialization error. otherwise it gets imported correctly.

mauritsvanrees commented 2 years ago

I have this in custom code, which fixes the problem for my case (export example content from English site, import it in Spanish site):

class CustomImportContent(ImportContent):
    def global_dict_hook(self, item):
        # When we export English content and import it in the Spanish site,
        # we must change the langue to Spanish, otherwise you get an error:
        # zExceptions.BadRequest: [{'message': 'Constraint not satisfied',
        # 'field': 'language', 'error': 'ValidationError'}]
        # BTW, the value is for example:
        # {'title': 'Nederlands', 'token': 'nl'}
        # Hey, wouldn't the easiest be to drop the key?  Seems to work fine.
        # Alternatively, use self.context.Language(), so a language is really set.
        # This might be better for multilingual sites.
        language = item.pop("language", None)
        if language is not None:
            logger.info("Popped language %s from item.", language)
        return item