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

Last change on this file since 7140 was 7140, checked in by uli, 14 years ago

Remove manual field constraints and use min_length instead.

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