Changeset 818
- Timestamp:
- 05/30/07 19:22:35 (2 years ago)
- Files:
-
- Bibliomane/trunk/bibliomane/configure.zcml (modified) (1 diff)
- Bibliomane/trunk/bibliomane/interfaces.py (modified) (5 diffs)
- Bibliomane/trunk/bibliomane/principals.py (added)
- Bibliomane/trunk/bibliomane/tests/test_doctests.py (modified) (2 diffs)
- Bibliomane/trunk/bibliomane/tests/works.txt (modified) (2 diffs)
- Bibliomane/trunk/bibliomane/works.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
Bibliomane/trunk/bibliomane/configure.zcml
r817 r818 92 92 </class> 93 93 94 <interface 95 interface=".interfaces.IPerson" 96 type="zope.app.content.interfaces.IContentType" 97 /> 98 99 <class class=".principals.Person"> 100 <require 101 permission="zope.View" 102 interface=".interfaces.IPerson" 103 /> 104 <require 105 permission="zope.ManageContent" 106 set_schema=".interfaces.IPerson" 107 /> 108 </class> 109 110 <interface 111 interface=".interfaces.ICorporateBody" 112 type="zope.app.content.interfaces.IContentType" 113 /> 114 115 <class class=".principals.CorporateBody"> 116 <require 117 permission="zope.View" 118 interface=".interfaces.ICorporateBody" 119 /> 120 <require 121 permission="zope.ManageContent" 122 set_schema=".interfaces.ICorporateBody" 123 /> 124 </class> 125 94 126 </configure> Bibliomane/trunk/bibliomane/interfaces.py
r817 r818 2 2 from zope.app.container.interfaces import IContainer, IContained 3 3 from zope.app.container.constraints import contains, containers 4 from zope.schema import Date, List, Text, TextLine 5 4 from zope.schema import Date, Iterable, List, Text, TextLine, URI 5 6 # Schemas 6 7 7 8 class IWork(IContained, IContainer): 9 10 """A Work "is realized through" an Expression and "is created by" a Person 11 or Corporate Body. It "has as subject" another Work, Expression, 12 Manifestation, Item, Person, object, or concept. 13 """ 8 14 contains('bibliomane.interfaces.IExpression') 9 15 … … 45 51 ) 46 52 53 subjects = Iterable( 54 title=u"Subjects", 55 description=u"Subjects of this work also found in the database", 56 required=False, 57 ) 58 59 works = Iterable( 60 title=u"Works", 61 description=u"Other works treating this one as a subject", 62 required=False, 63 ) 64 65 creators = Iterable( 66 title=u"Creators", 67 description=u"Creators of this work", 68 required=False, 69 ) 70 47 71 48 72 class IExpression(IWork): 73 74 """An Expression "is embodied in" a Manifestation and "is realized by" a 75 Person or Corporate Body. 76 """ 49 77 containers('bibliomane.interfaces.IWork') 50 78 … … 57 85 58 86 class IManifestation(IContained, IContainer): 87 88 """A Manifestation "is exemplified by" an Item and "is produced by" a 89 Person or Corporate Body. 90 """ 59 91 containers('bibliomane.interfaces.IExpression') 60 92 contains('bibliomane.interfaces.IItem') … … 86 118 87 119 class IItem(IContained): 120 121 """An Item "is owned by" a Person or Corporate Body. 122 """ 88 123 containers('bibliomane.interfaces.IManifestation') 89 124 … … 95 130 96 131 132 class IPerson(Interface): 133 134 name = TextLine( 135 title=u"Name", 136 description=u"The person's name", 137 required=True, 138 ) 139 140 name_language = TextLine( 141 title=u"Title Language", 142 description=u"The language and/or script of the person's name", 143 required=False, 144 ) 145 146 link = URI( 147 title=u"URI", 148 description=u"A link to more authoritative information", 149 required=False, 150 ) 151 152 creations = Iterable( 153 title=u"Creations", 154 description=u"Works that the person has created", 155 required=False, 156 ) 157 158 159 class ICorporateBody(Interface): 160 161 name = TextLine( 162 title=u"Name", 163 description=u"The corporate body's name", 164 required=True, 165 ) 166 167 name_language = TextLine( 168 title=u"Title Language", 169 description=u"The language and/or script of the name", 170 required=False, 171 ) 172 173 place = TextLine( 174 title=u"Place", 175 description=u"The location of the corporate body", 176 required=False, 177 ) 178 179 180 # Marker interfaces 181 182 class IFrbrRelationshipContainer(Interface): 183 pass 184 185 # Relationship markers 186 187 class IHasSubject(Interface): 188 pass 189 190 class ICreatedBy(Interface): 191 pass 192 193 class IRealizedBy(Interface): 194 pass 195 196 class IProducedBy(Interface): 197 pass 198 199 class IOwnedBy(Interface): 200 pass 201 202 Bibliomane/trunk/bibliomane/tests/test_doctests.py
r817 r818 4 4 from zope.testing import doctestunit 5 5 from zope.component import testing 6 7 from zc.relationship.tests import intidSetUp as setUp 8 from zc.relationship.tests import tearDown 6 9 7 10 OPTIONFLAGS = (doctest.REPORT_ONLY_FIRST_FAILURE | … … 19 22 doctestunit.DocFileSuite( 20 23 'works.txt', optionflags=OPTIONFLAGS, package='bibliomane.tests', 21 setUp= testing.setUp, tearDown=testing.tearDown),24 setUp=setUp, tearDown=tearDown), 22 25 23 26 #doctestunit.DocTestSuite( Bibliomane/trunk/bibliomane/tests/works.txt
r817 r818 22 22 >>> from zope.app.folder import Folder 23 23 24 >>> root = app.getSiteManager() 24 25 >>> works = Folder() 26 >>> root['works'] = works 27 25 28 >>> works[u'1'] = work 26 29 >>> IContained.providedBy(work) … … 76 79 True 77 80 81 Test subject relationships 82 -------------------------- 78 83 84 Create a subject relationship container 85 86 >>> from zc.relationship import Container 87 >>> container = Container() 88 >>> works['frbr_relationships'] = container 89 >>> from zope.component import provideUtility 90 >>> from bibliomane.interfaces import IFrbrRelationshipContainer 91 >>> provideUtility(container, IFrbrRelationshipContainer) 92 93 Relate two works 94 95 >>> another_work = Work() 96 >>> another_work.title = u'Herodotus and religion in the Persian Wars' 97 >>> works[u'2'] = another_work 98 99 >>> from bibliomane.relationships import relate 100 >>> from bibliomane.interfaces import IHasSubject 101 >>> relate(another_work, work, IHasSubject) 102 >>> [w.title for w in another_work.subjects] 103 [u'The Histories'] 104 >>> [w.title for w in work.works] 105 [u'Herodotus and religion in the Persian Wars'] 106 107 Remove relationship 108 109 >>> from bibliomane.relationships import unrelate 110 >>> unrelate(another_work, work, IHasSubject) 111 >>> list(another_work.subjects) 112 [] 113 >>> list(work.works) 114 [] 115 116 Test responsibility relationships 117 --------------------------------- 118 119 Relate work to creator 120 121 >>> from bibliomane.principals import Person 122 >>> herodotus = Person(name=u'Herodotus') 123 >>> herodotus 124 <bibliomane.principals.Person object at ...> 125 >>> principals = Folder() 126 >>> root['principals'] = principals 127 >>> principals[u'herodotus'] = herodotus 128 >>> import transaction 129 >>> transaction.commit() 130 131 >>> from bibliomane.interfaces import ICreatedBy 132 >>> relate(work, herodotus, ICreatedBy) 133 >>> [w.title for w in herodotus.creations] 134 [u'The Histories'] 135 >>> [c.name for c in work.creators] 136 [u'Herodotus'] 137 138 Bibliomane/trunk/bibliomane/works.py
r817 r818 1 1 from persistent import Persistent 2 2 from zope.interface import implements 3 from zope.component import getUtility 3 4 from zope.app.container.btree import BTreeContainer 4 5 from zope.app.container.contained import Contained 5 6 6 from interfaces import IWork, IExpression, IManifestation, IItem 7 from zc.relationship import Container, Relationship 8 9 from bibliomane.interfaces import IWork, IExpression, IManifestation, IItem 10 from bibliomane.interfaces import IHasSubject 11 from bibliomane.interfaces import ICreatedBy 12 from bibliomane.relationships import find_sources, find_targets 7 13 8 14 … … 23 29 self.title = title 24 30 31 @property 32 def subjects(self): 33 return find_targets(self, IHasSubject) 34 35 @property 36 def works(self): 37 return find_sources(self, IHasSubject) 38 39 @property 40 def creators(self): 41 return find_targets(self, ICreatedBy) 42 25 43 26 class Expression( Work):44 class Expression(BTreeContainer, Contained): 27 45 implements(IExpression) 28 46 47 __name__ = __parent__ = None 48 49 title = u"" 50 title_language = u"" 51 form = u"" 52 date = None 53 context = u"" 29 54 language = u"" 30 55
