[Zope-CMF] Proposition: Favourite with absolute url AND the query - any idea

Yuppie schubbe@web.de
Tue, 06 Aug 2002 18:30:51 +0200


Tres Seaver wrote:
> On Tue, 2002-08-06 at 08:07, Yuppie wrote:
>>1.) There's an inconsistency: invokeFactory/addFavorite needs a path 
>>without query string as remote_url. But edit() allows you to use an url 
>>with query string in remote_url.
>>
>>2.) getObject() and getIcon() might not give you the result you expect:
>>getObject() gives you an ugly Traceback and getIcon() returns 'p_/broken'.
> 
> 
> Right;  the favorite needs the 'remote_url' to work as a path reference
> to the object.  To accomodate this idea, we would need to capture the
> query string separately from the object URL.  Perhaps we could store the
> individual name/value pairs in a structure (e.g., a PersistentMapping)
> which would allow users to add / remove / edit individual pairs?

Proposal for a small solution:

1.) Using _edit code in addFavorite.

2.) def getIcon(self, relative_to_portal=0):
         obj = self.getObject()
         if obj:
             return obj.getIcon(relative_to_portal)
         else:
             return 'p_/broken'

     def getObject(self):
         try:
             portal_url = getToolByName(self, 'portal_url')
             portal_obj = portal_url.getPortalObject()
             tokens = urlparse.urlparse( self.remote_url )
             # I'm not sure if this returns always the right object
             return portal_obj.restrictedTraverse(tokens[2])
         except:
             return ''

3.) Adjusting addtoFavorites script.

Yuppie