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

Last change on this file since 4987 was 4969, checked in by uli, 15 years ago

Remove quick-import related interfaces.

  • Property svn:eol-style set to native
File size: 10.0 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    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 IBatchProcessor(Interface):
319    """A batch processor that handles mass-operations.
320    """
321    name = schema.TextLine(
322        title = u'Importer name'
323        )
324
325    mode = schema.Choice(
326        title = u'Import mode',
327        values = ['create', 'update', 'remove']
328        )
329   
330    def doImport(path):
331        """Read data from ``path`` and update connected object.
332        """
333
334class ISchemaTypeConverter(Interface):
335    """A converter for zope.schema.types.
336    """
337    def convert(string):
338        """Convert string to certain schema type.
339        """
340
341   
342class IUserAccount(IWAeUPObject):
343    """A user account.
344    """
345    name = schema.TextLine(
346        title = u'User ID',
347        description = u'Loginname',
348        required = True,)
349    title = schema.TextLine(
350        title = u'Username',
351        description = u'Real name',
352        required = False,)
353    description = schema.TextLine(
354        title = u'User description',
355        required = False,)
356    password = schema.Password(
357        title = u'Password',
358        required = True,)
359    roles = schema.List(
360        title = u'Roles',
361        value_type = schema.Choice(source=RoleSource()))
362   
363   
364class IUserContainer(IWAeUPObject):
365    """A container for users (principals).
366
367    These users are used for authentication purposes.
368    """
369
370    def addUser(name, password, title=None, description=None):
371        """Add a user.
372        """
373
374    def delUser(name):
375        """Delete a user if it exists.
376        """
377
378class IDataCenter(IWAeUPObject):
379    """A data center.
380
381    TODO : declare methods, at least those needed by pages.
382    """
383    pass
384
385class IDataCenterFile(Interface):
386    """A data center file.
387    """
388
389    name = schema.TextLine(
390        title = u'Filename')
391
392    size = schema.TextLine(
393        title = u'Human readable file size')
394
395    uploaddate = schema.TextLine(
396        title = u'Human readable upload datetime')
397
398    lines = schema.Int(
399        title = u'Number of lines in file')
400       
401    def getDate():
402        """Get creation timestamp from file in human readable form.
403        """
404
405    def getSize():
406        """Get human readable size of file.
407        """
408
409    def getLinesNumber():
410        """Get number of lines of file.
411        """
412
413class IDataCenterStorageMovedEvent(IObjectEvent):
414    """Emitted, when the storage of a datacenter changes.
415    """
Note: See TracBrowser for help on using the repository browser.