Search:
 

'Publish' CMFObjects into a Folder

Submitted by: runyaga
Last Edited: 2001-07-03

Category: CMF

Average rating is: 3.0 out of 5 (1 ratings)

Description:
This allows for objects to be indepedant of their user directories. once something has been published you can move it to another folder. In this example I have modified Link objects so when they are published they are pushed to CMF/website/links folder.

CMFs Workflow module is very straight forward. This is a very minimal hack to the DefaultWorkflow.py that shows how to copy a object into another folder on Publish.

If this were for a production system, I would subclass DefaultWorkflow.py and override the needed methods.


Source (Text):
# create a Folder in your CMF root, named website and a subfolder in that called links

# you do have to edit somethings.  first set the destination
# /CMFDefault/skins/content/link.py

destination = 'website/links'

context.edit(remote_url=remote_url,
             destination=destination)

# then edit /CMFDefault/Link.py
    def edit( self, remote_url, destination=None ):
        """
            Edit the Link
        """
        self.remote_url=remote_url
        self.destination=destination

# now in DefaultWorkflow.py (or your subclass) I create a method called copyIntoWebsite

    security.declarePrivate('copyIntoWebsite')
    def copyIntoWebsite(self, ob):
        from string import split
        if hasattr(ob, 'destination') and getattr(ob, 'destination') != None:
            for elem in split(getattr(ob, 'destination'), '/'):
                self = getattr(self, elem)
            self._setObject(ob.getId(), ob)

# and inf your doActionFor method at the bottom 

            self.setReviewStateOf(ob, 'published', action, comment)
            self.copyIntoWebsite(ob)

Explanation:
CMFDefault/skins/content/link.py is where you set the destination variable
CMFDefault/Link.py is how you set the attribute on the object
CMFDefault/DefaultWorkflow.py is where the attribute is used to push it into destination folder

NOTE:

for elem in split(getattr(ob, 'destination'), '/'):

is a hack around the fact, I am getting very confused about the Correct Way (tm)
to traverse the ZODB. getattr() I know is ok. restrictedTraverse doestn act
like its expected and the URLTool doesnt do it (it returns an objects path) it doesnt
traverse the path for you (might be nice ;)


Comments:

No Comments