Back to index

plone3  3.1.7
kss.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 from zope.component import getUtility, getMultiAdapter
00003 
00004 from Acquisition import aq_inner
00005 
00006 from plone.app.kss.interfaces import IPloneKSSView
00007 from plone.app.kss.plonekssview import PloneKSSView as base
00008 
00009 from plone.portlets.interfaces import IPortletManager
00010 from plone.portlets.interfaces import IPortletManagerRenderer
00011 
00012 from plone.portlets.utils import unhashPortletInfo
00013 from plone.app.portlets.utils import assignment_mapping_from_key
00014 
00015 from plone.app.portlets.interfaces import IPortletPermissionChecker
00016 
00017 class PortletManagerKSS(base):
00018     """Opertions on portlets done using KSS
00019     """
00020     implements(IPloneKSSView)
00021     
00022     def move_portlet_up(self, portlethash, viewname):
00023         info = unhashPortletInfo(portlethash)
00024         assignments = assignment_mapping_from_key(self.context, 
00025                         info['manager'], info['category'], info['key'])
00026         
00027         IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
00028         
00029         keys = list(assignments.keys())
00030         name = info['name']
00031         idx = keys.index(name)
00032         del keys[idx]
00033         keys.insert(idx-1, name)
00034         assignments.updateOrder(keys)
00035         
00036         return self._render_column(info, viewname)
00037         
00038         
00039     def move_portlet_down(self, portlethash, viewname):
00040         info = unhashPortletInfo(portlethash)
00041         assignments = assignment_mapping_from_key(self.context, 
00042                         info['manager'], info['category'], info['key'])
00043         
00044         IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
00045         
00046         keys = list(assignments.keys())
00047         name = info['name']
00048         idx = keys.index(name)
00049         del keys[idx]
00050         keys.insert(idx+1, name)
00051         assignments.updateOrder(keys)
00052         
00053         return self._render_column(info, viewname)
00054         
00055     def delete_portlet(self, portlethash, viewname):
00056         info = unhashPortletInfo(portlethash)
00057         assignments = assignment_mapping_from_key(self.context, 
00058                         info['manager'], info['category'], info['key'])
00059                         
00060         IPortletPermissionChecker(assignments.__of__(aq_inner(self.context)))()
00061         
00062         del assignments[info['name']]
00063         return self._render_column(info, viewname)
00064                 
00065     def _render_column(self, info, view_name):
00066         ksscore = self.getCommandSet('core')
00067         selector = ksscore.getCssSelector('div#portletmanager-' + info['manager'].replace('.', '-'))
00068         
00069         context = aq_inner(self.context)
00070         request = aq_inner(self.request)
00071         view = getMultiAdapter((context, request), name=view_name)
00072         manager = getUtility(IPortletManager, name=info['manager'])
00073         
00074         request['key'] = info['key']
00075         
00076         request['viewname'] = view_name
00077         renderer = getMultiAdapter((context, request, view, manager,), IPortletManagerRenderer)
00078         renderer.update()
00079         ksscore.replaceInnerHTML(selector, renderer.__of__(context).render())
00080         return self.render()