Back to index

plone3  3.1.7
Public Member Functions | Static Public Attributes | Private Member Functions | Static Private Attributes
plone.portlet.collection.collection.Renderer Class Reference

List of all members.

Public Member Functions

def __init__
def available
def collection_url
def results
def collection

Static Public Attributes

 render = _template

Private Member Functions

def _standard_results
def _random_results

Static Private Attributes

tuple _template = ViewPageTemplateFile('collection.pt')

Detailed Description

Portlet renderer.

This is registered in configure.zcml. The referenced page template is
rendered, and the implicit variable 'view' will refer to an instance
of this class. Other methods can be added and referenced in the template.

Definition at line 92 of file collection.py.


Constructor & Destructor Documentation

Definition at line 102 of file collection.py.

00102 
00103     def __init__(self, *args):
00104         base.Renderer.__init__(self, *args)

Here is the caller graph for this function:


Member Function Documentation

Definition at line 146 of file collection.py.

00146 
00147     def _random_results(self):
00148         results = []
00149         collection = self.collection()
00150         if collection is not None:
00151             """
00152             Kids, do not try this at home.
00153             
00154             We're poking at the internals of the (lazy) catalog results to avoid
00155             instantiating catalog brains unnecessarily.
00156             
00157             We're expecting a LazyCat wrapping two LazyMaps as the return value from
00158             Products.ATContentTypes.content.topic.ATTopic.queryCatalog.  The second
00159             of these contains the results of the catalog query.  We force sorting
00160             off because it's unnecessary and might result in a different structure of
00161             lazy objects.
00162             
00163             Using the correct LazyMap (results._seq[1]), we randomly pick a catalog index
00164             and then retrieve it as a catalog brain using the _func method.
00165             """
00166             
00167             results = collection.queryCatalog(sort_on=None)
00168             limit = self.data.limit and min(len(results), self.data.limit) or 1
00169             try:
00170                 results = [results._seq[1]._func(i) for i in random.sample(results._seq[1]._seq, limit)]
00171             except AttributeError, IndexError:
00172                 # This handles the cases where the lazy objects returned by the catalog
00173                 # are structured differently than expected.
00174                 results = []
00175         return results
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 136 of file collection.py.

00136 
00137     def _standard_results(self):
00138         results = []
00139         collection = self.collection()
00140         if collection is not None:
00141             results = collection.queryCatalog()
00142             if self.data.limit and self.data.limit > 0:
00143                 results = results[:self.data.limit]
00144         return results
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 116 of file collection.py.

00116 
00117     def available(self):
00118         return len(self.results())

Here is the call graph for this function:

get the collection the portlet is pointing to

Definition at line 177 of file collection.py.

00177 
00178     def collection(self):
00179         """ get the collection the portlet is pointing to"""
00180         
00181         collection_path = self.data.target_collection
00182         if not collection_path:
00183             return None
00184 
00185         if collection_path.startswith('/'):
00186             collection_path = collection_path[1:]
00187         
00188         if not collection_path:
00189             return None
00190 
00191         portal_state = getMultiAdapter((self.context, self.request), name=u'plone_portal_state')
00192         portal = portal_state.portal()
00193         return portal.restrictedTraverse(collection_path, default=None)
        

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 119 of file collection.py.

00119 
00120     def collection_url(self):
00121         collection = self.collection()
00122         if collection is None:
00123             return None
00124         else:
00125             return collection.absolute_url()

Here is the call graph for this function:

Get the actual result brains from the collection. 
    This is a wrapper so that we can memoize if and only if we aren't
    selecting random items.

Definition at line 126 of file collection.py.

00126 
00127     def results(self):
00128         """ Get the actual result brains from the collection. 
00129             This is a wrapper so that we can memoize if and only if we aren't
00130             selecting random items."""
00131         if self.data.random:
00132             return self._random_results()
00133         else:
00134             return self._standard_results()

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

tuple plone.portlet.collection.collection.Renderer._template = ViewPageTemplateFile('collection.pt') [static, private]

Definition at line 100 of file collection.py.

Definition at line 113 of file collection.py.


The documentation for this class was generated from the following file: