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

Last change on this file since 7165 was 7150, checked in by Henrik Bettermann, 13 years ago

Turn all functions subject to customization into methods of a global utility component called StudentsUtils?. This is really an incredible improvement and eases customization a lot.

  • Property svn:keywords set to Id
File size: 10.9 KB
RevLine 
[6621]1##
2## interfaces.py
[7133]3import re
[6996]4from datetime import datetime
[7150]5from zope.interface import Attribute, invariant, Interface
[6756]6from zope.interface.exceptions import Invalid
[6621]7from zope import schema
[6915]8from waeup.sirp.interfaces import IWAeUPObject, academic_sessions_vocab
[6788]9from waeup.sirp.schema import TextLineChoice
[6874]10from waeup.sirp.university.vocabularies import CourseSource, study_modes
[6648]11from waeup.sirp.students.vocabularies import (
[6788]12  CertificateSource, academic_sessions_vocab, verdicts, StudyLevelSource,
[6996]13  contextual_reg_num_source, contextual_mat_num_source, GenderSource,
[6648]14  )
[6877]15from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment
[6621]16
[7133]17# Define a valiation method for email addresses
18class NotAnEmailAddress(schema.ValidationError):
19    __doc__ = u"Invalid email address"
20
21check_email = re.compile(
22    r"[a-zA-Z0-9._%-]+@([a-zA-Z0-9-]+.)*[a-zA-Z]{2,4}").match
23def validate_email(value):
24    if not check_email(value):
25        raise NotAnEmailAddress(value)
26    return True
27
[7150]28class IStudentsUtils(Interface):
29    """A collection of methods which are subject to customization.
30
31    """
32    def get_payment_details(category, student):
33        """Get the payment dates of a student for the payment category
34        specified.
35
36        """
37
38    def get_accommodation_details(student):
39        """Determine the accommodation dates of a student.
40
41        """
42
43    def select_bed(available_beds):
44        """Select a bed from a list of available beds.
45
46        In the standard configuration we select the first bed found,
47        but can also randomize the selection if we like.
48        """
49
50    def render_pdf(view, subject='', filename='slip.pdf',):
51        """Render pdf slips for various pages.
52
53        """
54
[6692]55class IStudentsContainer(IWAeUPObject):
[7096]56    """A students container contains university students.
[6692]57
58    """
59    def addStudent(student):
60        """Add an IStudent object and subcontainers.
61
62        """
63
64    def archive(id=None):
65        """Create on-dist archive of students.
66
67        If id is `None`, all students are archived.
68
69        If id contains a single id string, only the respective
70        students are archived.
71
72        If id contains a list of id strings all of the respective
73        students types are saved to disk.
74        """
75
76    def clear(id=None, archive=True):
77        """Remove students of type given by 'id'.
78
79        Optionally archive the students.
80
81        If id is `None`, all students are archived.
82
83        If id contains a single id string, only the respective
84        students are archived.
85
86        If id contains a list of id strings all of the respective
87        student types are saved to disk.
88
89        If `archive` is ``False`` none of the archive-handling is done
90        and respective students are simply removed from the
91        database.
92        """
93
[6642]94class IStudentNavigation(IWAeUPObject):
95    """Interface needed for student navigation.
[7150]96
[6642]97    """
98    def getStudent():
99        """Return student object.
[7150]100
[6642]101        """
102
[6631]103class IStudentBase(IWAeUPObject):
104    """Representation of student base data.
[7150]105
[6621]106    """
[7062]107    history = Attribute('Object history, a list of messages')
[6637]108    state = Attribute('Returns the registration state of a student')
[6699]109    password = Attribute('Encrypted password of a student')
[6814]110    certificate = Attribute('The certificate of any chosen study course')
[7062]111    current_session = Attribute('The current session of the student')
[6637]112
113    def loggerInfo(ob_class, comment):
[7150]114        """Adds an INFO message to the log file.
115
[6637]116        """
117
[6665]118    student_id = schema.TextLine(
119        title = u'Student ID',
[6849]120        required = False,
[6665]121        )
122
[6818]123    fullname = schema.TextLine(
[6631]124        title = u'Full Name',
[6818]125        default = None,
[6621]126        required = True,
127        )
128
[6996]129    sex = schema.Choice(
130        title = u'Sex',
131        source = GenderSource(),
132        default = u'm',
133        required = True,
134        )
135
[6788]136    reg_number = TextLineChoice(
[6696]137        title = u'Registration Number',
[6818]138        default = None,
[6696]139        required = True,
140        readonly = False,
[6788]141        source = contextual_reg_num_source,
[6696]142        )
143
[6788]144    matric_number = TextLineChoice(
[6750]145        title = u'Matriculation Number',
[6788]146        #default = u'',
[6750]147        required = False,
148        readonly = False,
[6788]149        source = contextual_mat_num_source,
[6750]150        )
151
[6769]152    adm_code = schema.TextLine(
[6935]153        title = u'PWD Activation Code',
[6769]154        default = u'',
155        required = False,
156        readonly = True,
157        )
158
[7133]159    email = schema.ASCIILine(
160        title = u'Email',
161        required = False,
162        constraint=validate_email,
163        )
164    phone = schema.Int(
165        title = u'Phone',
166        description = u'Enter phone number with country code and without spaces.',
167        required = False,
168        )
169
[6631]170class IStudentClearance(IWAeUPObject):
171    """Representation of student clearance data.
[7150]172
[6631]173    """
174    date_of_birth = schema.Date(
175        title = u'Date of Birth',
176        required = True,
177        )
178
[6695]179    clearance_locked = schema.Bool(
180        title = u'Clearance form locked',
181        default = False,
182        )
183
[6769]184    clr_code = schema.TextLine(
[6935]185        title = u'CLR Activation Code',
[6769]186        default = u'',
187        required = False,
188        readonly = True,
189        )
190
[6631]191class IStudentPersonal(IWAeUPObject):
192    """Representation of student personal data.
[7150]193
[6631]194    """
[6651]195    perm_address = schema.Text(
[6631]196        title = u'Permanent Address',
197        required = False,
198        )
199
200class IStudent(IStudentBase,IStudentClearance,IStudentPersonal):
201    """Representation of a student.
[7150]202
[6631]203    """
204
[6849]205class IStudentUpdateByRegNo(IStudent):
206    """Representation of a student. Skip regular reg_number validation.
[7150]207
[6849]208    """
209    reg_number = schema.TextLine(
210        title = u'Registration Number',
211        default = None,
212        required = False,
213        )
214
215class IStudentUpdateByMatricNo(IStudent):
216    """Representation of a student. Skip regular matric_number validation.
[7150]217
[6849]218    """
219    matric_number = schema.TextLine(
220        title = u'Matriculation Number',
221        default = None,
222        required = False,
223        )
224
[6633]225class IStudentStudyCourse(IWAeUPObject):
226    """A container for student study levels.
227
228    """
[6648]229    certificate = schema.Choice(
230        title = u'Certificate',
231        source = CertificateSource(),
232        default = None,
[6633]233        required = True,
234        )
[6635]235
[6996]236
237    entry_mode = schema.Choice(
238        title = u'Entry Mode',
239        vocabulary = study_modes,
240        default = u'ug_ft',
241        required = True,
242        readonly = False,
243        )
244
245    entry_session = schema.Choice(
246        title = u'Entry Session',
247        source = academic_sessions_vocab,
248        default = datetime.now().year,
249        required = True,
250        readonly = False,
251        )
252
[6724]253    current_session = schema.Choice(
254        title = u'Current Session',
[6744]255        source = academic_sessions_vocab,
[6724]256        default = None,
257        required = True,
[6996]258        readonly = False,
[6724]259        )
260
261    current_level = schema.Choice(
262        title = u'Current Level',
[6725]263        source = StudyLevelSource(),
[6724]264        default = None,
[6725]265        required = False,
[6996]266        readonly = False,
[6724]267        )
268
269    current_verdict = schema.Choice(
270        title = u'Current Verdict',
271        source = verdicts,
[6804]272        default = '0',
[6725]273        required = False,
[6724]274        )
275
276    previous_verdict = schema.Choice(
277        title = u'Previous Verdict',
278        source = verdicts,
[6805]279        default = '0',
[6725]280        required = False,
[6724]281        )
282
[6825]283class IStudentStudyCourseImport(IStudentStudyCourse):
284    """A container for student study levels.
285
286    """
287    current_level = schema.Int(
288        title = u'Current Level',
289        default = None,
290        )
291
[6774]292class IStudentStudyLevel(IWAeUPObject):
293    """A container for course tickets.
294
295    """
296    level = Attribute('The level code')
[6793]297    validation_date = Attribute('The date of validation')
298    validated_by = Attribute('User Id of course adviser')
[6774]299
[6793]300    level_session = schema.Choice(
301        title = u'Session',
302        source = academic_sessions_vocab,
303        default = None,
304        required = True,
305        )
[6781]306
[6793]307    level_verdict = schema.Choice(
308        title = u'Verdict',
309        source = verdicts,
[6805]310        default = '0',
[6793]311        required = False,
312        )
313
[6781]314class ICourseTicket(IWAeUPObject):
315    """A course ticket.
316
317    """
[6783]318    code = Attribute('code of the original course')
319    title = Attribute('title of the original course')
320    credits = Attribute('credits of the original course')
321    passmark = Attribute('passmark of the original course')
322    semester = Attribute('semester of the original course')
323    faculty = Attribute('faculty of the original course')
324    department = Attribute('department of the original course')
[6781]325
[6795]326    core_or_elective = schema.Bool(
327        title = u'Mandatory',
328        default = False,
329        required = False,
330        readonly = False,
331        )
332
[6781]333    score = schema.Int(
334        title = u'Score',
335        default = 0,
336        required = False,
337        readonly = False,
338        )
339
[6806]340    automatic = schema.Bool(
341        title = u'Automatical Creation',
342        default = False,
343        required = False,
344        readonly = True,
345        )
346
[6795]347class ICourseTicketAdd(ICourseTicket):
[7150]348    """An interface for adding course tickets.
[6795]349
350    """
351    course = schema.Choice(
352        title = u'Course',
353        source = CourseSource(),
354        readonly = False,
355        )
356
[6635]357class IStudentAccommodation(IWAeUPObject):
358    """A container for student accommodation objects.
359
360    """
361
[6989]362class IBedTicket(IWAeUPObject):
363    """A ticket for accommodation booking.
364
365    """
[6996]366    bed = Attribute('The bed object.')
367
368    bed_coordinates = schema.TextLine(
369        title = u'Bed Coordinates',
[6992]370        default = None,
371        required = False,
[7014]372        readonly = False,
[6992]373        )
374
[6996]375    bed_type = schema.TextLine(
376        title = u'Bed Type',
377        default = None,
378        required = False,
[7014]379        readonly = False,
[6996]380        )
381
[6992]382    booking_session = schema.Choice(
383        title = u'Session',
384        source = academic_sessions_vocab,
385        default = None,
386        required = True,
[7014]387        readonly = True,
[6992]388        )
389
390    booking_date = schema.Datetime(
391        title = u'Booking Date',
392        required = False,
[7014]393        readonly = True,
[6992]394        )
395
396    booking_code = schema.TextLine(
397        title = u'Booking Activation Code',
398        default = u'',
399        required = False,
[7014]400        readonly = True,
[6992]401        )
402
[6994]403    def getSessionString():
[7150]404        """Returns the the title of academic_sessions_vocab term.
405
[6994]406        """
[6992]407
[6860]408class IStudentPaymentsContainer(IPaymentsContainer):
[6635]409    """A container for student payment objects.
410
411    """
412
[6877]413class IStudentOnlinePayment(IOnlinePayment):
414    """A student payment via payment gateways.
415
416    """
417    p_session = schema.Choice(
418        title = u'Payment Session',
419        source = academic_sessions_vocab,
420        required = False,
421        )
422
423IStudentOnlinePayment['p_session'].order = IStudentOnlinePayment[
424    'p_item'].order
425
[6694]426# Interfaces for students only
427
428class IStudentClearanceEdit(IStudentClearance):
429    """Interface needed for restricted editing of student clearance data.
[7150]430
[6694]431    """
432
433class IStudentPersonalEdit(IStudentPersonal):
434    """Interface needed for restricted editing of student personal data.
[7150]435
[6694]436    """
Note: See TracBrowser for help on using the repository browser.