ploneplone-3.x

Save objects to another instance in Plone 3.x


When creating an object (like News) programmatically in Plone 3.x is it possible save it to a folder in another instance?


Solution

  • Short answer: it is generally possible and you have various options depending on your setup.

    If I understood your question and your setup correctly, you have two Plone instances running in the same ZODB.

    Something like this:

    ipdb> self.context
    <Application at >
    ipdb> self.context.SiteA
    <PloneSite at /SiteA>
    ipdb> self.context.SiteB
    <PloneSite at /SiteB>
    

    If this is the case, you can copy or move the object in to the new site, as demonstrated by the following debug session:

    ipdb> cpdata = self.context.SiteA.manage_copyObjects(['front-page'])
    ipdb> self.context.SiteB.manage_pasteObjects(cpdata)
    [{'new_id': 'copy_of_front-page', 'id': 'front-page'}]
    ipdb> self.context.SiteB['copy_of_front-page'].Title()
    'Welcome to Plone'
    

    For example you can do the copy move operation adding an event subscriber.

    Of course you have to take care of the permissions settings. The example I pasted worked because I was using the user admin which is define in the acl_users folder of the zope application.

    But technically you can achieve this result by tweaking the security manager.

    If the two Plone sites are not in the same ZODB, do not worry :) There are solutions that will work also if one of the 2 sites (or both) are not running Plone.

    For example you can create on Site A a form that posts to the Site B. If you have SSO between the two sites it may be as trivial as changing the action attribute url from /SiteA/folder1/add_form to /SiteB/folder2/add_form.

    Another option is that when SiteA receives the form data, it crafts a request with the urllib and urllib2 to SiteB. In this case you wil miss the requests module (not available in Python2.4) a lot.