Changeset 818

Show
Ignore:
Timestamp:
05/30/07 19:22:35 (2 years ago)
Author:
sgillies
Message:

Add Persons and subject and responsibility relationships

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • Bibliomane/trunk/bibliomane/configure.zcml

    r817 r818  
    9292  </class> 
    9393 
     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 
    94126</configure> 
  • Bibliomane/trunk/bibliomane/interfaces.py

    r817 r818  
    22from zope.app.container.interfaces import IContainer, IContained 
    33from zope.app.container.constraints import contains, containers 
    4 from zope.schema import Date, List, Text, TextLine 
    5  
     4from zope.schema import Date, Iterable, List, Text, TextLine, URI 
     5 
     6# Schemas 
    67 
    78class 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    """ 
    814    contains('bibliomane.interfaces.IExpression') 
    915 
     
    4551        ) 
    4652 
     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 
    4771 
    4872class IExpression(IWork): 
     73     
     74    """An Expression "is embodied in" a Manifestation and "is realized by" a 
     75    Person or Corporate Body. 
     76    """ 
    4977    containers('bibliomane.interfaces.IWork') 
    5078 
     
    5785 
    5886class IManifestation(IContained, IContainer): 
     87 
     88    """A Manifestation "is exemplified by" an Item and "is produced by" a  
     89    Person or Corporate Body. 
     90    """ 
    5991    containers('bibliomane.interfaces.IExpression') 
    6092    contains('bibliomane.interfaces.IItem') 
     
    86118 
    87119class IItem(IContained): 
     120 
     121    """An Item "is owned by" a Person or Corporate Body. 
     122    """ 
    88123    containers('bibliomane.interfaces.IManifestation') 
    89124 
     
    95130 
    96131 
     132class 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 
     159class 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 
     182class IFrbrRelationshipContainer(Interface): 
     183    pass 
     184 
     185# Relationship markers 
     186 
     187class IHasSubject(Interface): 
     188    pass 
     189 
     190class ICreatedBy(Interface): 
     191    pass 
     192 
     193class IRealizedBy(Interface): 
     194    pass 
     195 
     196class IProducedBy(Interface): 
     197    pass 
     198 
     199class IOwnedBy(Interface): 
     200    pass 
     201 
     202 
  • Bibliomane/trunk/bibliomane/tests/test_doctests.py

    r817 r818  
    44from zope.testing import doctestunit 
    55from zope.component import testing 
     6 
     7from zc.relationship.tests import intidSetUp as setUp 
     8from zc.relationship.tests import tearDown 
    69 
    710OPTIONFLAGS = (doctest.REPORT_ONLY_FIRST_FAILURE | 
     
    1922        doctestunit.DocFileSuite( 
    2023            'works.txt', optionflags=OPTIONFLAGS, package='bibliomane.tests', 
    21             setUp=testing.setUp, tearDown=testing.tearDown), 
     24            setUp=setUp, tearDown=tearDown), 
    2225 
    2326        #doctestunit.DocTestSuite( 
  • Bibliomane/trunk/bibliomane/tests/works.txt

    r817 r818  
    2222  >>> from zope.app.folder import Folder 
    2323 
     24  >>> root = app.getSiteManager() 
    2425  >>> works = Folder() 
     26  >>> root['works'] = works 
     27 
    2528  >>> works[u'1'] = work 
    2629  >>> IContained.providedBy(work) 
     
    7679  True 
    7780 
     81Test subject relationships 
     82-------------------------- 
    7883 
     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 
     116Test 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  
    11from persistent import Persistent 
    22from zope.interface import implements 
     3from zope.component import getUtility 
    34from zope.app.container.btree import BTreeContainer 
    45from zope.app.container.contained import Contained 
    56 
    6 from interfaces import IWork, IExpression, IManifestation, IItem 
     7from zc.relationship import Container, Relationship 
     8 
     9from bibliomane.interfaces import IWork, IExpression, IManifestation, IItem 
     10from bibliomane.interfaces import IHasSubject 
     11from bibliomane.interfaces import ICreatedBy 
     12from bibliomane.relationships import find_sources, find_targets 
    713 
    814 
     
    2329        self.title = title 
    2430 
     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 
    2543         
    26 class Expression(Work): 
     44class Expression(BTreeContainer, Contained): 
    2745    implements(IExpression) 
    2846 
     47    __name__ = __parent__ = None 
     48 
     49    title = u"" 
     50    title_language = u"" 
     51    form = u"" 
     52    date = None 
     53    context = u"" 
    2954    language = u"" 
    3055