From ad7d8828a1f6b26fe58c018ee6a460b65d11bb81 Mon Sep 17 00:00:00 2001 From: helmutm Date: Sat, 13 Aug 2005 17:34:10 +0000 Subject: [PATCH] basic setup for menu.py and unit testing git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@544 fd906abe-77d9-0310-91a1-e0d9ade77398 --- doc/menu.txt | 1 - interfaces.py | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-- menu.py | 21 +++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/doc/menu.txt b/doc/menu.txt index abae2de..b66f37e 100644 --- a/doc/menu.txt +++ b/doc/menu.txt @@ -9,4 +9,3 @@ We first set up a test and working environment: Create a menu: >>> m1 = Menu() - \ No newline at end of file diff --git a/interfaces.py b/interfaces.py index 45ed4d4..ffaafe0 100644 --- a/interfaces.py +++ b/interfaces.py @@ -28,7 +28,90 @@ from zope.app.container.interfaces import IOrderedContainer from zope.schema import Text, TextLine, List, Object, Int -class IMenu(IOrderedContainer): - """ A Menu. +class IBaseMenuItem(IOrderedContainer): + """ Base interface with common methods for IMenu and IMenuItem. """ + def getMenuItems(): + """ Return sub-menu items contained in this menu or menu item. + """ + + def addMenuItem(id, title, description='', target=None, urlPath=''): + """ Add a new menu item to this item or menu. Return the newly + created menu item. + + This is a convenience method for creating menu structures + programmatically. + """ + + def getParentMenuItem(menu=None, accu=[]): + """ Return the menu or menu item this item is a sub menu item. + + For certain cases of dynamic menu generation it may be + useful to give this method the menu object to which the + parent menu item path may eventually lead, and a list + of already accumulated menu items - in order to avoid + infinite cyclic searches for parent menu items. + """ + + def getMenu(): + """ Return the top-most menu object. + """ + + +class IMenu(IBaseMenuItem): + """ A Menu is a container for MenuItems and will be shown in a + menu portlet. + """ + + def getActiveMenuItems(context): + """ Return a a tuple with two elements: + [0] list with basic (current) menu item objects that + are associtated with the context. + [1] list with all menu item objects that lead to + the context object. + """ + + def getCorrespondingMenuItems(context): + """ Return the menu items of which context is the target. + """ + + def menuItemPath(): + """ Used for index creation: returns normalized urlPath attribute + for efficiently finding correspondign menu items via the + context object's path. + """ + + +class IMenuItem(IBaseMenuItem): + """ A MenuItem is part of a Menu and usually displayed together + with other MenuItem objects in a menu portlet. + """ + + def getItemUrl(): + """ Return the target URL of this menu item. + """ + + def getTargetUrl(): + """ Return the target URL of this menu item. + """ + + def getTargetObject(): + """ Return the object this menu item points to. + """ + + def isActive(context): + """ Return True if this menu item leads to the context object. + """ + + def isCurrent(context): + """ Return True if this menu item is associated with the + context object. + """ + + def menuItemPath(): + """ Used for index creation: returns normalized urlPath attribute + for efficiently finding correspondign menu items via the + context object's path. + """ + diff --git a/menu.py b/menu.py index 7a67c25..ac10cea 100644 --- a/menu.py +++ b/menu.py @@ -33,3 +33,24 @@ class Menu(OrderedContainer): implements(IMenu) title = u'' + + def getMenuItems(self): + return () + + def addMenuItem(self, id, title, description='', target=None, urlPath=''): + pass + + def getParentMenuItem(self, menu=None, accu=[]): + return None + + def getMenu(self): + return None + + def getActiveMenuItems(self, context): + return () + + def getCorrespondingMenuItems(self,context): + return () + + def menuItemPath(self): + return ''