Back to index

plone3  3.1.7
Public Member Functions
plone.app.contentmenu.menu.DisplayMenu Class Reference
Inheritance diagram for plone.app.contentmenu.menu.DisplayMenu:
Inheritance graph
[legend]
Collaboration diagram for plone.app.contentmenu.menu.DisplayMenu:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def getMenuItems

Detailed Description

Definition at line 212 of file menu.py.


Member Function Documentation

def plone.app.contentmenu.menu.DisplayMenu.getMenuItems (   self,
  obj,
  request 
)
Return menu item entries in a TAL-friendly form.

Definition at line 215 of file menu.py.

00215 
00216     def getMenuItems(self, obj, request):
00217         """Return menu item entries in a TAL-friendly form."""
00218         results = []
00219 
00220         context_state = getMultiAdapter((obj, request), name='plone_context_state')
00221         isDefaultPage = context_state.is_default_page()
00222 
00223         parent = None
00224 
00225         folder = None
00226         context = None
00227 
00228         folderLayouts = []
00229         contextLayouts = []
00230 
00231         # If this is a default page, also get menu items relative to the parent
00232         if isDefaultPage:
00233             parent = utils.parent(obj)
00234             folder = ISelectableBrowserDefault(parent, None)
00235 
00236         context = ISelectableBrowserDefault(obj, None)
00237 
00238         folderLayouts = []
00239         folderCanSetLayout = False
00240         folderCanSetDefaultPage = False
00241 
00242         if folder is not None:
00243             folderLayouts = folder.getAvailableLayouts()
00244             folderCanSetLayout = folder.canSetLayout()
00245             folderCanSetDefaultPage = folder.canSetDefaultPage()
00246 
00247         contextLayouts = []
00248         contextCanSetLayout = False
00249         contextCanSetDefaultPage = False
00250 
00251         if context is not None:
00252             contextLayouts = context.getAvailableLayouts()
00253             contextCanSetLayout = context.canSetLayout()
00254             contextCanSetDefaultPage = context.canSetDefaultPage()
00255 
00256         # Short circuit if neither folder nor object will provide us with
00257         # items
00258         if not (folderCanSetLayout or folderCanSetDefaultPage or \
00259                 contextCanSetLayout or contextCanSetDefaultPage):
00260             return []
00261 
00262         # Only show the block "Folder display" and "Item display" separators if
00263         # they are necessars
00264         useSeparators = False
00265         if folderCanSetLayout or folderCanSetDefaultPage:
00266             if (contextCanSetLayout and len(contextLayouts) > 1) or \
00267                 contextCanSetDefaultPage:
00268                 useSeparators = True
00269 
00270         # 1. If this is a default-page, first render folder options
00271         if folder is not None:
00272             folderUrl = parent.absolute_url()
00273 
00274             if useSeparators:
00275                 results.append({ 'title'       : _(u'label_current_folder_views', default=u'Folder display'),
00276                                  'description' : '',
00277                                  'action'      : None,
00278                                  'selected'    : False,
00279                                  'icon'        : None,
00280                                  'extra'       : {'id': 'folderHeader', 'separator': 'actionSeparator', 'class': ''},
00281                                  'submenu'     : None,
00282                                  })
00283 
00284             if folderCanSetLayout:
00285                 for id, title in folderLayouts:
00286                     results.append({ 'title'       : title,
00287                                      'description' : '',
00288                                      'action'      : '%s/selectViewTemplate?templateId=%s' % (folderUrl, id,),
00289                                      'selected'    : False,
00290                                      'icon'        : None,
00291                                      'extra'       : {'id': id, 'separator': None, 'class': ''},
00292                                      'submenu'     : None,
00293                                      })
00294             # Display the selected item (i.e. the context)
00295             results.append({ 'title'       : _(u'label_item_selected', default=u'Item: ${contentitem}', mapping={'contentitem' : _safe_unicode(obj.Title())}),
00296                              'description' : '',
00297                              'action'      : None,
00298                              'selected'    : True,
00299                              'icon'        : None,
00300                              'extra'       : {'id': 'folderDefaultPageDisplay', 'separator': 'actionSeparator', 'class': 'actionMenuSelected'},
00301                              'submenu'     : None,
00302                              })
00303             # Let the user change the selection
00304             if folderCanSetDefaultPage:
00305                 results.append({ 'title'       : _(u'label_change_default_item', default=u'Change content item as default view...'),
00306                                  'description' : _(u'title_change_default_view_item', default=u'Change the item used as default view in this folder'),
00307                                  'action'      : '%s/select_default_page' % (folderUrl,),
00308                                  'selected'    : False,
00309                                  'icon'        : None,
00310                                  'extra'       : {'id': 'folderChangeDefaultPage', 'separator': 'actionSeparator', 'class': ''},
00311                                  'submenu'     : None,
00312                                  })
00313 
00314         # 2. Render context options
00315         if context is not None:
00316             contextUrl = obj.absolute_url()
00317             selected = context.getLayout()
00318             defaultPage = context.getDefaultPage()
00319             layouts = context.getAvailableLayouts()
00320 
00321             if useSeparators:
00322                 results.append({ 'title'       : _(u'label_current_item_views', default=u'Item display'),
00323                                  'description' : '',
00324                                  'action'      : None,
00325                                  'selected'    : False,
00326                                  'icon'        : None,
00327                                  'extra'       : {'id': 'contextHeader', 'separator': 'actionSeparator', 'class': ''},
00328                                  'submenu'     : None,
00329                                  })
00330 
00331             # If context is a default-page in a folder, that folder's views will
00332             # be shown. Only show context views if there are any to show.
00333 
00334             showLayouts = False
00335             if not isDefaultPage:
00336                 showLayouts = True
00337             elif len(layouts) > 1:
00338                 showLayouts = True
00339 
00340             if showLayouts and contextCanSetLayout:
00341                 for id, title in contextLayouts:
00342                     results.append({ 'title'       : title,
00343                                      'description' : '',
00344                                      'action'      : '%s/selectViewTemplate?templateId=%s' % (contextUrl, id,),
00345                                      'selected'    : (defaultPage is None and id == selected),
00346                                      'icon'        : None,
00347                                      'extra'       : {'id': id, 'separator': None, 'class': ''},
00348                                      'submenu'     : None,
00349                                      })
00350 
00351             # Allow setting / changing the default-page, unless this is a
00352             # default-page in a parent folder.
00353             if not INonStructuralFolder.providedBy(obj):
00354                 if defaultPage is None:
00355                     if contextCanSetDefaultPage:
00356                         results.append({ 'title'       : _(u'label_choose_item', default=u'Select a content item\nas default view...'),
00357                                          'description' : _(u'title_select_default_view_item', default=u'Select an item to be used as default view in this folder...'),
00358                                          'action'      : '%s/select_default_page' % (contextUrl,),
00359                                          'selected'    : False,
00360                                          'icon'        : None,
00361                                          'extra'       : {'id': 'contextSetDefaultPage', 'separator': 'actionSeparator', 'class': ''},
00362                                          'submenu'     : None,
00363                                          })
00364                 else:
00365                     defaultPageObj = getattr(obj, defaultPage, None)
00366                     defaultPageTitle = u""
00367                     if defaultPageObj is not None:
00368                         if hasattr(aq_base(defaultPageObj), 'Title'):
00369                             defaultPageTitle = defaultPageObj.Title()
00370                         else:
00371                             defaultPageTitle = getattr(aq_base(defaultPageObj), 'title', u'')
00372 
00373                     results.append({ 'title'       : _(u'label_item_selected', default=u'Item: ${contentitem}', mapping={'contentitem' : _safe_unicode(defaultPageTitle)}),
00374                                      'description' : '',
00375                                      'action'      : None,
00376                                      'selected'    : True,
00377                                      'icon'        : None,
00378                                      'extra'       : {'id': 'contextDefaultPageDisplay', 'separator': 'actionSeparator', 'class': ''},
00379                                      'submenu'     : None,
00380                                      })
00381                     if contextCanSetDefaultPage:
00382                         results.append({ 'title'       : _(u'label_change_item', default=u'Change content item\nas default view...'),
00383                                          'description' : _(u'title_change_default_view_item', default=u'Change the item used as default view in this folder'),
00384                                          'action'      : '%s/select_default_page' % (contextUrl,),
00385                                          'selected'    : False,
00386                                          'icon'        : None,
00387                                          'extra'       : {'id': 'contextChangeDefaultPage', 'separator': 'actionSeparator', 'class': ''},
00388                                          'submenu'     : None,
00389                                          })
00390 
00391         return results
00392 

Here is the call graph for this function:


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