Back to index

plone3  3.1.7
Public Member Functions | Public Attributes | Static Public Attributes
plone.app.viewletmanager.manager.OrderedViewletManager Class Reference
Inheritance diagram for plone.app.viewletmanager.manager.OrderedViewletManager:
Inheritance graph
[legend]
Collaboration diagram for plone.app.viewletmanager.manager.OrderedViewletManager:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def render
def filter
def sort

Public Attributes

 name
 interface

Static Public Attributes

tuple manager_template = ViewPageTemplateFile('manage-viewletmanager.pt')

Detailed Description

Definition at line 83 of file manager.py.


Member Function Documentation

def plone.app.viewletmanager.manager.BaseOrderedViewletManager.filter (   self,
  viewlets 
) [inherited]
Filter the viewlets.
    
``viewlets`` is a list of tuples of the form (name, viewlet).

This filters the viewlets just like Five, but also filters out
viewlets by name from the local utility which implements the
IViewletSettingsStorage interface.

Definition at line 23 of file manager.py.

00023 
00024     def filter(self, viewlets):
00025         """Filter the viewlets.
00026     
00027         ``viewlets`` is a list of tuples of the form (name, viewlet).
00028 
00029         This filters the viewlets just like Five, but also filters out
00030         viewlets by name from the local utility which implements the
00031         IViewletSettingsStorage interface.
00032         """
00033         storage = getUtility(IViewletSettingsStorage)
00034         skinname = self.context.getCurrentSkinName()
00035         hidden = frozenset(storage.getHidden(self.__name__, skinname))
00036         results = []
00037         # Only return visible viewlets accessible to the principal
00038         # We need to wrap each viewlet in its context to make sure that
00039         # the object has a real context from which to determine owner
00040         # security.
00041         # Copied from Five
00042         for name, viewlet in viewlets:
00043             viewlet = viewlet.__of__(viewlet.context)
00044             if name not in hidden and guarded_hasattr(viewlet, 'render'):
00045                 results.append((name, viewlet))
00046         return results

Here is the caller graph for this function:

See zope.contentprovider.interfaces.IContentProvider

Reimplemented from plone.app.viewletmanager.manager.BaseOrderedViewletManager.

Definition at line 86 of file manager.py.

00086 
00087     def render(self):
00088         """See zope.contentprovider.interfaces.IContentProvider"""
00089 
00090         # check whether we are in the manager view
00091         is_managing = False
00092         parent = getattr(self, '__parent__', None)
00093         while parent is not None:
00094             if IViewletManagementView.providedBy(parent):
00095                 is_managing = True
00096                 break
00097             parent = getattr(parent, '__parent__', None)
00098 
00099         if is_managing:
00100             # if we are in the managing view, then fetch all viewlets again
00101             viewlets = getAdapters(
00102                 (self.context, self.request, self.__parent__, self),
00103                 IViewlet)
00104 
00105             # sort them first
00106             viewlets = self.sort(viewlets)
00107 
00108             storage = getUtility(IViewletSettingsStorage)
00109             skinname = self.context.getCurrentSkinName()
00110             hidden = frozenset(storage.getHidden(self.__name__, skinname))
00111 
00112             # then render the ones which are accessible
00113             base_url = str(getMultiAdapter((self.context, self.request),
00114                            name='absolute_url'))
00115             query_tmpl = "%s/@@manage-viewlets?%%s" % base_url
00116             results = []
00117             for index, (name, viewlet) in enumerate(viewlets):
00118                 viewlet = viewlet.__of__(viewlet.context)
00119                 viewlet_id = "%s:%s" % (self.__name__, name)
00120                 options = {'index': index,
00121                            'name': name}
00122                 if guarded_hasattr(viewlet, 'render'):
00123                     viewlet.update()
00124                     options['content'] = viewlet.render()
00125                 else:
00126                     options['content'] = u""
00127                 if name in hidden:
00128                     options['hidden'] = True
00129                     query = {'show': viewlet_id}
00130                     options['show_url'] = query_tmpl % urlencode(query)
00131                 else:
00132                     options['hidden'] = False
00133                     query = {'hide': viewlet_id}
00134                     options['hide_url'] = query_tmpl % urlencode(query)
00135                 if index > 0:
00136                     prev_viewlet = viewlets[index-1][0]
00137                     query = {'move_above': "%s;%s" % (viewlet_id, prev_viewlet)}
00138                     options['up_url'] = query_tmpl % urlencode(query)
00139                 if index < (len(viewlets) - 1):
00140                     next_viewlet = viewlets[index+1][0]
00141                     query = {'move_below': "%s;%s" % (viewlet_id, next_viewlet)}
00142                     options['down_url'] = query_tmpl % urlencode(query)
00143                 results.append(options)
00144 
00145             self.name = self.__name__
00146             self.interface = list(providedBy(self).flattened())[0].__identifier__
00147             
00148             # and output them
00149             return self.manager_template(viewlets=results)
00150         # the rest is standard behaviour from zope.viewlet
00151         else:
00152             return BaseOrderedViewletManager.render(self)
00153 

Here is the call graph for this function:

def plone.app.viewletmanager.manager.BaseOrderedViewletManager.sort (   self,
  viewlets 
) [inherited]
Sort the viewlets.

``viewlets`` is a list of tuples of the form (name, viewlet).

This sorts the viewlets by the order looked up from the local utility
which implements the IViewletSettingsStorage interface. The remaining
ones are sorted just like Five does it.

Definition at line 47 of file manager.py.

00047 
00048     def sort(self, viewlets):
00049         """Sort the viewlets.
00050 
00051         ``viewlets`` is a list of tuples of the form (name, viewlet).
00052 
00053         This sorts the viewlets by the order looked up from the local utility
00054         which implements the IViewletSettingsStorage interface. The remaining
00055         ones are sorted just like Five does it.
00056         """
00057 
00058         storage = getUtility(IViewletSettingsStorage)
00059         skinname = self.context.getCurrentSkinName()
00060         order_by_name = storage.getOrder(self.__name__, skinname)
00061         # first get the known ones
00062         name_map = dict(viewlets)
00063         result = []
00064         for name in order_by_name:
00065             if name in name_map:
00066                 result.append((name, name_map[name]))
00067                 del name_map[name]
00068 
00069         # then sort the remaining ones
00070         # Copied from Five
00071         remaining = sorted(name_map.items(),
00072                            lambda x, y: cmp(aq_base(x[1]), aq_base(y[1])))
00073 
00074         # return both together
00075         return result + remaining

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 145 of file manager.py.

tuple plone.app.viewletmanager.manager.OrderedViewletManager.manager_template = ViewPageTemplateFile('manage-viewletmanager.pt') [static]

Definition at line 84 of file manager.py.

Definition at line 144 of file manager.py.


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