Advertisement
Guest User

Davi Lima

a guest
Mar 11th, 2011
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.29 KB | None | 0 0
  1. from zope.interface import implements
  2.  
  3. from plone.portlets.interfaces import IPortletDataProvider
  4. from plone.app.portlets.portlets import base
  5.  
  6. # TODO: If you define any fields for the portlet configuration schema below
  7. # do not forget to uncomment the following import
  8. #from zope import schema
  9. from z3c.form import field
  10. import z3cformhelper
  11.  
  12. from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
  13.  
  14. # TODO: If you require i18n translation for any of your schema fields below,
  15. # uncomment the following to import your package MessageFactory
  16. #from a.a.a import ExamplePortletMessageFactory as _
  17.  
  18.  
  19. class IExamplePortlet(IPortletDataProvider):
  20.     """A portlet
  21.  
  22.    It inherits from IPortletDataProvider because for this portlet, the
  23.    data that is being rendered and the portlet assignment itself are the
  24.    same.
  25.    """
  26.  
  27.     # TODO: Add any zope.schema fields here to capture portlet configuration
  28.     # information. Alternatively, if there are no settings, leave this as an
  29.     # empty interface - see also notes around the add form and edit form
  30.     # below.
  31.  
  32.     # some_field = schema.TextLine(title=_(u"Some field"),
  33.     #                              description=_(u"A field to use"),
  34.     #                              required=True)
  35.  
  36.  
  37. class Assignment(base.Assignment):
  38.     """Portlet assignment.
  39.  
  40.    This is what is actually managed through the portlets UI and associated
  41.    with columns.
  42.    """
  43.  
  44.     implements(IExamplePortlet)
  45.  
  46.     # TODO: Set default values for the configurable parameters here
  47.  
  48.     # some_field = u""
  49.  
  50.     # TODO: Add keyword parameters for configurable parameters here
  51.     # def __init__(self, some_field=u""):
  52.     #    self.some_field = some_field
  53.  
  54.     def __init__(self):
  55.         pass
  56.  
  57.     @property
  58.     def title(self):
  59.         """This property is used to give the title of the portlet in the
  60.        "manage portlets" screen.
  61.        """
  62.         return "Example Portlet"
  63.  
  64.  
  65. class Renderer(base.Renderer):
  66.     """Portlet renderer.
  67.  
  68.    This is registered in configure.zcml. The referenced page template is
  69.    rendered, and the implicit variable 'view' will refer to an instance
  70.    of this class. Other methods can be added and referenced in the template.
  71.    """
  72.  
  73.     render = ViewPageTemplateFile('exampleportlet.pt')
  74.  
  75.  
  76. class AddForm(z3cformhelper.AddForm):
  77.     """Portlet add form.
  78.  
  79.    This is registered in configure.zcml. The form_fields variable tells
  80.    zope.formlib which fields to display. The create() method actually
  81.    constructs the assignment that is being added.
  82.    """
  83.     fields = field.Fields(IExamplePortlet)
  84.  
  85.     def create(self, data):
  86.         return Assignment(**data)
  87.  
  88.  
  89. # NOTE: If this portlet does not have any configurable parameters, you
  90. # can use the next AddForm implementation instead of the previous.
  91.  
  92. # class AddForm(base.NullAddForm):
  93. #     """Portlet add form.
  94. #     """
  95. #     def create(self):
  96. #         return Assignment()
  97.  
  98.  
  99. # NOTE: If this portlet does not have any configurable parameters, you
  100. # can remove the EditForm class definition and delete the editview
  101. # attribute from the <plone:portlet /> registration in configure.zcml
  102.  
  103.  
  104. class EditForm(z3cformhelper.EditForm):
  105.     """Portlet edit form.
  106.  
  107.    This is registered with configure.zcml. The form_fields variable tells
  108.    zope.formlib which fields to display.
  109.    """
  110.     fields = field.Fields(IExamplePortlet)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement