source: waeup/branches/ulif-namespace/src/sirp/interfaces.py @ 4915

Last change on this file since 4915 was 4882, checked in by uli, 15 years ago

Add interface for events, fired when datacenter storage moves.

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