Back to index

plone3  3.1.7
utils.py
Go to the documentation of this file.
00001 from zope.component import getSiteManager
00002 from zope.interface import Interface
00003 from plone.portlets.interfaces import IPortletType
00004 from plone.portlets.registration import PortletType
00005 import binascii
00006 
00007 def registerPortletType(site, title, description, addview, for_=[Interface]):
00008     """Register a new type of portlet.
00009     
00010     site should be the local site where the registration should be made. The 
00011     title and description should be meaningful metadata about the portlet for 
00012     the UI.
00013     
00014     The addview should be the name of an add view registered, and must be 
00015     unique.
00016     """
00017     sm = getSiteManager(site)
00018     
00019     portlet = PortletType()
00020     portlet.title = title
00021     portlet.description = description
00022     portlet.addview = addview
00023     portlet.for_ = for_
00024     
00025     sm.registerUtility(component=portlet, provided=IPortletType, name=addview)
00026     
00027 def unregisterPortletType(site, addview):
00028     """Unregister a portlet type.
00029     
00030     site is the local site where the registration was made. The addview 
00031     should is used to uniquely identify the portlet.
00032     """
00033     
00034     sm = getSiteManager(site)
00035     sm.unregisterUtility(provided=IPortletType, name=addview)
00036 
00037 def hashPortletInfo(info):
00038     """Creates a hash from the portlet information.
00039 
00040     This is a bidirectional function. The hash must only contain characters
00041     acceptable as part of a html id.
00042 
00043     info is the portlet info dictionary. Hash is put into info, and
00044     also returned.
00045     """
00046     concat_txt = '%(manager)s\n%(category)s\n%(key)s\n%(name)s' % info
00047     info['hash'] = binascii.b2a_hex(concat_txt)
00048     return info['hash']
00049 
00050 def unhashPortletInfo(hash):
00051     """Creates the portlet info from the hash.
00052 
00053     Output is the info dictionary (containing only the 
00054     hashed fields).
00055     """
00056     concat_txt = binascii.a2b_hex(hash)
00057     manager, category, key, name = concat_txt.splitlines()
00058     info = dict(manager=manager, category=category, key=key, name=name, hash=hash)
00059     return info