def marshall(ob):
    types_tool = api.portal.get_tool('portal_types')
    fti = types_tool.get(ob.portal_type)
    # noinspection PyUnresolvedReferences
    if HAS_DEXTERITY and IDexterityFTI.providedBy(fti):
        # DX
        message = constructMessageFromSchemata(ob, iterSchemata(ob))
    elif HAS_ARCHETYPES and hasattr(Acquisition.aq_base(ob), 'schema'):
        # AT
        message = constructMessage(ob, iterFields(ob))
    else:
        # Other
        schemata = tuple(ob.__provides__.interfaces())
        message = constructMessageFromSchemata(ob, schemata)
    return message
Esempio n. 2
0
    def _getMessage(self):
        # Construct message on demand.
        message = constructMessageFromSchemata(self.context,
                                               iterSchemata(self.context))

        # Store the portal type in a header, to allow it to be identifed later
        message['Portal-Type'] = self.context.portal_type

        return message
 def _getMessage(self):
     """Construct message on demand
     """
     message = constructMessageFromSchemata(self.context, iterSchemata(self.context))
     
     # Store the portal type in a header, to allow it to be identifed later
     message['Portal-Type'] = self.context.portal_type
     
     return message
def marshall(obj):
    # noinspection PyUnresolvedReferences
    if HAS_DEXTERITY and IDexterityContent.providedBy(obj):
        # DX
        message = constructMessageFromSchemata(obj, iterSchemata(obj))
        # Ensure that all DC fields are included
        dc = constructMessageFromSchemata(DublinCore(obj), [IDublinCore])
        for name in [key for key in dc.keys() if not message[key]]:
            if name in message.keys():
                del message[name]
            message[name] = dc[name]
    elif HAS_ARCHETYPES and hasattr(Acquisition.aq_base(obj), 'schema'):
        # AT
        message = constructMessage(obj, iterFields(obj))
    else:
        # Other
        schemata = tuple(obj.__provides__.interfaces())
        message = constructMessageFromSchemata(obj, schemata)
    return message
Esempio n. 5
0
    def create_translation(self, *args, **kwargs):
        """Create translation for an object with uid in the given
        target_language and return its UID

        Usage::

            Create translation  /plone/en/foo  ca  title=Translated
        """
        disableCSRFProtection()
        # Parse arguments:
        uid_or_path = args[0]
        target_language = args[1]

        # BBB: Support keywords arguments with robotframework < 2.8.3
        kwargs.update(dict([arg.split('=', 1) for arg in args[2:]]))

        # Look up translatable content
        pc = getToolByName(self, "portal_catalog")
        uid_results = pc.unrestrictedSearchResults(UID=uid_or_path)
        path_results = pc.unrestrictedSearchResults(
            path={
                'query': uid_or_path.rstrip('/'),
                'depth': 0
            })
        obj = (uid_results or path_results)[0]._unrestrictedGetObject()

        # Translate
        manager = ITranslationManager(obj)
        manager.add_translation(target_language)
        translation = manager.get_translation(target_language)

        # Update fields
        data = constructMessageFromSchemata(obj, iterSchemata(obj))
        for key, value in kwargs.items():
            del data[key]
            data[key] = Header(value, 'utf-8')
        del data['language']
        initializeObjectFromSchemata(translation, iterSchemata(obj), data)
        notify(ObjectModifiedEvent(translation))

        # Return uid for the translation
        return IUUID(translation)
    def create_translation(self, *args, **kwargs):
        """Create translation for an object with uid in the given
        target_language and return its UID

        Usage::

            Create translation  /plone/en/foo  ca  title=Translated
        """
        disableCSRFProtection()
        # Parse arguments:
        uid_or_path = args[0]
        target_language = args[1]

        # BBB: Support keywords arguments with robotframework < 2.8.3
        kwargs.update(dict([arg.split('=', 1) for arg in args[2:]]))

        # Look up translatable content
        pc = getToolByName(self, "portal_catalog")
        uid_results = pc.unrestrictedSearchResults(UID=uid_or_path)
        path_results = pc.unrestrictedSearchResults(
            path={'query': uid_or_path.rstrip('/'), 'depth': 0})
        obj = (uid_results or path_results)[0]._unrestrictedGetObject()

        # Translate
        manager = ITranslationManager(obj)
        manager.add_translation(target_language)
        translation = manager.get_translation(target_language)

        # Update fields
        data = constructMessageFromSchemata(obj, iterSchemata(obj))
        for key, value in kwargs.items():
            del data[key]
            data[key] = Header(value, 'utf-8')
        del data['language']
        initializeObjectFromSchemata(translation, iterSchemata(obj), data)
        notify(ObjectModifiedEvent(translation))

        # Return uid for the translation
        return IUUID(translation)