Changeset 4977 for main/waeup.sirp/trunk/src
- Timestamp:
- 1 Feb 2010, 17:49:19 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/university/facultycontainer.txt
r4920 r4977 1 FacultyContainer 2 **************** 1 :mod:`waeup.sirp.university.facultycontainer` -- Faculty Containers 2 ******************************************************************* 3 3 4 Containers for faculties. 4 .. module:: waeup.sirp.university.facultycontainer 5 6 Components that represent faculty containers. 5 7 6 8 :Test-Layer: unit 7 9 8 Getting a faculty container 9 =========================== 10 Before we can create faculty containers, we have to grok the 11 :mod:`waeup.sirp` package. This happens automatically in real-world 12 use: 10 13 11 We can easily create `FacultyContainers`:: 14 >>> import grok 15 >>> grok.testing.grok('waeup.sirp') 16 17 18 Content Classes (models and containers) 19 ======================================= 20 21 :class:`FacultyContainer` 22 ------------------------- 23 24 .. class:: FacultyContainer() 25 26 Create a faculty container: 27 28 >>> from waeup.sirp.university.facultycontainer import FacultyContainer 29 >>> mycontainer = FacultyContainer() 30 >>> mycontainer 31 <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...> 32 33 Another way to create :class:`FacultyContainer` instances is by asking 34 for a factory called ``waeup.FacultyContainer``. This way we can create a 35 faculty without importing a class: 36 37 >>> from zope.component import createObject 38 >>> mycontainer = createObject(u'waeup.FacultyContainer') 39 >>> mycontainer 40 <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...> 41 42 :class:`FacultyContainer` instances have the attributes required by the 43 `IFacultyContainer` interface: 44 45 >>> from waeup.sirp.interfaces import IFacultyContainer 46 >>> IFacultyContainer.providedBy(mycontainer) 47 True 48 49 >>> from zope.interface.verify import verifyObject 50 >>> verifyObject(IFacultyContainer, mycontainer) 51 True 52 53 .. method:: addFaculty(faculty) 54 55 Add a faculty into this container. Added objects are checked and 56 only `IFaculty` objects accepted: 57 58 >>> mycontainer.addFaculty(object()) 59 Traceback (most recent call last): 60 ... 61 TypeError: FacultyContainers contain only IFaculty instances 62 63 >>> list(mycontainer.values()) 64 [] 65 66 Regular faculties are accepted: 67 68 >>> from waeup.sirp.university.faculty import Faculty 69 >>> mycontainer.addFaculty(Faculty(title='Physics', 70 ... code='FP')) 71 72 >>> list(mycontainer.items()) 73 [(u'FP', <waeup.sirp.university.faculty.Faculty object at 0x...>)] 74 75 .. method:: clear() 76 77 Remove all departments from this faculty: 78 79 >>> mycontainer.clear() 80 >>> list(mycontainer.items()) 81 [] 82 83 84 Utilities 85 ========= 86 87 :class:`FacultyContainerFactory` 88 -------------------------------- 89 90 .. class:: FacultyContainerFactory() 91 92 .. attribute:: grok.name(u'waeup.FacultyContainer') 93 94 .. attribute:: grok.implements(IFactoryContainer) 95 96 A named utility to deliver new instances of :class:`FacultyContainer` 97 without the need to import the implementation before: 98 99 >>> from zope.component import createObject 100 >>> mycontainer = createObject(u'waeup.FacultyContainer') 101 >>> mycontainer 102 <waeup.sirp.university.facultycontainer.FacultyContainer object at 0x...> 103 104 The factory complies with the specifications from the 105 :class:`IFactory` insterface: 106 107 >>> from zope.interface.verify import verifyClass 108 >>> from zope.component.interfaces import IFactory 109 >>> from waeup.sirp.university.facultycontainer import ( 110 ... FacultyContainerFactory) 111 >>> verifyClass(IFactory, FacultyContainerFactory) 112 True 113 114 This means also, that we can get the interfaces of the created 115 object from the factory: 116 117 >>> fac_container_factory = FacultyContainerFactory() 118 >>> fac_container_factory.getInterfaces() 119 <implementedBy waeup.sirp.university.facultycontainer.FacultyContainer> 120 121 Examples 122 ======== 123 124 We can easily create `FacultyContainers`: 12 125 13 126 >>> from waeup.sirp.university.facultycontainer import FacultyContainer … … 22 135 Another way to get a faculty container -- without importing the class 23 136 -- is via factories. We registered a factory for faculty containers 24 under the name ``waeup.facultycontainer``:: 25 26 >>> import grok 27 >>> grok.testing.grok('waeup') 28 29 Now we can ask for an object by calling the appropriate factory: 137 under the name ``waeup.facultycontainer``: 30 138 31 139 >>> from zope.component import createObject
Note: See TracChangeset for help on using the changeset viewer.