Back to index

plone3  3.1.7
base.py
Go to the documentation of this file.
00001 import sys
00002 
00003 from Acquisition import Explicit
00004 from OFS.SimpleItem import SimpleItem
00005 from ZODB.POSException import ConflictError
00006 
00007 from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00008 
00009 from zope.interface import Interface, implements
00010 from zope.component import adapts
00011 
00012 from zope.publisher.interfaces.browser import IBrowserView
00013 
00014 from plone.portlets.interfaces import IPortletDataProvider
00015 from plone.portlets.interfaces import IPortletAssignment
00016 from plone.portlets.interfaces import IPortletRenderer
00017 from plone.portlets.interfaces import IPortletManager
00018 
00019 from plone.app.portlets.interfaces import IDeferredPortletRenderer
00020 
00021 from zope.app.container.contained import Contained
00022 
00023 # Convenience imports
00024 from plone.app.portlets.browser.formhelper import AddForm
00025 from plone.app.portlets.browser.formhelper import NullAddForm
00026 from plone.app.portlets.browser.formhelper import EditForm
00027 
00028 class Assignment(SimpleItem, Contained):
00029     """Base class for assignments.
00030     
00031     Your type may override the 'title', 'available' and 'data' properties, and
00032     may 
00033     """
00034     
00035     implements(IPortletAssignment)
00036     
00037     __name__ = ''
00038     
00039     @property
00040     def id(self):
00041         return getattr(self, '__name__', '')
00042     
00043     @property
00044     def title(self):
00045         return self.template
00046 
00047     def available(self, context, request):
00048         """By default, this portlet is always available
00049         """
00050         return True
00051 
00052     @property
00053     def data(self):
00054         """Make the assignment itself represent the data object that is being rendered.
00055         """
00056         return self
00057 
00058 class Renderer(Explicit):
00059     """Base class for portlet renderers.
00060     
00061     You must override render() to return a string to render. One way of 
00062     doing this is to write:
00063     
00064         from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile
00065         ...
00066         render = ViewPageTemplateFile('mytemplate.pt')
00067         
00068     This will render the template mytemplate.pt, found in the same directory
00069     as your source code file.
00070     """
00071     
00072     implements(IPortletRenderer)
00073 
00074     def __init__(self, context, request, view, manager, data):
00075         self.context = context
00076         self.request = request
00077         self.view = view
00078         self.__parent__ = view
00079         self.manager = manager
00080         self.data = data
00081 
00082     def update(self):
00083         pass
00084 
00085     def render(self):
00086         raise NotImplementedError("You must implement 'render' as a method "
00087                                   "or page template file attribute")
00088 
00089     @property
00090     def available(self):
00091         """By default, portlets are available
00092         """
00093         return True
00094         
00095 class DeferredRenderer(Renderer):
00096     """provide defer functionality via KSS
00097     
00098     in here don't override render() but instead override render_full
00099     
00100     """
00101 
00102     implements(IDeferredPortletRenderer)
00103 
00104     render_preload = ViewPageTemplateFile('deferred_portlet.pt')
00105     
00106     def render_full(self):
00107         raise NotImplemented, "You must implement 'render_full' as a method or page template file attribute"
00108 
00109     def render(self):
00110         """render the portlet
00111 
00112         the template gets choosen depending on the initialize state
00113         """
00114         if self.initializing:
00115             return self.render_preload()
00116         else:
00117             return self.render_full()
00118