source: main/waeup.sirp/trunk/src/waeup/sirp/interfaces.py @ 5000

Last change on this file since 5000 was 4993, checked in by Henrik Bettermann, 15 years ago

Remove category attribute.
max_pass and application_category must not be required.

  • Property svn:eol-style set to native
File size: 9.9 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.sirp.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    study_mode = schema.TextLine(
220        title = u'study mode',
221        required = True,
222        )
223
224    start_level = schema.TextLine(
225        title = u'start level',
226        required = True,
227        )
228   
229    end_level = schema.TextLine(
230        title = u'end level',
231        required = True,
232        )
233   
234    application_category = schema.TextLine(
235        title = u'application category',
236        required = False,
237        )
238   
239    max_pass = schema.TextLine(
240        title = u'maximum pass',
241        required = False,
242        )
243   
244
245   
246class ICertificateContainer(IWAeUPContainer):
247    """A container for certificates.
248    """
249    def addCertificate(faculty):
250        """Add an ICertificate object.
251
252        Returns the key, under which the object was stored.
253        """
254
255class ICertificateCourse(IWAeUPObject):
256    """A certificatecourse is a course referenced by a certificate, which
257       provides some own attributes.
258    """
259    course = schema.Choice(
260        title = u'Course',
261        source = CourseSource(),
262        )
263   
264    level = schema.Int(
265        title = u'Level of this course',
266        required = True,
267        default = 100
268        )
269
270    core_or_elective = schema.Bool(
271        title = u'Is mandatory course (not elective)',
272        required = True,
273        default = True
274        )
275
276    def getCourseCode():
277        """Return the code of the referenced course.
278
279        This is needed for cataloging.
280        """
281       
282class IWAeUPExporter(Interface):
283    """An exporter for objects.
284    """
285    def export(obj, filepath=None):
286        """Export by pickling.
287
288        Returns a file-like object containing a representation of `obj`.
289
290        This is done using `pickle`. If `filepath` is ``None``, a
291        `cStringIO` object is returned, that contains the saved data.
292        """
293
294class IWAeUPXMLExporter(Interface):
295    """An XML exporter for objects.
296    """
297    def export(obj, filepath=None):
298        """Export as XML.
299
300        Returns an XML representation of `obj`.
301
302        If `filepath` is ``None``, a StringIO` object is returned,
303        that contains the transformed data.
304        """
305
306class IWAeUPXMLImporter(Interface):
307    """An XML import for objects.
308    """
309    def doImport(filepath):
310        """Create Python object from XML.
311
312        Returns a Python object.
313        """
314
315class IBatchProcessor(Interface):
316    """A batch processor that handles mass-operations.
317    """
318    name = schema.TextLine(
319        title = u'Importer name'
320        )
321
322    mode = schema.Choice(
323        title = u'Import mode',
324        values = ['create', 'update', 'remove']
325        )
326   
327    def doImport(path):
328        """Read data from ``path`` and update connected object.
329        """
330
331class ISchemaTypeConverter(Interface):
332    """A converter for zope.schema.types.
333    """
334    def convert(string):
335        """Convert string to certain schema type.
336        """
337
338   
339class IUserAccount(IWAeUPObject):
340    """A user account.
341    """
342    name = schema.TextLine(
343        title = u'User ID',
344        description = u'Loginname',
345        required = True,)
346    title = schema.TextLine(
347        title = u'Username',
348        description = u'Real name',
349        required = False,)
350    description = schema.TextLine(
351        title = u'User description',
352        required = False,)
353    password = schema.Password(
354        title = u'Password',
355        required = True,)
356    roles = schema.List(
357        title = u'Roles',
358        value_type = schema.Choice(source=RoleSource()))
359   
360   
361class IUserContainer(IWAeUPObject):
362    """A container for users (principals).
363
364    These users are used for authentication purposes.
365    """
366
367    def addUser(name, password, title=None, description=None):
368        """Add a user.
369        """
370
371    def delUser(name):
372        """Delete a user if it exists.
373        """
374
375class IDataCenter(IWAeUPObject):
376    """A data center.
377
378    TODO : declare methods, at least those needed by pages.
379    """
380    pass
381
382class IDataCenterFile(Interface):
383    """A data center file.
384    """
385
386    name = schema.TextLine(
387        title = u'Filename')
388
389    size = schema.TextLine(
390        title = u'Human readable file size')
391
392    uploaddate = schema.TextLine(
393        title = u'Human readable upload datetime')
394
395    lines = schema.Int(
396        title = u'Number of lines in file')
397       
398    def getDate():
399        """Get creation timestamp from file in human readable form.
400        """
401
402    def getSize():
403        """Get human readable size of file.
404        """
405
406    def getLinesNumber():
407        """Get number of lines of file.
408        """
409
410class IDataCenterStorageMovedEvent(IObjectEvent):
411    """Emitted, when the storage of a datacenter changes.
412    """
Note: See TracBrowser for help on using the repository browser.