Back to index

plone3  3.1.7
classic.py
Go to the documentation of this file.
00001 from zope.interface import implements
00002 
00003 from plone.portlets.interfaces import IPortletDataProvider
00004 from plone.app.portlets.portlets import base
00005 
00006 from zope import schema
00007 from zope.formlib import form
00008 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00009 from Products.CMFPlone import PloneMessageFactory as _
00010 
00011 class IClassicPortlet(IPortletDataProvider):
00012     """A portlet which can render a classic Plone portlet macro
00013     """
00014 
00015     template = schema.ASCIILine(title=_(u'Template'),
00016                             description=_(u'The template containing the portlet.'),
00017                             required=True)
00018 
00019     macro = schema.ASCIILine(title=_(u'Macro'),
00020                          description=_(u"The macro containing the portlet."),
00021                          default='portlet',
00022                          required=True)
00023 
00024 class Assignment(base.Assignment):
00025     implements(IClassicPortlet)
00026 
00027     def __init__(self, template='', macro=''):
00028         self.template = template
00029         self.macro = macro
00030 
00031     @property
00032     def title(self):
00033         return self.template
00034 
00035 class Renderer(base.Renderer):
00036 
00037     def __init__(self, context, request, view, manager, data):
00038         self.context = context
00039         self.data = data
00040 
00041     render = ViewPageTemplateFile('classic.pt')
00042     
00043     def use_macro(self):
00044         return bool(self.data.macro)
00045 
00046     def path_expression(self):
00047         expr = 'context/%s' % self.data.template
00048         if self.use_macro():
00049             expr += '/macros/%s' % self.data.macro
00050         return expr
00051 
00052 class AddForm(base.AddForm):
00053     form_fields = form.Fields(IClassicPortlet)
00054     label = _(u"Add Classic Portlet")
00055     description = _(u"A classic portlet allows you to use legacy portlet templates.")
00056 
00057     def create(self, data):
00058         return Assignment(template=data.get('template', ''),
00059                           macro=data.get('macro', ''))
00060 
00061 class EditForm(base.EditForm):
00062     form_fields = form.Fields(IClassicPortlet)
00063     label = _(u"Edit Classic Portlet")
00064     description = _(u"A classic portlet allows you to use legacy portlet templates.")