1 | """Interfaces of academics specific objects. |
---|
2 | """ |
---|
3 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
4 | from zope import schema |
---|
5 | try: |
---|
6 | from zope.catalog.interfaces import ICatalog |
---|
7 | except ImportError: |
---|
8 | # BBB |
---|
9 | from zope.app.catalog.interfaces import ICatalog |
---|
10 | from zope.component import getUtility |
---|
11 | from zope.interface import Attribute |
---|
12 | from waeup.sirp.interfaces import (IWAeUPObject, IWAeUPContainer, |
---|
13 | SimpleWAeUPVocabulary) |
---|
14 | |
---|
15 | class CourseSource(BasicSourceFactory): |
---|
16 | """A course source delivers all courses inside the portal by looking |
---|
17 | up a catalog. |
---|
18 | """ |
---|
19 | def getValues(self): |
---|
20 | catalog = getUtility(ICatalog, name='courses_catalog') |
---|
21 | return list(catalog.searchResults(code=('', 'z*'))) |
---|
22 | |
---|
23 | def getToken(self, value): |
---|
24 | return value.code |
---|
25 | |
---|
26 | def getTitle(self, value): |
---|
27 | return "%s %s" % (value.code, value.title[:32]) |
---|
28 | |
---|
29 | class IFaculty(IWAeUPContainer): |
---|
30 | """Representation of a university faculty. |
---|
31 | """ |
---|
32 | code = schema.TextLine( |
---|
33 | title = u'Code', |
---|
34 | description = u'Abbreviated code of the faculty', |
---|
35 | default = u'NA', |
---|
36 | required = True, |
---|
37 | readonly = True, |
---|
38 | ) |
---|
39 | |
---|
40 | title = schema.TextLine( |
---|
41 | title = u'Name of Faculty', |
---|
42 | default = u'Unnamed', |
---|
43 | required = True, |
---|
44 | ) |
---|
45 | |
---|
46 | title_prefix = schema.TextLine( |
---|
47 | title = u'Title prefix', |
---|
48 | default = u'faculty', |
---|
49 | required = True, |
---|
50 | ) |
---|
51 | |
---|
52 | class IFacultyContainer(IWAeUPContainer): |
---|
53 | """A container for faculties. |
---|
54 | """ |
---|
55 | def addFaculty(faculty): |
---|
56 | """Add an IFactulty object. |
---|
57 | |
---|
58 | Returns the key, under which the object was stored. |
---|
59 | """ |
---|
60 | class IDepartment(IWAeUPObject): |
---|
61 | """Representation of a department. |
---|
62 | """ |
---|
63 | code = schema.TextLine( |
---|
64 | title = u'Code', |
---|
65 | default = u'NA', |
---|
66 | description = u'Abbreviated code of the department', |
---|
67 | required = True, |
---|
68 | readonly = True, |
---|
69 | ) |
---|
70 | |
---|
71 | title = schema.TextLine( |
---|
72 | title = u'Name of Department', |
---|
73 | default = u'Unnamed', |
---|
74 | required = True, |
---|
75 | ) |
---|
76 | |
---|
77 | title_prefix = schema.TextLine( |
---|
78 | title = u'Title prefix', |
---|
79 | default = u'department', |
---|
80 | required = True, |
---|
81 | ) |
---|
82 | |
---|
83 | courses = Attribute("A container for courses.") |
---|
84 | certificates = Attribute("A container for certificates.") |
---|
85 | |
---|
86 | |
---|
87 | class ICourseContainer(IWAeUPContainer): |
---|
88 | """A container for faculties. |
---|
89 | """ |
---|
90 | def addCourse(faculty): |
---|
91 | """Add an ICourse object. |
---|
92 | |
---|
93 | Returns the key, under which the object was stored. |
---|
94 | """ |
---|
95 | |
---|
96 | class ICourse(IWAeUPObject): |
---|
97 | """Representation of a course. |
---|
98 | """ |
---|
99 | code = schema.TextLine( |
---|
100 | title = u'Code', |
---|
101 | default = u'NA', |
---|
102 | description = u'Abbreviated code of the course', |
---|
103 | required = True, |
---|
104 | readonly = True, |
---|
105 | ) |
---|
106 | |
---|
107 | title = schema.TextLine( |
---|
108 | title = u'Title of course', |
---|
109 | default = u'Unnamed', |
---|
110 | required = True, |
---|
111 | ) |
---|
112 | |
---|
113 | credits = schema.Int( |
---|
114 | title = u'Credits', |
---|
115 | default = 0, |
---|
116 | required = False, |
---|
117 | ) |
---|
118 | |
---|
119 | passmark = schema.Int( |
---|
120 | title = u'Passmark', |
---|
121 | default = 40, |
---|
122 | required = False, |
---|
123 | ) |
---|
124 | |
---|
125 | semester = schema.Choice( |
---|
126 | title = u'Semester/Term', |
---|
127 | default = 0, |
---|
128 | vocabulary = SimpleWAeUPVocabulary( |
---|
129 | ('N/A', 0), ('First Semester', 1), |
---|
130 | ('Second Semester', 2), ('Combined', 3)), |
---|
131 | required = True, |
---|
132 | ) |
---|
133 | |
---|
134 | |
---|
135 | class ICertificate(IWAeUPObject): |
---|
136 | """Representation of a certificate. |
---|
137 | """ |
---|
138 | code = schema.TextLine( |
---|
139 | title = u'Code', |
---|
140 | default = u'NA', |
---|
141 | description = u'Abbreviated code of the certificate.', |
---|
142 | required = True, |
---|
143 | readonly = True, |
---|
144 | ) |
---|
145 | |
---|
146 | review_state = schema.Choice( |
---|
147 | title = u'Review State', |
---|
148 | default = 'unchecked', |
---|
149 | values = ['unchecked', 'checked'] |
---|
150 | ) |
---|
151 | |
---|
152 | title = schema.TextLine( |
---|
153 | title = u'Title', |
---|
154 | required = True, |
---|
155 | ) |
---|
156 | |
---|
157 | study_mode = schema.TextLine( |
---|
158 | title = u'Study Mode', |
---|
159 | required = True, |
---|
160 | ) |
---|
161 | |
---|
162 | start_level = schema.TextLine( |
---|
163 | title = u'Start Level', |
---|
164 | required = True, |
---|
165 | ) |
---|
166 | |
---|
167 | end_level = schema.TextLine( |
---|
168 | title = u'End Level', |
---|
169 | required = True, |
---|
170 | ) |
---|
171 | |
---|
172 | application_category = schema.TextLine( |
---|
173 | title = u'aApplication Category', |
---|
174 | required = False, |
---|
175 | ) |
---|
176 | |
---|
177 | |
---|
178 | class ICertificateContainer(IWAeUPContainer): |
---|
179 | """A container for certificates. |
---|
180 | """ |
---|
181 | def addCertificate(faculty): |
---|
182 | """Add an ICertificate object. |
---|
183 | |
---|
184 | Returns the key, under which the object was stored. |
---|
185 | """ |
---|
186 | |
---|
187 | class ICertificateCourse(IWAeUPObject): |
---|
188 | """A certificatecourse is a course referenced by a certificate, which |
---|
189 | provides some own attributes. |
---|
190 | """ |
---|
191 | course = schema.Choice( |
---|
192 | title = u'Course', |
---|
193 | source = CourseSource(), |
---|
194 | ) |
---|
195 | |
---|
196 | level = schema.Int( |
---|
197 | title = u'Level of this course', |
---|
198 | required = True, |
---|
199 | default = 100 |
---|
200 | ) |
---|
201 | |
---|
202 | core_or_elective = schema.Bool( |
---|
203 | title = u'Is mandatory course (not elective)', |
---|
204 | required = True, |
---|
205 | default = True |
---|
206 | ) |
---|
207 | |
---|
208 | def getCourseCode(): |
---|
209 | """Return the code of the referenced course. |
---|
210 | |
---|
211 | This is needed for cataloging. |
---|
212 | """ |
---|