- Timestamp:
- 08/10/05 15:20:03 (7 years ago)
- Location:
- trunk/src/chronolog
- Files:
-
- 1 added
- 2 modified
- 1 moved
-
common.py (added)
-
keys/configure.zcml (modified) (1 diff)
-
keys/domainscollection.py (modified) (3 diffs)
-
tests.py (moved) (moved from trunk/src/chronolog/keys/tests.py) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/chronolog/keys/configure.zcml
r16 r19 20 20 for=".domainscollection.ILocalTimeLogKeyDomainsCollection" 21 21 provides="zope.app.container.interfaces.INameChooser" 22 factory=". domainscollection.DomainNameChooser"22 factory="..common.IdAttributeNameChooser" 23 23 /> 24 24 -
trunk/src/chronolog/keys/domainscollection.py
r17 r19 12 12 # 13 13 ############################################################################## 14 """A local utility domains collection """14 """A local utility domains collection""" 15 15 __docformat__ = "reStructuredText" 16 16 17 17 from zope.interface import implements 18 from zope.i18nmessageid import MessageFactory19 18 20 19 from zope.app.container.interfaces import IContainer 21 20 from zope.app.container.btree import BTreeContainer 22 21 from zope.app.container.constraints import contains 23 from zope.app.container.contained import NameChooser24 from zope.app.exception.interfaces import UserError25 22 from zope.app.component.interfaces.registration import IRegisterable 26 23 … … 28 25 from chronolog.interfaces import ITimeLogKeyDomain 29 26 30 _ = MessageFactory('chronolog')31 27 32 28 class ILocalTimeLogKeyDomainsCollection(ITimeLogKeyDomainsCollection, … … 41 37 42 38 implements(ILocalTimeLogKeyDomainsCollection) 43 44 45 class DomainNameChooser(NameChooser):46 """INameChooser adapter for ILocalTimeLogKeyDomainsCollections47 48 This NameChooser uses the id of the domain objects passed in as the name49 to be used. We'll use a mockup object to demonstrate this with:50 51 >>> class DummyDomain:52 ... def __init__(self, id='foo'):53 ... self.id = id54 ...55 56 It'll refuse any name that is not the id of the domain object57 outright:58 59 >>> from chronolog.keys.domainscollection import DomainNameChooser60 >>> chooser = DomainNameChooser({})61 >>> chooser.checkName('foo', DummyDomain())62 True63 >>> chooser.checkName('bar', DummyDomain())64 Traceback (most recent call last):65 ...66 UserError: Given name and domain id do not match!67 68 As stated, the choosen name will be taken from the domain object itself,69 and the passed in name is ignored:70 71 >>> chooser.chooseName('bar', DummyDomain())72 'foo'73 74 """75 76 def checkName(self, name, object):77 if name != object.id:78 raise UserError(_(u'Given name and domain id do not match!'))79 return super(DomainNameChooser, self).checkName(name, object)80 81 def chooseName(self, name, object):82 name = object.id83 self.checkName(name, object)84 return name -
trunk/src/chronolog/tests.py
r17 r19 12 12 # 13 13 ############################################################################## 14 """Tests for timelog keysfunctionality"""14 """Tests for chronolog functionality""" 15 15 __docformat__ = "reStructuredText" 16 16 … … 21 21 def test_suite(): 22 22 return unittest.TestSuite(( 23 DocTestSuite('chronolog. keys.domainscollection'),23 DocTestSuite('chronolog.common'), 24 24 )) 25 25
