first steps...; addedd relations package
git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@616 fd906abe-77d9-0310-91a1-e0d9ade77398
This commit is contained in:
parent
b6d61f557b
commit
1570c8d680
8 changed files with 199 additions and 5 deletions
|
@ -27,8 +27,8 @@
|
|||
<table class="columns">
|
||||
<tr>
|
||||
<td class="left">
|
||||
<span metal:use-macro="context/@@standard_macros/navigation_box" />
|
||||
<!--
|
||||
<span metal:use-macro="context/@@standard_macros/navigation_box" />
|
||||
<span metal:use-macro="context/@@standard_macros/commontasks_box" />
|
||||
<span metal:use-macro="context/@@standard_macros/metadata_box" />
|
||||
<span metal:use-macro="context/@@standard_macros/views_box" />
|
||||
|
|
25
doc/menu.txt
25
doc/menu.txt
|
@ -3,9 +3,30 @@ Creating and Rendering Menus
|
|||
|
||||
We first set up a test and working environment:
|
||||
|
||||
>>> from zope.app import zapi
|
||||
>>> from zope.app.testing import ztapi
|
||||
>>> from zope.app.component import site, interfaces
|
||||
>>> from zope.app.folder import Folder
|
||||
>>> from cybertools.menu import Menu
|
||||
>>> from cybertools.interfaces import IMenu
|
||||
|
||||
Create a menu:
|
||||
Set up a site:
|
||||
|
||||
>>> m1 = Menu()
|
||||
>>> f1 = Folder()
|
||||
>>> sm = site.LocalSiteManager(f1)
|
||||
>>> f1.setSiteManager(sm)
|
||||
>>> default = sm['default']
|
||||
|
||||
Create a menu and register it:
|
||||
|
||||
>>> m1 = Menu('m1')
|
||||
>>> default['m1'] = m1
|
||||
>>> reg = site.UtilityRegistration('main', IMenu, m1)
|
||||
>>> default.registrationManager.addRegistration(reg)
|
||||
'UtilityRegistration'
|
||||
>>> reg.status = interfaces.registration.ActiveStatus
|
||||
>>> zapi.getUtility(IMenu, 'main', context=f1)
|
||||
Menu('m1')
|
||||
>>> list(zapi.getUtilitiesFor(IMenu, f1))
|
||||
[('main', Menu('m1'))]
|
||||
|
8
menu.py
8
menu.py
|
@ -34,6 +34,9 @@ class Menu(OrderedContainer):
|
|||
|
||||
title = u''
|
||||
|
||||
def __init__(self, name=''):
|
||||
self.__name__ = name
|
||||
|
||||
def getMenuItems(self):
|
||||
return ()
|
||||
|
||||
|
@ -54,3 +57,8 @@ class Menu(OrderedContainer):
|
|||
|
||||
def menuItemPath(self):
|
||||
return ''
|
||||
|
||||
def __repr__(self):
|
||||
return "%s('%s')" % (self.__class__.__name__, self.__name__)
|
||||
|
||||
|
7
relations/__init__.py
Normal file
7
relations/__init__.py
Normal file
|
@ -0,0 +1,7 @@
|
|||
# -*- coding: UTF-8 -*-
|
||||
# -*- Mode: Python; py-indent-offset: 4 -*-
|
||||
# Copyright (C) 2005 Helmut Merz <helmutm@cy55.de>
|
||||
|
||||
"""
|
||||
$Id$
|
||||
"""
|
21
relations/configure.zcml
Normal file
21
relations/configure.zcml
Normal file
|
@ -0,0 +1,21 @@
|
|||
<!-- $Id$ -->
|
||||
|
||||
<configure
|
||||
xmlns="http://namespaces.zope.org/zope"
|
||||
i18n_domain="zope"
|
||||
>
|
||||
|
||||
<!-- Security definitions -->
|
||||
|
||||
<!-- Content declarations -->
|
||||
|
||||
<utility provides=".interfaces.IRelationsRepository"
|
||||
factory=".utilities.RelationsRepository" />
|
||||
|
||||
<utility provides=".interfaces.IRelationsRegistry"
|
||||
factory=".utilities.RelationsRegistry" />
|
||||
|
||||
<!-- Register various browser related components, including all views -->
|
||||
<!--include package=".browser" /-->
|
||||
|
||||
</configure>
|
84
relations/interfaces.py
Normal file
84
relations/interfaces.py
Normal file
|
@ -0,0 +1,84 @@
|
|||
#
|
||||
# Copyright (c) 2005 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
interface definitions for the Relations utility and relation objects.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.interface import Interface, Attribute
|
||||
|
||||
|
||||
class IRelationsRepository(Interface):
|
||||
""" Local utility for storing relations.
|
||||
"""
|
||||
|
||||
def add(relation):
|
||||
""" Add the relation given and return the id generated for it.
|
||||
"""
|
||||
|
||||
def remove(relation):
|
||||
""" Remove the relation given.
|
||||
"""
|
||||
|
||||
|
||||
class IRelationsRegistry(Interface):
|
||||
""" Local utility for registering (cataloguing) and searching relations.
|
||||
"""
|
||||
|
||||
def register(relation):
|
||||
""" Register the relation given with this registry.
|
||||
"""
|
||||
|
||||
def unregister(relation):
|
||||
""" Remove the relation given from this registry.
|
||||
"""
|
||||
|
||||
def query(**kw):
|
||||
""" Return a list of relations that fulfill the criteria given.
|
||||
|
||||
Example: rr.queryRelations(first=someObject, second=anotherObject,
|
||||
relationship='a.dotted.name')
|
||||
"""
|
||||
|
||||
|
||||
class IRelation(Interface):
|
||||
""" Base class for relations.
|
||||
"""
|
||||
|
||||
relationship = Attribute(
|
||||
'A string specific for a kind of relation; e.g. the full module '
|
||||
'path and class name of the class implementing a certain type of relation.')
|
||||
|
||||
|
||||
class IDyadicRelation(IRelation):
|
||||
""" Relation connecting two objects.
|
||||
"""
|
||||
|
||||
first = Attribute('First object that belongs to the relation.')
|
||||
second = Attribute('Second object that belongs to the relation.')
|
||||
|
||||
|
||||
class ITriadicRelation(IDyadicRelation):
|
||||
""" Relation connecting three objects.
|
||||
"""
|
||||
|
||||
third = Attribute('Third object that belongs to the relation.')
|
||||
|
||||
|
51
relations/utilities.py
Normal file
51
relations/utilities.py
Normal file
|
@ -0,0 +1,51 @@
|
|||
#
|
||||
# Copyright (c) 2005 Helmut Merz helmutm@cy55.de
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program; if not, write to the Free Software
|
||||
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
#
|
||||
|
||||
"""
|
||||
Implementation of the utilities needed for the relations package.
|
||||
|
||||
$Id$
|
||||
"""
|
||||
|
||||
from zope.interface import implements
|
||||
from zope.app import zapi
|
||||
|
||||
class RelationsRepository(Persistent, Contained):
|
||||
""" Local utility for storing relations.
|
||||
"""
|
||||
|
||||
def add(self, relation):
|
||||
return 'bla'
|
||||
|
||||
def remove(self, relation):
|
||||
pass
|
||||
|
||||
|
||||
class RelationsRegistry(Persistent, Contained):
|
||||
""" Local utility for registering (cataloguing) and searching relations.
|
||||
"""
|
||||
|
||||
def register(self, relation):
|
||||
pass
|
||||
|
||||
def unregister(relation):
|
||||
pass
|
||||
|
||||
def query(**kw):
|
||||
return []
|
||||
|
|
@ -13,6 +13,7 @@ from zope.app import zapi
|
|||
from cybertools.menu import Menu
|
||||
from cybertools.interfaces import IMenu
|
||||
|
||||
|
||||
class TestMenu(unittest.TestCase):
|
||||
"Test methods of the Menu class."
|
||||
|
||||
|
@ -21,8 +22,8 @@ class TestMenu(unittest.TestCase):
|
|||
placefulSetUp()
|
||||
self.f1 = Folder()
|
||||
self.f1.__name__ = u'f1'
|
||||
self.m1 = Menu()
|
||||
self.f1['m1'] = self.m1
|
||||
#self.m1 = Menu()
|
||||
#self.f1['m1'] = self.m1
|
||||
|
||||
def tearDown(self):
|
||||
pass
|
||||
|
@ -36,6 +37,7 @@ class TestMenu(unittest.TestCase):
|
|||
'Interface IContained is not implemented by class Menu.')
|
||||
verifyClass(IMenu, Menu)
|
||||
|
||||
|
||||
def test_suite():
|
||||
return unittest.TestSuite((
|
||||
unittest.makeSuite(TestMenu),
|
||||
|
|
Loading…
Add table
Reference in a new issue