Back to index

plone3  3.1.7
view.py
Go to the documentation of this file.
00001 from zope.component import getMultiAdapter
00002 
00003 from plone.app.layout.viewlets import ViewletBase
00004 from plone.app.layout.nextprevious.interfaces import INextPreviousProvider
00005 from plone.memoize import view, instance
00006 
00007 from Products.Five.browser import BrowserView
00008 from Products.Five.browser.pagetemplatefile import ZopeTwoPageTemplateFile
00009 from Acquisition import aq_inner, aq_parent
00010 
00011 
00012 class NextPreviousView(BrowserView):
00013     """Information about next/previous navigation
00014     """
00015 
00016     @view.memoize
00017     def next(self):
00018         provider = self._provider()
00019         if provider is None:
00020             return None
00021         return provider.getNextItem(aq_inner(self.context))
00022     
00023     @view.memoize
00024     def previous(self):
00025         provider = self._provider()
00026         if provider is None:
00027             return None
00028         return provider.getPreviousItem(aq_inner(self.context))
00029 
00030     @view.memoize
00031     def enabled(self):
00032         provider = self._provider()
00033         if provider is None:
00034             return False
00035         return provider.enabled
00036 
00037     @instance.memoize
00038     def _provider(self):
00039         # Note - the next/previous provider is the container of this object!
00040         # This may not support next/previous navigation, so code defensively
00041         return INextPreviousProvider(aq_parent(aq_inner(self.context)), None)
00042 
00043     @view.memoize
00044     def isViewTemplate(self):
00045         plone = getMultiAdapter((self.context, self.request), name=u'plone_context_state')
00046         return plone.is_view_template()
00047 
00048 
00049 class NextPreviousViewlet(ViewletBase, NextPreviousView):
00050     render = ZopeTwoPageTemplateFile('nextprevious.pt')
00051 
00052 
00053 class NextPreviousLinksViewlet(ViewletBase, NextPreviousView):
00054     render = ZopeTwoPageTemplateFile('links.pt')