'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)

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 that shows how to copy a object into another folder on Publish.

If this were for a production system, I would subclass 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/

destination = 'website/links'


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

# now in (or your subclass) I create a method called 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)

CMFDefault/skins/content/ is where you set the destination variable
CMFDefault/ is how you set the attribute on the object
CMFDefault/ is where the attribute is used to push it into destination folder


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 ;)


No Comments