[Zope-CMF] Icons for publishing state

Jeffrey P Shell jeffrey@cuemedia.com
Tue, 23 Apr 2002 11:26:05 -0600


On 4/23/02 4:28 AM, "Duncan Booth" <duncan@rcp.co.uk> wrote:

> I would like to modify the CMF folder view to indicate the publishing state of
> each item. Does anyone have any icons to indicate private/pending/published
> state? Or any suggestions how best to convey those states pictographically?

I had something like this for an (unfinished) Project/Task management system
I was working on using the CMF.  The following code is from the Task content
type.  There were a four state classifications with icons mapped to them -
'new', 'inner', 'done', and 'cancelled', which mapped to icons like
'task_icon_new.gif', etc.

There are some other ways to do this that I never got around to, like moving
some of this code into the Workflow Agent definition, or into the workflow
tool itself.  But the following works:

    security.declarePublic('getIcon')
    def getIcon(self, relative_to_portal=0):
        """ 
        Using this method allows the content class
        creator to grab icons on the fly instead of using a fixed
        attribute on the class.
        """ 
        wf = getToolByName(self, 'portal_workflow')
        status = wf.getInfoFor(self, 'task_status', None)
        ti = self.getTypeInfo()
        icon = 'task_icon_new.gif'    # Default icon
 
        if status: 
            ## These categories map actual states (the values) to
            ## a group classification to determine the icon
            iconbits = {
                'new' : ('New (Unassigned)', 'Pending'),
                'inner': ('In Progress', 'Halted', 'Testing'),
                'done': ('Done',),
                'cancelled': ('Denied', 'Cancelled'),
                } 
            for grouping, states in iconbits.items():
                if status in states:
                    icon = 'task_icon_%s.gif' % grouping
                    break

        elif (status is None) and (ti is not None):
            ## There was no status reported, ask the TypeInformation object
            ## for this instance for an icon.
            icon = ti.getIcon()

        if icon: 
            if relative_to_portal:
                return icon
            else: 
                # Relative to REQUEST['BASEPATH1']
                portal_url = getToolByName(self, 'portal_url')
                res = portal_url(relative=1) + '/' + icon
                while res[:1] == '/':
                    res = res[1:]
                return res
 
    security.declarePublic('icon')
    icon = getIcon  # For the ZMI

-- 
Jeffrey P Shell 
www.cuemedia.com