source: main/waeup.kofa/trunk/src/waeup/kofa/students/interfaces.py @ 8408

Last change on this file since 8408 was 8408, checked in by uli, 13 years ago

Extend interfaces for StudentsContainer? (require attribute to deliver
a unique student ID) and introduce a more specialized interface for
CSV export of students.

  • Property svn:keywords set to Id
File size: 13.9 KB
Line 
1## $Id: interfaces.py 8408 2012-05-10 16:33:38Z uli $
2##
3## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann
4## This program is free software; you can redistribute it and/or modify
5## it under the terms of the GNU General Public License as published by
6## the Free Software Foundation; either version 2 of the License, or
7## (at your option) any later version.
8##
9## This program is distributed in the hope that it will be useful,
10## but WITHOUT ANY WARRANTY; without even the implied warranty of
11## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12## GNU General Public License for more details.
13##
14## You should have received a copy of the GNU General Public License
15## along with this program; if not, write to the Free Software
16## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17##
18from datetime import datetime
19from zope.component import getUtility
20from zope.interface import Attribute, Interface
21from zope import schema
22from zc.sourcefactory.contextual import BasicContextualSourceFactory
23from waeup.kofa.interfaces import (
24    IKofaObject, academic_sessions_vocab, validate_email, IKofaUtils,
25    ICSVExporter)
26from waeup.kofa.interfaces import MessageFactory as _
27from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber
28from waeup.kofa.students.vocabularies import (
29    StudyLevelSource, contextual_reg_num_source, contextual_mat_num_source,
30    GenderSource, nats_vocab,
31    )
32from waeup.kofa.payments.interfaces import (
33    IPaymentsContainer, IOnlinePayment)
34from waeup.kofa.university.vocabularies import (
35    CourseSource, StudyModeSource, CertificateSource)
36
37# VerdictSource can't be placed into the vocabularies module because it
38# requires importing IStudentsUtils which then leads to circular imports.
39class VerdictSource(BasicContextualSourceFactory):
40    """A verdicts source delivers all verdicts provided
41    in the portal.
42    """
43    def getValues(self, context):
44        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
45        return verdicts_dict.keys()
46
47    def getToken(self, context, value):
48        return value
49
50    def getTitle(self, context, value):
51        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
52        return verdicts_dict[value]
53
54
55class IStudentsUtils(Interface):
56    """A collection of methods which are subject to customization.
57
58    """
59    def setReturningData(student):
60        """ This method defines what happens after school fee payment
61        depending on the student's senate verdict.
62
63        In the base configuration current level is always increased
64        by 100 no matter which verdict has been assigned.
65        """
66
67    def getPaymentDetails(category, student):
68        """Get the payment dates of a student for the payment category
69        specified.
70
71        """
72
73    def getAccommodation_details(student):
74        """Determine the accommodation dates of a student.
75
76        """
77
78    def selectBed(available_beds):
79        """Select a bed from a list of available beds.
80
81        In the standard configuration we select the first bed found,
82        but can also randomize the selection if we like.
83        """
84
85    def renderPDF(view, subject='', filename='slip.pdf',):
86        """Render pdf slips for various pages.
87
88        """
89
90class IStudentsContainer(IKofaObject):
91    """A students container contains university students.
92
93    """
94    def addStudent(student):
95        """Add an IStudent object and subcontainers.
96
97        """
98
99    def archive(id=None):
100        """Create on-dist archive of students.
101
102        If id is `None`, all students are archived.
103
104        If id contains a single id string, only the respective
105        students are archived.
106
107        If id contains a list of id strings all of the respective
108        students types are saved to disk.
109        """
110
111    def clear(id=None, archive=True):
112        """Remove students of type given by 'id'.
113
114        Optionally archive the students.
115
116        If id is `None`, all students are archived.
117
118        If id contains a single id string, only the respective
119        students are archived.
120
121        If id contains a list of id strings all of the respective
122        student types are saved to disk.
123
124        If `archive` is ``False`` none of the archive-handling is done
125        and respective students are simply removed from the
126        database.
127        """
128
129    unique_student_id = Attribute("""A unique student id.""")
130
131class IStudentNavigation(IKofaObject):
132    """Interface needed for student navigation.
133
134    """
135    def getStudent():
136        """Return student object.
137
138        """
139
140class IStudentBase(IKofaObject):
141    """Representation of student base data.
142
143    """
144    history = Attribute('Object history, a list of messages')
145    state = Attribute('Returns the registration state of a student')
146    password = Attribute('Encrypted password of a student')
147    certcode = Attribute('The certificate code of any chosen study course')
148    depcode = Attribute('The department code of any chosen study course')
149    faccode = Attribute('The faculty code of any chosen study course')
150    current_session = Attribute('The current session of the student')
151    current_mode = Attribute('The current mode of the student')
152    fullname = Attribute('All name parts separated by hyphens')
153    display_fullname = Attribute('The fullname of an applicant')
154
155    def loggerInfo(ob_class, comment):
156        """Adds an INFO message to the log file.
157
158        """
159
160    student_id = schema.TextLine(
161        title = _(u'Student Id'),
162        required = False,
163        )
164
165    firstname = schema.TextLine(
166        title = _(u'First Name'),
167        required = True,
168        )
169
170    middlename = schema.TextLine(
171        title = _(u'Middle Name'),
172        required = False,
173        )
174
175    lastname = schema.TextLine(
176        title = _(u'Last Name (Surname)'),
177        required = True,
178        )
179
180    sex = schema.Choice(
181        title = _(u'Sex'),
182        source = GenderSource(),
183        required = True,
184        )
185
186    reg_number = TextLineChoice(
187        title = _(u'Registration Number'),
188        required = True,
189        readonly = False,
190        source = contextual_reg_num_source,
191        )
192
193    matric_number = TextLineChoice(
194        title = _(u'Matriculation Number'),
195        required = False,
196        readonly = False,
197        source = contextual_mat_num_source,
198        )
199
200    adm_code = schema.TextLine(
201        title = _(u'PWD Activation Code'),
202        required = False,
203        readonly = True,
204        )
205
206    email = schema.ASCIILine(
207        title = _(u'Email'),
208        required = False,
209        constraint=validate_email,
210        )
211    phone = PhoneNumber(
212        title = _(u'Phone'),
213        description = u'',
214        required = False,
215        )
216
217class IUGStudentClearance(IKofaObject):
218    """Representation of undergraduate student clearance data.
219
220    """
221    date_of_birth = FormattedDate(
222        title = _(u'Date of Birth'),
223        required = True,
224        show_year = True,
225        )
226
227    clearance_locked = schema.Bool(
228        title = _(u'Clearance form locked'),
229        default = False,
230        )
231
232    clr_code = schema.TextLine(
233        title = _(u'CLR Activation Code'),
234        required = False,
235        readonly = True,
236        )
237
238    nationality = schema.Choice(
239        vocabulary = nats_vocab,
240        title = _(u'Nationality'),
241        required = False,
242        )
243
244class IPGStudentClearance(IUGStudentClearance):
245    """Representation of postgraduate student clearance data.
246
247    """
248    employer = schema.TextLine(
249        title = _(u'Employer'),
250        required = False,
251        readonly = False,
252        )
253
254class IStudentPersonal(IKofaObject):
255    """Representation of student personal data.
256
257    """
258    perm_address = schema.Text(
259        title = _(u'Permanent Address'),
260        required = False,
261        )
262
263class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,
264    IStudentPersonal):
265    """Representation of a student.
266
267    """
268
269class IStudentUpdateByRegNo(IStudent):
270    """Representation of a student. Skip regular reg_number validation.
271
272    """
273    reg_number = schema.TextLine(
274        title = _(u'Registration Number'),
275        required = False,
276        )
277
278class IStudentUpdateByMatricNo(IStudent):
279    """Representation of a student. Skip regular matric_number validation.
280
281    """
282    matric_number = schema.TextLine(
283        title = _(u'Matriculation Number'),
284        required = False,
285        )
286
287class IStudentStudyCourse(IKofaObject):
288    """A container for student study levels.
289
290    """
291    certificate = schema.Choice(
292        title = _(u'Certificate'),
293        source = CertificateSource(),
294        required = False,
295        )
296
297    entry_mode = schema.Choice(
298        title = _(u'Entry Mode'),
299        source = StudyModeSource(),
300        required = True,
301        readonly = False,
302        )
303
304    entry_session = schema.Choice(
305        title = _(u'Entry Session'),
306        source = academic_sessions_vocab,
307        #default = datetime.now().year,
308        required = True,
309        readonly = False,
310        )
311
312    current_session = schema.Choice(
313        title = _(u'Current Session'),
314        source = academic_sessions_vocab,
315        required = True,
316        readonly = False,
317        )
318
319    current_level = schema.Choice(
320        title = _(u'Current Level'),
321        source = StudyLevelSource(),
322        required = False,
323        readonly = False,
324        )
325
326    current_verdict = schema.Choice(
327        title = _(u'Current Verdict'),
328        source = VerdictSource(),
329        default = '0',
330        required = False,
331        )
332
333    previous_verdict = schema.Choice(
334        title = _(u'Previous Verdict'),
335        source = VerdictSource(),
336        default = '0',
337        required = False,
338        )
339
340class IStudentVerdictUpdate(IKofaObject):
341    """A interface for verdict imports.
342
343    """
344
345    current_verdict = schema.Choice(
346        title = _(u'Current Verdict'),
347        source = VerdictSource(),
348        required = True,
349        )
350
351    current_session = schema.Choice(
352        title = _(u'Current Session'),
353        source = academic_sessions_vocab,
354        required = True,
355        )
356
357    current_level = schema.Choice(
358        title = _(u'Current Level'),
359        source = StudyLevelSource(),
360        required = True,
361        )
362
363class IStudentStudyLevel(IKofaObject):
364    """A container for course tickets.
365
366    """
367    level = Attribute('The level code')
368    validation_date = Attribute('The date of validation')
369    validated_by = Attribute('User Id of course adviser')
370
371    level_session = schema.Choice(
372        title = _(u'Session'),
373        source = academic_sessions_vocab,
374        required = True,
375        )
376
377    level_verdict = schema.Choice(
378        title = _(u'Verdict'),
379        source = VerdictSource(),
380        default = '0',
381        required = False,
382        )
383
384    def addCourseTicket(courseticket):
385        """Add a course ticket object.
386        """
387
388    def getStudent():
389        """Return student
390        """
391
392class ICourseTicket(IKofaObject):
393    """A course ticket.
394
395    """
396    code = Attribute('code of the original course')
397    title = Attribute('title of the original course')
398    credits = Attribute('credits of the original course')
399    passmark = Attribute('passmark of the original course')
400    semester = Attribute('semester of the original course')
401    fcode = Attribute('faculty code of the original course')
402    dcode = Attribute('department code of the original course')
403
404    mandatory = schema.Bool(
405        title = _(u'Mandatory'),
406        default = False,
407        required = False,
408        readonly = False,
409        )
410
411    score = schema.Int(
412        title = _(u'Score'),
413        default = 0,
414        required = False,
415        readonly = False,
416        )
417
418    automatic = schema.Bool(
419        title = _(u'Automatical Creation'),
420        default = False,
421        required = False,
422        readonly = True,
423        )
424
425    carry_over = schema.Bool(
426        title = _(u'Carry-over Course'),
427        default = False,
428        required = False,
429        readonly = False,
430        )
431
432    def getLevel():
433        """Returns the id of the level the ticket has been added to.
434        """
435
436    def getLevelSession():
437        """Returns the session of the level the ticket has been added to.
438        """
439
440class ICourseTicketAdd(ICourseTicket):
441    """An interface for adding course tickets.
442
443    """
444    course = schema.Choice(
445        title = _(u'Course'),
446        source = CourseSource(),
447        readonly = False,
448        )
449
450class IStudentAccommodation(IKofaObject):
451    """A container for student accommodation objects.
452
453    """
454
455class IBedTicket(IKofaObject):
456    """A ticket for accommodation booking.
457
458    """
459    bed = Attribute('The bed object.')
460
461    bed_coordinates = schema.TextLine(
462        title = _(u'Bed Coordinates'),
463        required = False,
464        readonly = False,
465        )
466
467    bed_type = schema.TextLine(
468        title = _(u'Bed Type'),
469        required = False,
470        readonly = False,
471        )
472
473    booking_session = schema.Choice(
474        title = _(u'Session'),
475        source = academic_sessions_vocab,
476        required = True,
477        readonly = True,
478        )
479
480    booking_date = schema.Datetime(
481        title = _(u'Booking Date'),
482        required = False,
483        readonly = True,
484        )
485
486    booking_code = schema.TextLine(
487        title = _(u'Booking Activation Code'),
488        required = False,
489        readonly = True,
490        )
491
492    def getSessionString():
493        """Returns the title of academic_sessions_vocab term.
494
495        """
496
497class IStudentPaymentsContainer(IPaymentsContainer):
498    """A container for student payment objects.
499
500    """
501
502class IStudentOnlinePayment(IOnlinePayment):
503    """A student payment via payment gateways.
504
505    """
506
507    p_level = schema.Int(
508        title = _(u'Payment Level'),
509        required = False,
510        readonly = True,
511        )
512
513IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
514    'p_session'].order
515
516class ICSVStudentExporter(ICSVExporter):
517    """A regular ICSVExporter that additionally supports exporting
518      data from a given student object.
519    """
520
521    def export_student(student, filepath=None):
522        """Export data for a given student.
523        """
Note: See TracBrowser for help on using the repository browser.