[Zope-CMF] Problems with CMF, SiteRoot, getIcon etc.. OR is there a way to set 'relative_to_portal'?

Steve Spicklemire steve@spvi.com
Sun, 25 Mar 2001 13:22:20 -0500 (EST)


This is kinda wierd... so I'm sure I'm not quite 'grok'ing something.

I wanted to check out the new CMF so I grabbed a fresh CVS export,
along with a fresh Zope2.3.X from CVS. I set up a portal in a directory
and also a SiteRoot. The problem is that 'getIcon' is returning
paths that don't work with 'portal_content'. I ended up with the 
following patch:

----------------------------------------------------------------------
diff -c -r1.4 DynamicType.py
*** DynamicType.py      2001/03/02 20:05:22     1.4
--- DynamicType.py      2001/03/25 18:05:49
***************
*** 145,151 ****
                  else:
                      # Need the full path to the icon.
                      portal_url = getPortal(self).absolute_url(relative=1)
!                     return portal_url + '/' + icon
          return 'misc_/OFSP/dtmldoc.gif'
  
      security.declarePublic('icon')
--- 145,155 ----
                  else:
                      # Need the full path to the icon.
                      portal_url = getPortal(self).absolute_url(relative=1)
!                     if portal_url:
!                         return portal_url + '/' + icon
!                     else:
!                         return icon
!                     
          return 'misc_/OFSP/dtmldoc.gif'
  
      security.declarePublic('icon')
----------------------------------------------------------------------

The how/why are below... 

The contentish interface says:

    def getIcon(self):
        """
        This method returns the path to an object's icon. It is used
        in the folder_contents view to generate an appropriate icon
        for the items found in the folder.

        If the content item does not define an attribute named "icon"
        this method will return the path "/misc_/dtmldoc.gif", which is
        the icon used for DTML Documents.
        """

The implementation in Dynamic.py does this:

    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.
        """
        ti = self.getTypeInfo()
        if ti is not None:
            icon = quote(ti.getIcon())
            if icon:
                if relative_to_portal:
                    return icon
                else:
                    # Need the full path to the icon.
                    portal_url = getPortal(self).absolute_url(relative=1)
                    return portal_url + '/' + icon
        return 'misc_/OFSP/dtmldoc.gif'

There is no mention of relative_to_portal (the behavior that
I think is needed when using a SiteRoot) in the interface
document, nor can I find it referenced in any mail messages
to the list, or in any doc files in the cmf distribution.
It is used in two getIcon methods though.. Soo... the problem is
that when using a SiteRoot portal_url comes back as ''. Then
you get "return '' + '/' + icon, which when coupled with code
like: 

      <td>
         <dtml-if icon>
         <a href="&dtml.url_quote-id;&dtml-methodID;"
          ><img src="&dtml-BASEPATH1;/&dtml-icon;"
                alt="&dtml-Type;" border="0"></a> 
         </dtml-if>
      </td>

from CMFDefault/skins/generic/folder_contents.dtml you end up with:

      <td>
                  <a href="index_html/view"
          ><img src="//document_icon.gif"
                alt="Document" border="0"></a> 
         <br>/document_icon.gif
      </td>

which obviously doesn't work. ;-)   So... either I need the patch,
or I need a way to set 'relative_to_portal'. What are other folks
doing here?

thanks,
-steve