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

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

Remove manual field constraints and use min_length instead.

  • Property svn:keywords set to Id
File size: 10.7 KB
Line 
1##
2## interfaces.py
3import re
4from datetime import datetime
5from zope.interface import Attribute, invariant
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 IStudentsContainer(IWAeUPObject):
29    """A students container contains university students.
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
68class IStudentNavigation(IWAeUPObject):
69    """Interface needed for student navigation.
70    """
71
72    def getStudent():
73        """Return student object.
74        """
75
76class IStudentPasswordSetting(IWAeUPObject):
77    """Data needed for password setting.
78    """
79
80    password = schema.Password(
81        title = u'New password',
82        description = u'min. length: 3',
83        min_length = 3,
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
98class IStudentBase(IWAeUPObject):
99    """Representation of student base data.
100    """
101    history = Attribute('Object history, a list of messages')
102    state = Attribute('Returns the registration state of a student')
103    password = Attribute('Encrypted password of a student')
104    certificate = Attribute('The certificate of any chosen study course')
105    current_session = Attribute('The current session of the student')
106
107    def loggerInfo(ob_class, comment):
108        """Adds an INFO message to the log file
109        """
110
111    student_id = schema.TextLine(
112        title = u'Student ID',
113        required = False,
114        )
115
116    fullname = schema.TextLine(
117        title = u'Full Name',
118        default = None,
119        required = True,
120        )
121
122    sex = schema.Choice(
123        title = u'Sex',
124        source = GenderSource(),
125        default = u'm',
126        required = True,
127        )
128
129    reg_number = TextLineChoice(
130        title = u'Registration Number',
131        default = None,
132        required = True,
133        readonly = False,
134        source = contextual_reg_num_source,
135        )
136
137    matric_number = TextLineChoice(
138        title = u'Matriculation Number',
139        #default = u'',
140        required = False,
141        readonly = False,
142        source = contextual_mat_num_source,
143        )
144
145    adm_code = schema.TextLine(
146        title = u'PWD Activation Code',
147        default = u'',
148        required = False,
149        readonly = True,
150        )
151
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
163class IStudentClearance(IWAeUPObject):
164    """Representation of student clearance data.
165    """
166
167    date_of_birth = schema.Date(
168        title = u'Date of Birth',
169        required = True,
170        )
171
172    clearance_locked = schema.Bool(
173        title = u'Clearance form locked',
174        default = False,
175        )
176
177    clr_code = schema.TextLine(
178        title = u'CLR Activation Code',
179        default = u'',
180        required = False,
181        readonly = True,
182        )
183
184class IStudentPersonal(IWAeUPObject):
185    """Representation of student personal data.
186    """
187
188    perm_address = schema.Text(
189        title = u'Permanent Address',
190        required = False,
191        )
192
193class IStudent(IStudentBase,IStudentClearance,IStudentPersonal):
194    """Representation of a student.
195    """
196
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
217class IStudentStudyCourse(IWAeUPObject):
218    """A container for student study levels.
219
220    """
221
222    certificate = schema.Choice(
223        title = u'Certificate',
224        source = CertificateSource(),
225        default = None,
226        required = True,
227        )
228
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
246    current_session = schema.Choice(
247        title = u'Current Session',
248        source = academic_sessions_vocab,
249        default = None,
250        required = True,
251        readonly = False,
252        )
253
254    current_level = schema.Choice(
255        title = u'Current Level',
256        source = StudyLevelSource(),
257        default = None,
258        required = False,
259        readonly = False,
260        )
261
262    current_verdict = schema.Choice(
263        title = u'Current Verdict',
264        source = verdicts,
265        default = '0',
266        required = False,
267        )
268
269    previous_verdict = schema.Choice(
270        title = u'Previous Verdict',
271        source = verdicts,
272        default = '0',
273        required = False,
274        )
275
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
286class IStudentStudyLevel(IWAeUPObject):
287    """A container for course tickets.
288
289    """
290    level = Attribute('The level code')
291    validation_date = Attribute('The date of validation')
292    validated_by = Attribute('User Id of course adviser')
293
294    level_session = schema.Choice(
295        title = u'Session',
296        source = academic_sessions_vocab,
297        default = None,
298        required = True,
299        )
300
301    level_verdict = schema.Choice(
302        title = u'Verdict',
303        source = verdicts,
304        default = '0',
305        required = False,
306        )
307
308class ICourseTicket(IWAeUPObject):
309    """A course ticket.
310
311    """
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')
319
320    core_or_elective = schema.Bool(
321        title = u'Mandatory',
322        default = False,
323        required = False,
324        readonly = False,
325        )
326
327    score = schema.Int(
328        title = u'Score',
329        default = 0,
330        required = False,
331        readonly = False,
332        )
333
334    automatic = schema.Bool(
335        title = u'Automatical Creation',
336        default = False,
337        required = False,
338        readonly = True,
339        )
340
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
351class IStudentAccommodation(IWAeUPObject):
352    """A container for student accommodation objects.
353
354    """
355
356class IBedTicket(IWAeUPObject):
357    """A ticket for accommodation booking.
358
359    """
360
361    bed = Attribute('The bed object.')
362
363    bed_coordinates = schema.TextLine(
364        title = u'Bed Coordinates',
365        default = None,
366        required = False,
367        readonly = False,
368        )
369
370    bed_type = schema.TextLine(
371        title = u'Bed Type',
372        default = None,
373        required = False,
374        readonly = False,
375        )
376
377    booking_session = schema.Choice(
378        title = u'Session',
379        source = academic_sessions_vocab,
380        default = None,
381        required = True,
382        readonly = True,
383        )
384
385    booking_date = schema.Datetime(
386        title = u'Booking Date',
387        required = False,
388        readonly = True,
389        )
390
391    booking_code = schema.TextLine(
392        title = u'Booking Activation Code',
393        default = u'',
394        required = False,
395        readonly = True,
396        )
397
398    def getSessionString():
399        """Returns the the title of academic_sessions_vocab term
400        """
401
402class IStudentPaymentsContainer(IPaymentsContainer):
403    """A container for student payment objects.
404
405    """
406
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
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.