portlet reference from hash code

Nicola Senno biancosteso at yahoo.it
Sat Oct 6 18:16:54 UTC 2007


Hi mates

sorry for the delay in replying but I had to put this project on hold for  a
while...
At the moment there isn't any existing tool kit available I can use and I
kind had to start from scratch.

The solution that I've been working on so far is the following:

first I'm creating a list of empty objects

portlets= { 'login'                : login.Assignment(),
            'news'                 : news.Assignment(count=5),
            'events'               : events.Assignment(count=5),
            'navigation'           : navigation.Assignment(),
            'calendar'             : calendar.Assignment(),
            'review'               : review.Assignment(),
            'recent'               : recent.Assignment(count=5),
            }

then I query the portlet-manager using the portlethash obtained from kss as
shown below to retrive the name of the portlet actually instantiated by
portal. At this point I can match the right object in portlets list
(objPortlet = portlets.get(item, None)) and use it to call the adapter
(portlet = IDynamicMenu(objPortlet)).


class DragSupport(PloneKSSView):

    """send a reply to browser via kss """
    def getReply(self, urlObject = None,  urlDest = None,  portlethash =
None):
    ...
	if portlethash is not None:
		info = unhashPortletInfo(portlethash)
		for item in portlets:
			if item == info['name']:
				objPortlet = portlets.get(item, None)
				break
		portlet = IDynamicMenu(objPortlet)



So far so good

Now when I run these pieces of code and the class  
http://www.nabble.com/file/p13076197/navigationMenu.py navigationMenu.py 
instantiates an object the following errors are posted:

Traceback (innermost last):
  Module ZPublisher.Publish, line 119, in publish
  Module ZPublisher.mapply, line 88, in mapply
  Module ZPublisher.Publish, line 42, in call_object
  Module Products.kssdnd.browser.dragSupport, line 54, in getReply
  Module Products.kssdnd.browser.navigationMenu, line 73, in getMenu
  Module Products.kssdnd.browser.navigationMenu, line 60, in getObject
  Module Products.kssdnd.browser.navigationMenu, line 47, in getObjectRef
  Module Products.CMFCore.utils, line 123, in getToolByName
AttributeError: portal_catalog

My best guess is that the object is created whithout context, although I
can't undesrtand why this is happening. Is it because the objects in list
portlets are empty?

any help will be very much appreciated. 

Nicola


Martin Aspeli wrote:
> 
> Hi Nicola,
> 
>> I'm now developing a little tool using plone 3 and kss, something like
>> "drag
>> and drop" behavour.
> 
> Cool - I'm interested in that. Which toolkit are you using?
> 
> 
>> I need to obtain a portlet reference by its hash code.
> 
> <snip code />
> 
>> How to obtain this portlet reference? Varius portlet must have different
>> menu ;)
> 
> Are you asking how to get a portlet hash, or how to turn a portlet hash 
> into an actual portlet?
> 
> If you have a hash, you can get a portlet info dict from 
> plone.portlets.utils.unhashPortletInfo()
> 
> With this info, you can call 
> plone.app.portlets.utils.assignment_from_key() which returns an 
> IPortletAssignment.
> 
> Look at plone.app.portlets.browser.kss to see how it's used. If you need 
> to render the assignment, multi-adapt assignment.data to IPortletRenderer.
> 
> The hashes themselves are stored in the page template. You can use a 
> kssAttr() type attribute to find them and send them to the server-side 
> action.
> 
> Martin
> 
> 
> -- 
> Acquisition is a jealous mistress
> 
> 
> _______________________________________________
> Product-Developers mailing list
> Product-Developers at lists.plone.org
> http://lists.plone.org/mailman/listinfo/product-developers
> 
> 

-- 
View this message in context: http://www.nabble.com/portlet-reference-from-hash-code-tf4269138s20094.html#a13076197
Sent from the Product Developers mailing list archive at Nabble.com.





More information about the Product-Developers mailing list