Back to index

plone3  3.1.7
Classes | Functions
CMFCore.browser.globalbrowsermenuservice Namespace Reference

Classes

class  menuItemsDirective

Functions

def addMenuItem
def getMenu
def menuItemDirective

Function Documentation

def CMFCore.browser.globalbrowsermenuservice.addMenuItem (   menu_id,
  interface,
  action,
  title,
  description = '',
  filter_string = None,
  permission = None,
  extra = None 
)

Definition at line 38 of file globalbrowsermenuservice.py.

00038 
00039                 ):
00040     registry = globalBrowserMenuService._registry[menu_id].registry
00041 
00042     if permission:
00043         if permission == 'zope.Public':
00044             permission = CheckerPublic
00045 
00046     if interface is not None and not IInterface.providedBy(interface):
00047         if isinstance(interface, (type, ClassType)):
00048             interface = implementedBy(interface)
00049         else:
00050             raise TypeError(
00051                 "The interface argument must be an interface (or None) "
00052                 "or a class.")
00053 
00054     data = registry.get(interface) or []
00055     data.append(
00056         MenuItem(action, title, description, filter_string, permission, extra)
00057         )
00058     registry.register(interface, data)
00059 

def CMFCore.browser.globalbrowsermenuservice.getMenu (   menu_id,
  object,
  request,
  max = 999999 
)

Definition at line 60 of file globalbrowsermenuservice.py.

00060 
00061 def getMenu(menu_id, object, request, max=999999):
00062     traverser = PublicationTraverser()
00063 
00064     result = []
00065     seen = {}
00066 
00067     # stuff for figuring out the selected view
00068     request_url = request.getURL()
00069 
00070     for item in globalBrowserMenuService.getAllMenuItems(menu_id, object):
00071 
00072         # Make sure we don't repeat a specification for a given title
00073         title = item.title
00074         if title in seen:
00075             continue
00076         seen[title] = 1
00077 
00078         permission = item.permission
00079         action = item.action
00080 
00081         if permission:
00082             # If we have an explicit permission, check that we
00083             # can access it.
00084             if not checkPermission(permission, object):
00085                 continue
00086 
00087         elif action:
00088             # Otherwise, test access by attempting access
00089             path = action
00090             l = action.find('?')
00091             if l >= 0:
00092                path = action[:l]
00093             try:
00094                 v = traverser.traverseRelativeURL(
00095                     request, object, path)
00096                 # TODO:
00097                 # tickle the security proxy's checker
00098                 # we're assuming that view pages are callable
00099                 # this is a pretty sound assumption
00100                 v.__call__
00101             except (Unauthorized, Forbidden):
00102                 continue # Skip unauthorized or forbidden
00103 
00104         normalized_action = action
00105         if action.startswith('@@'):
00106             normalized_action = action[2:]
00107 
00108         if request_url.endswith('/'+normalized_action):
00109             selected='selected'
00110         elif request_url.endswith('/++view++'+normalized_action):
00111             selected='selected'
00112         elif request_url.endswith('/@@'+normalized_action):
00113             selected='selected'
00114         else:
00115             selected=''
00116 
00117         result.append({
00118             'title': title,
00119             'description': item.description,
00120             'action': "%s" % action,
00121             'filter': item.filter,
00122             'selected': selected,
00123             'extra': item.extra,
00124             })
00125 
00126         if len(result) >= max:
00127             return result
00128 
00129     return result
00130 
00131 

Here is the call graph for this function:

Here is the caller graph for this function:

def CMFCore.browser.globalbrowsermenuservice.menuItemDirective (   _context,
  menu,
  for_,
  action,
  title,
  description = '',
  filter = None,
  permission = None,
  extra = None 
)

Definition at line 134 of file globalbrowsermenuservice.py.

00134 
00135                       permission=None, extra=None):
00136     return menuItemsDirective(_context, menu, for_).menuItem(
00137         _context, action, title, description, filter, permission, extra)
00138 

Here is the caller graph for this function: