[1003] | 1 | import cgi |
---|
| 2 | |
---|
| 3 | from zope.interface import implements |
---|
| 4 | |
---|
| 5 | from plone.portlets.interfaces import IPortletDataProvider |
---|
| 6 | from plone.app.portlets.portlets import base |
---|
| 7 | |
---|
| 8 | from zope import schema |
---|
| 9 | from zope.formlib import form |
---|
| 10 | from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile |
---|
| 11 | |
---|
| 12 | from quintagroup.portlet.cumulus import CumulusPortletMessageFactory as _ |
---|
| 13 | |
---|
| 14 | |
---|
| 15 | class ICumulusPortlet(IPortletDataProvider): |
---|
| 16 | """A portlet |
---|
| 17 | |
---|
| 18 | It inherits from IPortletDataProvider because for this portlet, the |
---|
| 19 | data that is being rendered and the portlet assignment itself are the |
---|
| 20 | same. |
---|
| 21 | """ |
---|
| 22 | |
---|
| 23 | # TODO: Add any zope.schema fields here to capture portlet configuration |
---|
| 24 | # information. Alternatively, if there are no settings, leave this as an |
---|
| 25 | # empty interface - see also notes around the add form and edit form |
---|
| 26 | # below. |
---|
| 27 | |
---|
| 28 | # some_field = schema.TextLine(title=_(u"Some field"), |
---|
| 29 | # description=_(u"A field to use"), |
---|
| 30 | # required=True) |
---|
| 31 | |
---|
| 32 | |
---|
| 33 | class Assignment(base.Assignment): |
---|
| 34 | """Portlet assignment. |
---|
| 35 | |
---|
| 36 | This is what is actually managed through the portlets UI and associated |
---|
| 37 | with columns. |
---|
| 38 | """ |
---|
| 39 | |
---|
| 40 | implements(ICumulusPortlet) |
---|
| 41 | |
---|
| 42 | # TODO: Set default values for the configurable parameters here |
---|
| 43 | |
---|
| 44 | # some_field = u"" |
---|
| 45 | |
---|
| 46 | # TODO: Add keyword parameters for configurable parameters here |
---|
| 47 | # def __init__(self, some_field=u""): |
---|
| 48 | # self.some_field = some_field |
---|
| 49 | |
---|
| 50 | def __init__(self): |
---|
| 51 | pass |
---|
| 52 | |
---|
| 53 | @property |
---|
| 54 | def title(self): |
---|
| 55 | """This property is used to give the title of the portlet in the |
---|
| 56 | "manage portlets" screen. |
---|
| 57 | """ |
---|
| 58 | return "Cumulus portlet" |
---|
| 59 | |
---|
| 60 | |
---|
| 61 | class Renderer(base.Renderer): |
---|
| 62 | """Portlet renderer. |
---|
| 63 | |
---|
| 64 | This is registered in configure.zcml. The referenced page template is |
---|
| 65 | rendered, and the implicit variable 'view' will refer to an instance |
---|
| 66 | of this class. Other methods can be added and referenced in the template. |
---|
| 67 | """ |
---|
| 68 | |
---|
| 69 | render = ViewPageTemplateFile('cumulusportlet.pt') |
---|
| 70 | |
---|
| 71 | def getTags(self): |
---|
| 72 | tags = '<tags>' |
---|
| 73 | for i in range(10): |
---|
| 74 | tags += "<a href='#' style='10'>test%d</a>" % i |
---|
| 75 | tags += '</tags>' |
---|
| 76 | return cgi.escape(tags) |
---|
| 77 | |
---|
| 78 | def getScript(self): |
---|
| 79 | tags = self.getTags() |
---|
| 80 | return """<script type="text/javascript"> |
---|
| 81 | var so = new SWFObject("++resource++tagcloud.swf", "tagcloud", "200", "200", "7", "#ffffff"); |
---|
| 82 | so.addParam("wmode", "transparent"); |
---|
| 83 | so.addVariable("tcolor", "0x333333"); |
---|
| 84 | so.addVariable("mode", "tags"); |
---|
| 85 | so.addVariable("distr", "true"); |
---|
| 86 | so.addVariable("tspeed", "100"); |
---|
| 87 | so.addVariable("tagcloud", "%s"); |
---|
| 88 | so.write("comulus"); |
---|
| 89 | </script>""" % tags |
---|
| 90 | |
---|
| 91 | class AddForm(base.AddForm): |
---|
| 92 | """Portlet add form. |
---|
| 93 | |
---|
| 94 | This is registered in configure.zcml. The form_fields variable tells |
---|
| 95 | zope.formlib which fields to display. The create() method actually |
---|
| 96 | constructs the assignment that is being added. |
---|
| 97 | """ |
---|
| 98 | form_fields = form.Fields(ICumulusPortlet) |
---|
| 99 | |
---|
| 100 | def create(self, data): |
---|
| 101 | return Assignment(**data) |
---|
| 102 | |
---|
| 103 | |
---|
| 104 | # NOTE: If this portlet does not have any configurable parameters, you |
---|
| 105 | # can use the next AddForm implementation instead of the previous. |
---|
| 106 | |
---|
| 107 | # class AddForm(base.NullAddForm): |
---|
| 108 | # """Portlet add form. |
---|
| 109 | # """ |
---|
| 110 | # def create(self): |
---|
| 111 | # return Assignment() |
---|
| 112 | |
---|
| 113 | |
---|
| 114 | # NOTE: If this portlet does not have any configurable parameters, you |
---|
| 115 | # can remove the EditForm class definition and delete the editview |
---|
| 116 | # attribute from the <plone:portlet /> registration in configure.zcml |
---|
| 117 | |
---|
| 118 | |
---|
| 119 | class EditForm(base.EditForm): |
---|
| 120 | """Portlet edit form. |
---|
| 121 | |
---|
| 122 | This is registered with configure.zcml. The form_fields variable tells |
---|
| 123 | zope.formlib which fields to display. |
---|
| 124 | """ |
---|
| 125 | form_fields = form.Fields(ICumulusPortlet) |
---|