1 | ## |
---|
2 | ## interfaces.py |
---|
3 | from zc.sourcefactory.basic import BasicSourceFactory |
---|
4 | from zope.component import getUtility |
---|
5 | from zope.app.catalog.interfaces import ICatalog |
---|
6 | from zope.interface import Interface, Attribute |
---|
7 | from zope import schema |
---|
8 | from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm |
---|
9 | from waeup.permissions import RoleSource |
---|
10 | |
---|
11 | def SimpleWAeUPVocabulary(*terms): |
---|
12 | """A well-buildt vocabulary provides terms with a value, token and |
---|
13 | title for each term |
---|
14 | """ |
---|
15 | return SimpleVocabulary([ |
---|
16 | SimpleTerm(value, value, title) for title, value in terms]) |
---|
17 | |
---|
18 | |
---|
19 | class CourseSource(BasicSourceFactory): |
---|
20 | """A course source delivers all courses inside the portal by looking |
---|
21 | up a catalog. |
---|
22 | """ |
---|
23 | catalog = None |
---|
24 | def getValues(self): |
---|
25 | if self.catalog is None: |
---|
26 | self.catalog = getUtility(ICatalog, name='courses_catalog') |
---|
27 | return list(self.catalog.searchResults(code=('', 'z*'))) |
---|
28 | |
---|
29 | def getTitle(self, value): |
---|
30 | return "%s %s" % (value.code, value.title[:32]) |
---|
31 | |
---|
32 | |
---|
33 | class IWAeUPObject(Interface): |
---|
34 | """A WAeUP object. |
---|
35 | """ |
---|
36 | |
---|
37 | class IUniversity(IWAeUPObject): |
---|
38 | """Representation of a university. |
---|
39 | """ |
---|
40 | name = schema.TextLine( |
---|
41 | title = u'Name of University', |
---|
42 | default = u'Unnamed', |
---|
43 | required = True, |
---|
44 | ) |
---|
45 | |
---|
46 | faculties = Attribute("A container for faculties.") |
---|
47 | students = Attribute("A container for students.") |
---|
48 | hostels = Attribute("A container for hostels.") |
---|
49 | |
---|
50 | class IWAeUPContainer(IWAeUPObject): |
---|
51 | """A container for WAeUP objects. |
---|
52 | """ |
---|
53 | |
---|
54 | class IWAeUPContained(IWAeUPObject): |
---|
55 | """An item contained in an IWAeUPContainer. |
---|
56 | """ |
---|
57 | |
---|
58 | class IStudentContainer(IWAeUPContainer): |
---|
59 | """A container for StudentObjects. |
---|
60 | """ |
---|
61 | |
---|
62 | class IFaculty(IWAeUPContainer): |
---|
63 | """Representation of a university faculty. |
---|
64 | """ |
---|
65 | title = schema.TextLine( |
---|
66 | title = u'Name of Faculty', |
---|
67 | default = u'Unnamed', |
---|
68 | required = True, |
---|
69 | ) |
---|
70 | |
---|
71 | title_prefix = schema.TextLine( |
---|
72 | title = u'Title prefix', |
---|
73 | default = u'faculty', |
---|
74 | required = True, |
---|
75 | ) |
---|
76 | |
---|
77 | code = schema.TextLine( |
---|
78 | title = u'Code', |
---|
79 | description = u'Abbreviated code of the faculty', |
---|
80 | default = u'NA', |
---|
81 | required = True, |
---|
82 | ) |
---|
83 | |
---|
84 | class IFacultyContainer(IWAeUPContainer): |
---|
85 | """A container for faculties. |
---|
86 | """ |
---|
87 | def addFaculty(faculty): |
---|
88 | """Add an IFactulty object. |
---|
89 | |
---|
90 | Returns the key, under which the object was stored. |
---|
91 | """ |
---|
92 | |
---|
93 | class IHostelContainer(IWAeUPContainer): |
---|
94 | """A container for hostels. |
---|
95 | """ |
---|
96 | def addHostel(hostel): |
---|
97 | """Add an IHostel object. |
---|
98 | |
---|
99 | Returns the key, under which the object was stored. |
---|
100 | """ |
---|
101 | |
---|
102 | class IHostel(IWAeUPObject): |
---|
103 | """Representation of a hostel. |
---|
104 | """ |
---|
105 | name = schema.TextLine( |
---|
106 | title = u'Name of Hostel', |
---|
107 | default = u'Nobody', |
---|
108 | required = True, |
---|
109 | ) |
---|
110 | |
---|
111 | class IDepartment(IWAeUPObject): |
---|
112 | """Representation of a department. |
---|
113 | """ |
---|
114 | title = schema.TextLine( |
---|
115 | title = u'Name of Department', |
---|
116 | default = u'Unnamed', |
---|
117 | required = True, |
---|
118 | ) |
---|
119 | |
---|
120 | title_prefix = schema.TextLine( |
---|
121 | title = u'Title prefix', |
---|
122 | default = u'department', |
---|
123 | required = True, |
---|
124 | ) |
---|
125 | |
---|
126 | code = schema.TextLine( |
---|
127 | title = u'Code', |
---|
128 | default = u'NA', |
---|
129 | description = u'Abbreviated code of the department', |
---|
130 | required = True, |
---|
131 | ) |
---|
132 | |
---|
133 | courses = Attribute("A container for courses.") |
---|
134 | certificates = Attribute("A container for certificates.") |
---|
135 | |
---|
136 | |
---|
137 | class ICourseContainer(IWAeUPContainer): |
---|
138 | """A container for faculties. |
---|
139 | """ |
---|
140 | def addCourse(faculty): |
---|
141 | """Add an ICourse object. |
---|
142 | |
---|
143 | Returns the key, under which the object was stored. |
---|
144 | """ |
---|
145 | |
---|
146 | class ICourse(IWAeUPObject): |
---|
147 | """Representation of a course. |
---|
148 | """ |
---|
149 | code = schema.TextLine( |
---|
150 | title = u'Code', |
---|
151 | default = u'NA', |
---|
152 | description = u'Abbreviated code of the course', |
---|
153 | required = True, |
---|
154 | readonly = True, |
---|
155 | ) |
---|
156 | |
---|
157 | title = schema.TextLine( |
---|
158 | title = u'Title of course', |
---|
159 | default = u'Unnamed', |
---|
160 | required = True, |
---|
161 | ) |
---|
162 | |
---|
163 | level = schema.TextLine( |
---|
164 | title = u'Level', |
---|
165 | default = u'100', |
---|
166 | required = False, |
---|
167 | ) |
---|
168 | |
---|
169 | credits = schema.Int( |
---|
170 | title = u'Credits', |
---|
171 | default = 0, |
---|
172 | required = False, |
---|
173 | ) |
---|
174 | |
---|
175 | passmark = schema.Int( |
---|
176 | title = u'Passmark', |
---|
177 | default = 40, |
---|
178 | required = False, |
---|
179 | ) |
---|
180 | |
---|
181 | semester = schema.Choice( |
---|
182 | title = u'Semester/Term', |
---|
183 | default = 0, |
---|
184 | vocabulary = SimpleWAeUPVocabulary( |
---|
185 | ('N/A', 0), ('First Semester', 1), |
---|
186 | ('Second Semester', 2), ('Combined', 3)), |
---|
187 | required = True, |
---|
188 | ) |
---|
189 | |
---|
190 | |
---|
191 | class ICertificate(IWAeUPObject): |
---|
192 | """Representation of a certificate. |
---|
193 | """ |
---|
194 | code = schema.TextLine( |
---|
195 | title = u'Code', |
---|
196 | default = u'NA', |
---|
197 | description = u'Abbreviated code of the certificate.', |
---|
198 | required = True, |
---|
199 | ) |
---|
200 | |
---|
201 | review_state = schema.Choice( |
---|
202 | title = u'review state', |
---|
203 | values = ['unchecked', 'checked'] |
---|
204 | ) |
---|
205 | |
---|
206 | title = schema.TextLine( |
---|
207 | title = u'title', |
---|
208 | required = True, |
---|
209 | ) |
---|
210 | |
---|
211 | category = schema.TextLine( |
---|
212 | title = u'category', |
---|
213 | required = True, |
---|
214 | ) |
---|
215 | |
---|
216 | study_mode = schema.TextLine( |
---|
217 | title = u'study mode', |
---|
218 | required = True, |
---|
219 | ) |
---|
220 | |
---|
221 | start_level = schema.TextLine( |
---|
222 | title = u'start level', |
---|
223 | required = True, |
---|
224 | ) |
---|
225 | |
---|
226 | end_level = schema.TextLine( |
---|
227 | title = u'end level', |
---|
228 | required = True, |
---|
229 | ) |
---|
230 | |
---|
231 | application_category = schema.TextLine( |
---|
232 | title = u'application category', |
---|
233 | required = True, |
---|
234 | ) |
---|
235 | |
---|
236 | m_prefix = schema.TextLine( |
---|
237 | title = u'prefix', |
---|
238 | required = True, |
---|
239 | ) |
---|
240 | |
---|
241 | max_pass = schema.TextLine( |
---|
242 | title = u'maximum pass', |
---|
243 | required = True, |
---|
244 | ) |
---|
245 | |
---|
246 | |
---|
247 | |
---|
248 | class ICertificateContainer(IWAeUPContainer): |
---|
249 | """A container for certificates. |
---|
250 | """ |
---|
251 | def addCertificate(faculty): |
---|
252 | """Add an ICertificate object. |
---|
253 | |
---|
254 | Returns the key, under which the object was stored. |
---|
255 | """ |
---|
256 | |
---|
257 | class ICertificateCourse(IWAeUPObject): |
---|
258 | """A certificatecourse is a course referenced by a certificate, which |
---|
259 | provides some own attributes. |
---|
260 | """ |
---|
261 | course = schema.Choice( |
---|
262 | title = u'Course', |
---|
263 | source = CourseSource(), |
---|
264 | ) |
---|
265 | |
---|
266 | level = schema.Int( |
---|
267 | title = u'Level of this course', |
---|
268 | required = True, |
---|
269 | default = 100 |
---|
270 | ) |
---|
271 | |
---|
272 | core_or_elective = schema.Bool( |
---|
273 | title = u'Is mandatory course (not elective)', |
---|
274 | required = True, |
---|
275 | default = True |
---|
276 | ) |
---|
277 | |
---|
278 | def getCourseCode(): |
---|
279 | """Return the code of the referenced course. |
---|
280 | |
---|
281 | This is needed for cataloging. |
---|
282 | """ |
---|
283 | |
---|
284 | class IWAeUPExporter(Interface): |
---|
285 | """An exporter for objects. |
---|
286 | """ |
---|
287 | def export(obj, filepath=None): |
---|
288 | """Export by pickling. |
---|
289 | |
---|
290 | Returns a file-like object containing a representation of `obj`. |
---|
291 | |
---|
292 | This is done using `pickle`. If `filepath` is ``None``, a |
---|
293 | `cStringIO` object is returned, that contains the saved data. |
---|
294 | """ |
---|
295 | |
---|
296 | class IWAeUPXMLExporter(Interface): |
---|
297 | """An XML exporter for objects. |
---|
298 | """ |
---|
299 | def export(obj, filepath=None): |
---|
300 | """Export as XML. |
---|
301 | |
---|
302 | Returns an XML representation of `obj`. |
---|
303 | |
---|
304 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
305 | that contains the transformed data. |
---|
306 | """ |
---|
307 | |
---|
308 | class IWAeUPXMLImporter(Interface): |
---|
309 | """An XML import for objects. |
---|
310 | """ |
---|
311 | def doImport(filepath): |
---|
312 | """Create Python object from XML. |
---|
313 | |
---|
314 | Returns a Python object. |
---|
315 | """ |
---|
316 | |
---|
317 | class IWAeUPCSVExporter(Interface): |
---|
318 | """A CSV exporter for objects. |
---|
319 | """ |
---|
320 | |
---|
321 | def export(obj, filepath=None): |
---|
322 | """Export as CSV. |
---|
323 | |
---|
324 | Returns a CSV representation of `obj`. |
---|
325 | |
---|
326 | If `filepath` is ``None``, a StringIO` object is returned, |
---|
327 | that contains the transformed data. |
---|
328 | """ |
---|
329 | |
---|
330 | class IWAeUPCSVImporter(Interface): |
---|
331 | """A CSV importer for objects. |
---|
332 | """ |
---|
333 | datatype = schema.TextLine( |
---|
334 | title = u'Data type', |
---|
335 | description = u'Type of data supported by this filter.', |
---|
336 | required = True,) |
---|
337 | |
---|
338 | def doImport(clear_old_data=True, overwrite=True): |
---|
339 | """Read data from `filepath` and apply data. |
---|
340 | |
---|
341 | It depends on the context, what 'applying data' means here. |
---|
342 | |
---|
343 | If `clear_old_data` is False, old data will be |
---|
344 | preserved. Otherwise all old data will get lost. |
---|
345 | |
---|
346 | If `overwrite` is False, any existing entries with similar |
---|
347 | keys might be overwritten. This option is ignored, when |
---|
348 | `clear_old_data` is set to True. |
---|
349 | """ |
---|
350 | |
---|
351 | class IUserAccount(IWAeUPObject): |
---|
352 | """A user account. |
---|
353 | """ |
---|
354 | name = schema.TextLine( |
---|
355 | title = u'User ID', |
---|
356 | description = u'Loginname', |
---|
357 | required = True,) |
---|
358 | title = schema.TextLine( |
---|
359 | title = u'Username', |
---|
360 | description = u'Real name', |
---|
361 | required = False,) |
---|
362 | description = schema.TextLine( |
---|
363 | title = u'User description', |
---|
364 | required = False,) |
---|
365 | password = schema.Password( |
---|
366 | title = u'Password', |
---|
367 | required = True,) |
---|
368 | roles = schema.List( |
---|
369 | title = u'Roles', |
---|
370 | value_type = schema.Choice(source=RoleSource())) |
---|
371 | |
---|
372 | |
---|
373 | class IUserContainer(IWAeUPObject): |
---|
374 | """A container for users (principals). |
---|
375 | |
---|
376 | These users are used for authentication purposes. |
---|
377 | """ |
---|
378 | |
---|
379 | def addUser(name, password, title=None, description=None): |
---|
380 | """Add a user. |
---|
381 | """ |
---|
382 | |
---|
383 | def delUser(name): |
---|
384 | """Delete a user if it exists. |
---|
385 | """ |
---|
386 | |
---|
387 | class IDataCenter(IWAeUPObject): |
---|
388 | """A data center. |
---|
389 | |
---|
390 | TODO : declare methods, at least those needed by pages. |
---|
391 | """ |
---|
392 | pass |
---|
393 | |
---|
394 | class ICSVDataReceivers(Interface): |
---|
395 | """An object containing things ready for CSV imports. |
---|
396 | |
---|
397 | This is pure marker interface. Objects that implement it, indicate |
---|
398 | that they might provide attributes, which are able to receive CSV |
---|
399 | data, i.e. for which an IWAeUPCSVDataImporter exists. |
---|
400 | """ |
---|
401 | |
---|
402 | class IDataCenterFile(Interface): |
---|
403 | """A data center file. |
---|
404 | """ |
---|
405 | def getDate(): |
---|
406 | """Get creation timestamp from file in human readable form. |
---|
407 | """ |
---|
408 | |
---|
409 | def getSize(): |
---|
410 | """Get human readable size of file. |
---|
411 | """ |
---|