import urllibfrom zope.interface import implementsfrom zope.component import getMultiAdapterfrom zope.component import getAdapterfrom plone.portlets.interfaces import IPortletDataProviderfrom plone.app.portlets.portlets import basefrom plone.memoize.instance import memoizefrom zope import schemafrom zope.formlib import formfrom Products.Five.browser.pagetemplatefile import ViewPageTemplateFilefrom quintagroup.portlet.cumulus.interfaces import ITagsRetrieverfrom quintagroup.portlet.cumulus import cumulusportlet as pbasefrom collective.portlet.localcumulus.localcumulus import LocalCumulusPortletMessageFactory as _class ICumulusPortlet(pbase.ICumulusPortlet): """ A cumulus tag cloud portlet. """ path = schema.TextLine( title=_(u'Path to search'), description=_(u'Path to restrict searches'),)class Assignment(pbase.Assignment): """Portlet assignment. This is what is actually managed through the portlets UI and associated with columns. """ implements(ICumulusPortlet) path = u'' @property def title(self): """This property is used to give the title of the portlet in the "manage portlets" screen. """ return _("Local Tag Cloud (cumulus)")class Renderer(pbase.Renderer): """Portlet renderer. """ render = ViewPageTemplateFile('cumulusportlet.pt') @property def title(self): return _("Local Tag Cloud") def getTags(self): import pdb;pdb.set_trace() ## Breakpoint ## from plone.portlets.interfaces import IPortletAssignmentMapping from zope.component import getMultiAdapter tags = ITagsRetriever(self.context).getTags() if tags == []: return [] number_of_entries = [i[1] for i in tags] min_number = min(number_of_entries) max_number = max(number_of_entries) distance = float(max_number - min_number) or 1 step = (self.data.largest - self.data.smallest) / distance result = [] for name, number, url in tags: size = self.data.smallest + step * (number - min_number) result.append({ 'name': name, 'size': size, 'number_of_entries': number, 'url': url }) return resultclass AddForm(pbase.AddForm): """Portlet add form. This is registered in configure.zcml. The form_fields variable tells zope.formlib which fields to display. The create() method actually constructs the assignment that is being added. """ form_fields = form.Fields(ICumulusPortlet) def create(self, data): return Assignment(**data) class EditForm(pbase.EditForm): """Portlet edit form. This is registered with configure.zcml. The form_fields variable tells zope.formlib which fields to display. """ form_fields = form.Fields(ICumulusPortlet)