def TestGroupMenuFuntions(): GroupMenuFnxObj = GroupMenuFnx() from tx2.Users.BusinessFunctions.GroupFunctions import GroupFnx from tx2.Users.BusinessFunctions.MenuFunctions import MenuFnx # get a list of groups GroupFnxObj = GroupFnx() MenuFnxObj = MenuFnx() GroupList = GroupFnxObj.ListAllGroups() if GroupList[0] != 1: return GroupList[1] else: GroupList = GroupList[1] print ' === PRINTING ALL GROUPS ===' for g in GroupList: print g.GroupName MenuList = MenuFnxObj.getParentMenu() if MenuList[0] != 1: return MenuList[1] else: MenuList = MenuList[1] print ' === PRINTING ALL PARENT MENU ===' for p in MenuList: print p.MenuName import random print ' === FOR EACH GROUP, ADD 2 PARENT MENUS ===' for g in GroupList: pstr = [] p1 = random.randint(0,len(MenuList)-1) print 'PARENT -1 = %d , %s' % (MenuList[p1].id, MenuList[p1].MenuName) # add parent 1 pstr.append(MenuList[p1].id) ChildMenu = MenuFnxObj.getChildMenuByParentID(MenuList[p1].id) if ChildMenu[0] is 1: for c in ChildMenu[1]: pstr.append(c.id) p2 = random.randint(0,len(MenuList)-1) print 'PARENT -2 = %d , %s' % (MenuList[p2].id, MenuList[p2].MenuName) pstr.append(MenuList[p2].id) ChildMenu = MenuFnxObj.getChildMenuByParentID(MenuList[p2].id) if ChildMenu[0] is 1: for c in ChildMenu[1]: pstr.append(c.id) print '=== menu list ===' ,pstr result = GroupMenuFnxObj.Insert(pstr,g.id,pstr,pstr,1,'test') if result[0] != 1: return result[1] else: print pstr, g.GroupName , result # now for each group, get the list of menu and delete them for g in GroupList: GroupMenuObjList = GroupMenuFnxObj.getGroupMenuObjectByGroupID(g.id) if GroupMenuObjList[0] != 1: return GroupMenuObjList[1] else: menustr = [] print '=== %s, Menu in this group ===' % (g.GroupName) for p in GroupMenuObjList[1]: print p.Menu.MenuName menustr.append(p.id) print menustr , g.GroupName result = GroupMenuFnxObj.Delete(menustr,1,'ip') print menustr , g.GroupName , result