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

Last change on this file since 9156 was 9150, checked in by Henrik Bettermann, 12 years ago

p_current must not be readonly. Otherwise we can't import this field.

  • Property svn:keywords set to Id
File size: 16.4 KB
Line 
1## $Id: interfaces.py 9150 2012-09-04 07:02:30Z henrik $
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##
18#from 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, ICSVExporter)
25from waeup.kofa.interfaces import MessageFactory as _
26from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber
27from waeup.kofa.students.vocabularies import (
28    StudyLevelSource, contextual_reg_num_source, contextual_mat_num_source,
29    GenderSource, nats_vocab,
30    )
31from waeup.kofa.payments.interfaces import (
32    IPaymentsContainer, IOnlinePayment)
33from waeup.kofa.university.vocabularies import (
34    CourseSource, StudyModeSource, CertificateSource)
35
36# VerdictSource can't be placed into the vocabularies module because it
37# requires importing IStudentsUtils which then leads to circular imports.
38class VerdictSource(BasicContextualSourceFactory):
39    """A verdicts source delivers all verdicts provided
40    in the portal.
41    """
42    def getValues(self, context):
43        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
44        return sorted(verdicts_dict.keys())
45
46    def getToken(self, context, value):
47        return value
48
49    def getTitle(self, context, value):
50        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
51        if value != '0':
52            return verdicts_dict[value] + ' (%s)' % value
53        return verdicts_dict[value]
54
55
56class IStudentsUtils(Interface):
57    """A collection of methods which are subject to customization.
58
59    """
60    def setReturningData(student):
61        """ This method defines what happens after school fee payment
62        depending on the student's senate verdict.
63
64        In the base configuration current level is always increased
65        by 100 no matter which verdict has been assigned.
66        """
67
68    def setPaymentDetails(category, student, previous_session=None,
69            previous_level=None,):
70        """Create Payment object and set the payment data of a student for
71        the payment category specified.
72
73        """
74
75    def getAccommodation_details(student):
76        """Determine the accommodation dates of a student.
77
78        """
79
80    def selectBed(available_beds):
81        """Select a bed from a list of available beds.
82
83        In the standard configuration we select the first bed found,
84        but can also randomize the selection if we like.
85        """
86
87    def renderPDF(view, subject='', filename='slip.pdf',):
88        """Render pdf slips for various pages.
89
90        """
91
92class IStudentsContainer(IKofaObject):
93    """A students container contains university students.
94
95    """
96    def addStudent(student):
97        """Add an IStudent object and subcontainers.
98
99        """
100
101    def archive(id=None):
102        """Create on-dist archive of students.
103
104        If id is `None`, all students are archived.
105
106        If id contains a single id string, only the respective
107        students are archived.
108
109        If id contains a list of id strings all of the respective
110        students types are saved to disk.
111        """
112
113    def clear(id=None, archive=True):
114        """Remove students of type given by 'id'.
115
116        Optionally archive the students.
117
118        If id is `None`, all students are archived.
119
120        If id contains a single id string, only the respective
121        students are archived.
122
123        If id contains a list of id strings all of the respective
124        student types are saved to disk.
125
126        If `archive` is ``False`` none of the archive-handling is done
127        and respective students are simply removed from the
128        database.
129        """
130
131    unique_student_id = Attribute("""A unique student id.""")
132
133class IStudentNavigation(IKofaObject):
134    """Interface needed for student navigation, logging, etc.
135
136    """
137    student = Attribute('Student object of context.')
138
139    def writeLogMessage(view, message):
140        """Write a view specific log message into students.log.
141
142        """
143
144class IStudentBase(IKofaObject):
145    """Representation of student base data.
146
147    """
148    history = Attribute('Object history, a list of messages')
149    state = Attribute('Returns the registration state of a student')
150    password = Attribute('Encrypted password of a student')
151    certcode = Attribute('The certificate code of any chosen study course')
152    depcode = Attribute('The department code of any chosen study course')
153    faccode = Attribute('The faculty code of any chosen study course')
154    current_session = Attribute('The current session of the student')
155    current_level = Attribute('The current level of the student')
156    current_mode = Attribute('The current mode of the student')
157    fullname = Attribute('All name parts separated by hyphens')
158    display_fullname = Attribute('The fullname of an applicant')
159    is_postgrad = Attribute('True if postgraduate student')
160
161    suspended = schema.Bool(
162        title = _(u'Account suspended'),
163        default = False,
164        required = False,
165        )
166
167    student_id = schema.TextLine(
168        title = _(u'Student Id'),
169        required = False,
170        )
171
172    firstname = schema.TextLine(
173        title = _(u'First Name'),
174        required = True,
175        )
176
177    middlename = schema.TextLine(
178        title = _(u'Middle Name'),
179        required = False,
180        )
181
182    lastname = schema.TextLine(
183        title = _(u'Last Name (Surname)'),
184        required = True,
185        )
186
187    sex = schema.Choice(
188        title = _(u'Sex'),
189        source = GenderSource(),
190        required = True,
191        )
192
193    reg_number = TextLineChoice(
194        title = _(u'Registration Number'),
195        required = True,
196        readonly = False,
197        source = contextual_reg_num_source,
198        )
199
200    matric_number = TextLineChoice(
201        title = _(u'Matriculation Number'),
202        required = False,
203        readonly = False,
204        source = contextual_mat_num_source,
205        )
206
207    adm_code = schema.TextLine(
208        title = _(u'PWD Activation Code'),
209        required = False,
210        readonly = False,
211        )
212
213    email = schema.ASCIILine(
214        title = _(u'Email'),
215        required = False,
216        constraint=validate_email,
217        )
218    phone = PhoneNumber(
219        title = _(u'Phone'),
220        description = u'',
221        required = False,
222        )
223
224    def transfer(certificate, current_session,
225        current_level, current_verdict):
226        """ Creates a new studycourse and backups the old one.
227
228        """
229
230class IUGStudentClearance(IKofaObject):
231    """Representation of undergraduate student clearance data.
232
233    """
234    date_of_birth = FormattedDate(
235        title = _(u'Date of Birth'),
236        required = True,
237        show_year = True,
238        )
239
240    clearance_locked = schema.Bool(
241        title = _(u'Clearance form locked'),
242        default = False,
243        required = False,
244        )
245
246    clr_code = schema.TextLine(
247        title = _(u'CLR Activation Code'),
248        required = False,
249        readonly = False,
250        )
251
252    nationality = schema.Choice(
253        vocabulary = nats_vocab,
254        title = _(u'Nationality'),
255        required = False,
256        )
257
258class IPGStudentClearance(IUGStudentClearance):
259    """Representation of postgraduate student clearance data.
260
261    """
262    employer = schema.TextLine(
263        title = _(u'Employer'),
264        required = False,
265        readonly = False,
266        )
267
268class IStudentPersonal(IKofaObject):
269    """Representation of student personal data.
270
271    """
272    perm_address = schema.Text(
273        title = _(u'Permanent Address'),
274        required = False,
275        )
276
277class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,
278    IStudentPersonal):
279    """Representation of a student.
280
281    """
282
283class IStudentUpdateByRegNo(IStudent):
284    """Representation of a student. Skip regular reg_number validation.
285
286    """
287    reg_number = schema.TextLine(
288        title = _(u'Registration Number'),
289        required = False,
290        )
291
292class IStudentUpdateByMatricNo(IStudent):
293    """Representation of a student. Skip regular matric_number validation.
294
295    """
296    matric_number = schema.TextLine(
297        title = _(u'Matriculation Number'),
298        required = False,
299        )
300
301class IStudentRequestPW(IStudent):
302    """Representation of an student for first-time password request.
303
304    This interface is used when students use the requestpw page to
305    login for the the first time.
306    """
307    number = schema.TextLine(
308        title = _(u'Registr. or Matric. Number'),
309        required = True,
310        )
311
312    firstname = schema.TextLine(
313        title = _(u'First Name'),
314        required = True,
315        )
316
317    email = schema.ASCIILine(
318        title = _(u'Email Address'),
319        required = True,
320        constraint=validate_email,
321        )
322
323class IStudentStudyCourse(IKofaObject):
324    """A container for student study levels.
325
326    """
327    certificate = schema.Choice(
328        title = _(u'Certificate'),
329        source = CertificateSource(),
330        required = False,
331        )
332
333    entry_mode = schema.Choice(
334        title = _(u'Entry Mode'),
335        source = StudyModeSource(),
336        required = True,
337        readonly = False,
338        )
339
340    entry_session = schema.Choice(
341        title = _(u'Entry Session'),
342        source = academic_sessions_vocab,
343        #default = datetime.now().year,
344        required = True,
345        readonly = False,
346        )
347
348    current_session = schema.Choice(
349        title = _(u'Current Session'),
350        source = academic_sessions_vocab,
351        required = True,
352        readonly = False,
353        )
354
355    current_level = schema.Choice(
356        title = _(u'Current Level'),
357        source = StudyLevelSource(),
358        required = False,
359        readonly = False,
360        )
361
362    current_verdict = schema.Choice(
363        title = _(u'Current Verdict'),
364        source = VerdictSource(),
365        default = '0',
366        required = False,
367        )
368
369    previous_verdict = schema.Choice(
370        title = _(u'Previous Verdict'),
371        source = VerdictSource(),
372        default = '0',
373        required = False,
374        )
375
376class IStudentStudyCourseTransfer(IStudentStudyCourse):
377    """An student transfers.
378
379    """
380
381    certificate = schema.Choice(
382        title = _(u'Certificate'),
383        source = CertificateSource(),
384        required = True,
385        )
386
387    current_level = schema.Choice(
388        title = _(u'Current Level'),
389        source = StudyLevelSource(),
390        required = True,
391        readonly = False,
392        )
393
394
395IStudentStudyCourseTransfer['certificate'].order = IStudentStudyCourse[
396    'certificate'].order
397IStudentStudyCourseTransfer['current_level'].order = IStudentStudyCourse[
398    'current_level'].order
399
400class IStudentVerdictUpdate(IKofaObject):
401    """A interface for verdict imports.
402
403    """
404
405    current_verdict = schema.Choice(
406        title = _(u'Current Verdict'),
407        source = VerdictSource(),
408        required = True,
409        )
410
411    current_session = schema.Choice(
412        title = _(u'Current Session'),
413        source = academic_sessions_vocab,
414        required = True,
415        )
416
417    current_level = schema.Choice(
418        title = _(u'Current Level'),
419        source = StudyLevelSource(),
420        required = True,
421        )
422
423class IStudentStudyLevel(IKofaObject):
424    """A container for course tickets.
425
426    """
427    level = Attribute('The level code')
428    validation_date = Attribute('The date of validation')
429    validated_by = Attribute('User Id of course adviser')
430
431    level_session = schema.Choice(
432        title = _(u'Session'),
433        source = academic_sessions_vocab,
434        required = True,
435        )
436
437    level_verdict = schema.Choice(
438        title = _(u'Verdict'),
439        source = VerdictSource(),
440        default = '0',
441        required = False,
442        )
443
444    def addCourseTicket(ticket, course):
445        """Add a course ticket object.
446        """
447
448class ICourseTicket(IKofaObject):
449    """A course ticket.
450
451    """
452    code = Attribute('code of the original course')
453    title = Attribute('title of the original course')
454    credits = Attribute('credits of the original course')
455    passmark = Attribute('passmark of the original course')
456    semester = Attribute('semester of the original course')
457    fcode = Attribute('faculty code of the original course')
458    dcode = Attribute('department code of the original course')
459
460    mandatory = schema.Bool(
461        title = _(u'Mandatory'),
462        default = False,
463        required = False,
464        readonly = False,
465        )
466
467    score = schema.Int(
468        title = _(u'Score'),
469        default = 0,
470        required = False,
471        readonly = False,
472        )
473
474    automatic = schema.Bool(
475        title = _(u'Automatical Creation'),
476        default = False,
477        required = False,
478        readonly = True,
479        )
480
481    carry_over = schema.Bool(
482        title = _(u'Carry-over Course'),
483        default = False,
484        required = False,
485        readonly = False,
486        )
487
488    def getLevel():
489        """Returns the id of the level the ticket has been added to.
490        """
491
492    def getLevelSession():
493        """Returns the session of the level the ticket has been added to.
494        """
495
496class ICourseTicketAdd(ICourseTicket):
497    """An interface for adding course tickets.
498
499    """
500    course = schema.Choice(
501        title = _(u'Course'),
502        source = CourseSource(),
503        readonly = False,
504        )
505
506class IStudentAccommodation(IKofaObject):
507    """A container for student accommodation objects.
508
509    """
510
511class IBedTicket(IKofaObject):
512    """A ticket for accommodation booking.
513
514    """
515    bed = Attribute('The bed object.')
516
517    bed_coordinates = schema.TextLine(
518        title = _(u'Bed Coordinates'),
519        required = False,
520        readonly = False,
521        )
522
523    bed_type = schema.TextLine(
524        title = _(u'Bed Type'),
525        required = False,
526        readonly = False,
527        )
528
529    booking_session = schema.Choice(
530        title = _(u'Session'),
531        source = academic_sessions_vocab,
532        required = True,
533        readonly = True,
534        )
535
536    booking_date = schema.Datetime(
537        title = _(u'Booking Date'),
538        required = False,
539        readonly = True,
540        )
541
542    booking_code = schema.TextLine(
543        title = _(u'Booking Activation Code'),
544        required = False,
545        readonly = True,
546        )
547
548    def getSessionString():
549        """Returns the title of academic_sessions_vocab term.
550
551        """
552
553class IStudentPaymentsContainer(IPaymentsContainer):
554    """A container for student payment objects.
555
556    """
557
558class IStudentOnlinePayment(IOnlinePayment):
559    """A student payment via payment gateways.
560
561    """
562
563    p_current = schema.Bool(
564        title = _(u'Current Session Payment'),
565        default = True,
566        required = False,
567        )
568
569    p_level = schema.Int(
570        title = _(u'Payment Level'),
571        required = False,
572        readonly = True,
573        )
574
575    def doAfterStudentPayment():
576        """Process student after payment was made.
577
578        """
579
580    def doAfterStudentPaymentApproval():
581        """Process student after payment was approved.
582
583        """
584
585    def approveStudentPayment():
586        """Approve payment and process student.
587
588        """
589
590IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
591    'p_session'].order
592
593class IStudentPreviousPayment(IOnlinePayment):
594    """An interface for adding previous session payments.
595
596    """
597
598    p_session = schema.Choice(
599        title = _(u'Payment Session'),
600        source = academic_sessions_vocab,
601        required = True,
602        )
603
604    p_level = schema.Choice(
605        title = _(u'Payment Level'),
606        source = StudyLevelSource(),
607        required = True,
608        )
609
610class ICSVStudentExporter(ICSVExporter):
611    """A regular ICSVExporter that additionally supports exporting
612      data from a given student object.
613    """
614
615    def export_student(student, filepath=None):
616        """Export data for a given student.
617        """
Note: See TracBrowser for help on using the repository browser.