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

Last change on this file since 7156 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
Line 
1##
2## interfaces.py
3import re
4from datetime import datetime
5from zope.interface import Attribute, invariant, Interface
6from zope.interface.exceptions import Invalid
7from zope import schema
8from waeup.sirp.interfaces import IWAeUPObject, academic_sessions_vocab
9from waeup.sirp.schema import TextLineChoice
10from waeup.sirp.university.vocabularies import CourseSource, study_modes
11from waeup.sirp.students.vocabularies import (
12  CertificateSource, academic_sessions_vocab, verdicts, StudyLevelSource,
13  contextual_reg_num_source, contextual_mat_num_source, GenderSource,
14  )
15from waeup.sirp.payments.interfaces import IPaymentsContainer, IOnlinePayment
16
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
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
55class IStudentsContainer(IWAeUPObject):
56    """A students container contains university students.
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
94class IStudentNavigation(IWAeUPObject):
95    """Interface needed for student navigation.
96
97    """
98    def getStudent():
99        """Return student object.
100
101        """
102
103class IStudentBase(IWAeUPObject):
104    """Representation of student base data.
105
106    """
107    history = Attribute('Object history, a list of messages')
108    state = Attribute('Returns the registration state of a student')
109    password = Attribute('Encrypted password of a student')
110    certificate = Attribute('The certificate of any chosen study course')
111    current_session = Attribute('The current session of the student')
112
113    def loggerInfo(ob_class, comment):
114        """Adds an INFO message to the log file.
115
116        """
117
118    student_id = schema.TextLine(
119        title = u'Student ID',
120        required = False,
121        )
122
123    fullname = schema.TextLine(
124        title = u'Full Name',
125        default = None,
126        required = True,
127        )
128
129    sex = schema.Choice(
130        title = u'Sex',
131        source = GenderSource(),
132        default = u'm',
133        required = True,
134        )
135
136    reg_number = TextLineChoice(
137        title = u'Registration Number',
138        default = None,
139        required = True,
140        readonly = False,
141        source = contextual_reg_num_source,
142        )
143
144    matric_number = TextLineChoice(
145        title = u'Matriculation Number',
146        #default = u'',
147        required = False,
148        readonly = False,
149        source = contextual_mat_num_source,
150        )
151
152    adm_code = schema.TextLine(
153        title = u'PWD Activation Code',
154        default = u'',
155        required = False,
156        readonly = True,
157        )
158
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
170class IStudentClearance(IWAeUPObject):
171    """Representation of student clearance data.
172
173    """
174    date_of_birth = schema.Date(
175        title = u'Date of Birth',
176        required = True,
177        )
178
179    clearance_locked = schema.Bool(
180        title = u'Clearance form locked',
181        default = False,
182        )
183
184    clr_code = schema.TextLine(
185        title = u'CLR Activation Code',
186        default = u'',
187        required = False,
188        readonly = True,
189        )
190
191class IStudentPersonal(IWAeUPObject):
192    """Representation of student personal data.
193
194    """
195    perm_address = schema.Text(
196        title = u'Permanent Address',
197        required = False,
198        )
199
200class IStudent(IStudentBase,IStudentClearance,IStudentPersonal):
201    """Representation of a student.
202
203    """
204
205class IStudentUpdateByRegNo(IStudent):
206    """Representation of a student. Skip regular reg_number validation.
207
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.
217
218    """
219    matric_number = schema.TextLine(
220        title = u'Matriculation Number',
221        default = None,
222        required = False,
223        )
224
225class IStudentStudyCourse(IWAeUPObject):
226    """A container for student study levels.
227
228    """
229    certificate = schema.Choice(
230        title = u'Certificate',
231        source = CertificateSource(),
232        default = None,
233        required = True,
234        )
235
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
253    current_session = schema.Choice(
254        title = u'Current Session',
255        source = academic_sessions_vocab,
256        default = None,
257        required = True,
258        readonly = False,
259        )
260
261    current_level = schema.Choice(
262        title = u'Current Level',
263        source = StudyLevelSource(),
264        default = None,
265        required = False,
266        readonly = False,
267        )
268
269    current_verdict = schema.Choice(
270        title = u'Current Verdict',
271        source = verdicts,
272        default = '0',
273        required = False,
274        )
275
276    previous_verdict = schema.Choice(
277        title = u'Previous Verdict',
278        source = verdicts,
279        default = '0',
280        required = False,
281        )
282
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
292class IStudentStudyLevel(IWAeUPObject):
293    """A container for course tickets.
294
295    """
296    level = Attribute('The level code')
297    validation_date = Attribute('The date of validation')
298    validated_by = Attribute('User Id of course adviser')
299
300    level_session = schema.Choice(
301        title = u'Session',
302        source = academic_sessions_vocab,
303        default = None,
304        required = True,
305        )
306
307    level_verdict = schema.Choice(
308        title = u'Verdict',
309        source = verdicts,
310        default = '0',
311        required = False,
312        )
313
314class ICourseTicket(IWAeUPObject):
315    """A course ticket.
316
317    """
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')
325
326    core_or_elective = schema.Bool(
327        title = u'Mandatory',
328        default = False,
329        required = False,
330        readonly = False,
331        )
332
333    score = schema.Int(
334        title = u'Score',
335        default = 0,
336        required = False,
337        readonly = False,
338        )
339
340    automatic = schema.Bool(
341        title = u'Automatical Creation',
342        default = False,
343        required = False,
344        readonly = True,
345        )
346
347class ICourseTicketAdd(ICourseTicket):
348    """An interface for adding course tickets.
349
350    """
351    course = schema.Choice(
352        title = u'Course',
353        source = CourseSource(),
354        readonly = False,
355        )
356
357class IStudentAccommodation(IWAeUPObject):
358    """A container for student accommodation objects.
359
360    """
361
362class IBedTicket(IWAeUPObject):
363    """A ticket for accommodation booking.
364
365    """
366    bed = Attribute('The bed object.')
367
368    bed_coordinates = schema.TextLine(
369        title = u'Bed Coordinates',
370        default = None,
371        required = False,
372        readonly = False,
373        )
374
375    bed_type = schema.TextLine(
376        title = u'Bed Type',
377        default = None,
378        required = False,
379        readonly = False,
380        )
381
382    booking_session = schema.Choice(
383        title = u'Session',
384        source = academic_sessions_vocab,
385        default = None,
386        required = True,
387        readonly = True,
388        )
389
390    booking_date = schema.Datetime(
391        title = u'Booking Date',
392        required = False,
393        readonly = True,
394        )
395
396    booking_code = schema.TextLine(
397        title = u'Booking Activation Code',
398        default = u'',
399        required = False,
400        readonly = True,
401        )
402
403    def getSessionString():
404        """Returns the the title of academic_sessions_vocab term.
405
406        """
407
408class IStudentPaymentsContainer(IPaymentsContainer):
409    """A container for student payment objects.
410
411    """
412
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
426# Interfaces for students only
427
428class IStudentClearanceEdit(IStudentClearance):
429    """Interface needed for restricted editing of student clearance data.
430
431    """
432
433class IStudentPersonalEdit(IStudentPersonal):
434    """Interface needed for restricted editing of student personal data.
435
436    """
Note: See TracBrowser for help on using the repository browser.