Changeset 4423 for waeup/branches/ulif-rewrite
- Timestamp:
- 23 Jul 2009, 12:47:05 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
waeup/branches/ulif-rewrite/src/waeup/university/faculty.txt
r4232 r4423 1 Faculties 2 ********* 1 :mod:`waeup.university.faculty` -- Faculties 2 ******************************************** 3 4 .. module:: waeup.university.faculty 5 6 Components that represent university faculties. 3 7 4 8 :Test-Layer: unit 5 9 6 Creating faculties 7 ================== 10 Before we can create faculties, we have to grok the :mod:`waeup` 11 package. This happens automatically in real-world use: 12 13 >>> import grok 14 >>> grok.testing.grok('waeup') 15 16 Content Classes (models and containers) 17 ======================================= 18 19 20 :class:`Faculty` 21 ---------------- 22 23 .. class:: Faculty(title=u'Unnamed Faculty'[, title_prefix=u'faculty' [, code=u"NA"]]) 24 25 Create a representation of a university faculty: 26 27 >>> from waeup.university.faculty import Faculty 28 >>> myfac = Faculty() 29 >>> myfac 30 <waeup.university.faculty.Faculty object at 0x...> 31 32 Another way to create :class:`Faculty` instances is by asking 33 for a factory called ``waeup.Faculty``. This way we can create a 34 faculty without importing a class: 35 36 >>> from zope.component import createObject 37 >>> myfac = createObject(u'waeup.Faculty') 38 >>> myfac 39 <waeup.university.faculty.Faculty object at 0x...> 40 41 :class:`Faculty` instances have the attributes required by the 42 `IFaculty` interface: 43 44 >>> from waeup.interfaces import IFaculty 45 >>> IFaculty.providedBy(myfac) 46 True 47 48 >>> from zope.interface.verify import verifyObject 49 >>> verifyObject(IFaculty, myfac) 50 True 51 52 .. method:: addDepartment(department) 53 54 Add a department into this faculty. Faculties are containers for 55 departments. Added objects are checked and only `IDepartment` 56 objects accepted: 57 58 >>> myfac.addDepartment(object()) 59 Traceback (most recent call last): 60 ... 61 TypeError: Faculties contain only IDepartment instances 62 63 >>> list(myfac.values()) 64 [] 65 66 Regular departments are accepted: 67 68 >>> from waeup.university.department import Department 69 >>> myfac.addDepartment(Department(title='Physics', 70 ... code='DP')) 71 72 >>> list(myfac.items()) 73 [(u'DP', <waeup.university.department.Department object at 0x...>)] 74 75 .. method:: clear() 76 77 Remove all departments from this faculty: 78 79 >>> myfac.clear() 80 >>> list(myfac.items()) 81 [] 82 83 .. attribute:: title 84 85 (string) The title of a faculty. 86 87 Each faculty has a title: 88 89 >>> myfac.title 90 u'Unnamed Faculty' 91 92 93 .. attribute:: title_prefix 94 95 (string) The prefix of a faculty. 96 97 Each faculty has a title prefix, which specifies the kind of 98 institution: 99 100 >>> myfac.title_prefix 101 u'faculty' 102 103 104 .. attribute:: code 105 106 (string) An internally used unique code string. 107 108 Each faculty holds a code, which might be a shortcut or 109 abbreviation of the real faculty name. By default the code is 110 ``NA`` (=not assigned): 111 112 >>> myfac.code 113 u'NA' 114 115 116 Utilities 117 ========= 118 119 :class:`FacultyFactory` 120 -------------------------- 121 122 .. class:: FacultyFactory() 123 124 .. attribute:: grok.name(u'waeup.Faculty') 125 126 .. attribute:: grok.implements(IFactory) 127 128 A named utility to deliver new instances of :class:`Faculty` 129 without the need to import the implementation before: 130 131 >>> from zope.component import createObject 132 >>> myfaculty = createObject(u'waeup.Faculty') 133 >>> myfaculty 134 <waeup.university.faculty.Faculty object at 0x...> 135 136 The factory complies with the specifications from the 137 :class:`IFactory` insterface: 138 139 >>> from zope.interface.verify import verifyClass 140 >>> from zope.component.interfaces import IFactory 141 >>> from waeup.university.faculty import FacultyFactory 142 >>> verifyClass(IFactory, FacultyFactory) 143 True 144 145 This means also, that we can get the interfaces of the created 146 object from the factory: 147 148 >>> faculty_factory = FacultyFactory() 149 >>> faculty_factory.getInterfaces() 150 <implementedBy waeup.university.faculty.Faculty> 151 152 153 Examples: 154 ========= 8 155 9 156 We can create faculties: … … 15 162 16 163 Another way to create faculties is by asking for a factory called 17 ``waeup.Faculty``. Before we can do this, we have to grok the `waeup` 18 package. This happens automatically in real-world use: 19 20 >>> import grok 21 >>> grok.testing.grok('waeup') 22 23 Now we can create a factory without importing a class: 164 ``waeup.Faculty``. Now we can create a factory without importing a 165 class: 24 166 25 167 >>> from zope.component import createObject
Note: See TracChangeset for help on using the changeset viewer.