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

Last change on this file since 9949 was 9949, checked in by uli, 12 years ago

Use specialized methods to get a PDF creator; better usable in customized packages when different pdf forms are needed for different circumstances.

  • Property svn:keywords set to Id
File size: 21.5 KB
RevLine 
[7191]1## $Id: interfaces.py 9949 2013-02-14 16:32:40Z uli $
[6621]2##
[7191]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##
[8409]18#from datetime import datetime
[7620]19from zope.component import getUtility
[7256]20from zope.interface import Attribute, Interface
[6621]21from zope import schema
[7620]22from zc.sourcefactory.contextual import BasicContextualSourceFactory
[9217]23from waeup.kofa.browser.interfaces import IStudentNavigationBase
[7811]24from waeup.kofa.interfaces import (
[8409]25    IKofaObject, academic_sessions_vocab, validate_email, ICSVExporter)
[7811]26from waeup.kofa.interfaces import MessageFactory as _
[8176]27from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber
[7811]28from waeup.kofa.students.vocabularies import (
[7915]29    StudyLevelSource, contextual_reg_num_source, contextual_mat_num_source,
[9420]30    GenderSource, nats_vocab
[7915]31    )
[8160]32from waeup.kofa.payments.interfaces import (
[8174]33    IPaymentsContainer, IOnlinePayment)
[7915]34from waeup.kofa.university.vocabularies import (
[9864]35    CourseSource, StudyModeSource, CertificateSource, SemesterSource,
36    ContextualDictSourceFactoryBase)
[6621]37
[9864]38class PreviousPaymentCategorySource(ContextualDictSourceFactoryBase):
39    """A source that delivers all selectable categories of previous session
40    payments.
41    """
42    #: name of dict to deliver from kofa utils.
43    DICT_NAME = 'PREVIOUS_PAYMENT_CATEGORIES'
44
[9868]45class BalancePaymentCategorySource(ContextualDictSourceFactoryBase):
[9864]46    """A source that delivers all selectable items of balance payments.
47    """
48    #: name of dict to deliver from kofa utils.
[9868]49    DICT_NAME = 'BALANCE_PAYMENT_CATEGORIES'
[9864]50
[7620]51# VerdictSource can't be placed into the vocabularies module because it
52# requires importing IStudentsUtils which then leads to circular imports.
53class VerdictSource(BasicContextualSourceFactory):
54    """A verdicts source delivers all verdicts provided
55    in the portal.
56    """
57    def getValues(self, context):
[7841]58        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
[8820]59        return sorted(verdicts_dict.keys())
[7620]60
61    def getToken(self, context, value):
62        return value
63
64    def getTitle(self, context, value):
[7841]65        verdicts_dict = getUtility(IStudentsUtils).VERDICTS_DICT
[8820]66        if value != '0':
67            return verdicts_dict[value] + ' (%s)' % value
[7688]68        return verdicts_dict[value]
[7620]69
[7681]70
[7150]71class IStudentsUtils(Interface):
72    """A collection of methods which are subject to customization.
73
74    """
[7841]75    def setReturningData(student):
76        """ This method defines what happens after school fee payment
77        depending on the student's senate verdict.
78
79        In the base configuration current level is always increased
80        by 100 no matter which verdict has been assigned.
81        """
82
[9148]83    def setPaymentDetails(category, student, previous_session=None,
84            previous_level=None,):
[8595]85        """Create Payment object and set the payment data of a student for
86        the payment category specified.
[7150]87
88        """
89
[7186]90    def getAccommodation_details(student):
[7150]91        """Determine the accommodation dates of a student.
92
93        """
94
[7186]95    def selectBed(available_beds):
[7150]96        """Select a bed from a list of available beds.
97
98        In the standard configuration we select the first bed found,
99        but can also randomize the selection if we like.
100        """
101
[9949]102    def getPDFCreator(context):
103        """Get some IPDFCreator instance suitable for use with `context`.
104        """
105
[7186]106    def renderPDF(view, subject='', filename='slip.pdf',):
[7150]107        """Render pdf slips for various pages.
108
109        """
110
[7819]111class IStudentsContainer(IKofaObject):
[7096]112    """A students container contains university students.
[6692]113
114    """
115    def addStudent(student):
116        """Add an IStudent object and subcontainers.
117
118        """
119
120    def archive(id=None):
121        """Create on-dist archive of students.
122
123        If id is `None`, all students are archived.
124
125        If id contains a single id string, only the respective
126        students are archived.
127
128        If id contains a list of id strings all of the respective
129        students types are saved to disk.
130        """
131
132    def clear(id=None, archive=True):
133        """Remove students of type given by 'id'.
134
135        Optionally archive the students.
136
137        If id is `None`, all students are archived.
138
139        If id contains a single id string, only the respective
140        students are archived.
141
142        If id contains a list of id strings all of the respective
143        student types are saved to disk.
144
145        If `archive` is ``False`` none of the archive-handling is done
146        and respective students are simply removed from the
147        database.
148        """
149
[8408]150    unique_student_id = Attribute("""A unique student id.""")
151
[9217]152class IStudentNavigation(IStudentNavigationBase):
[8735]153    """Interface needed for student navigation, logging, etc.
[7150]154
[6642]155    """
[8736]156    student = Attribute('Student object of context.')
[7150]157
[8735]158    def writeLogMessage(view, message):
159        """Write a view specific log message into students.log.
160
161        """
162
[7819]163class IStudentBase(IKofaObject):
[6631]164    """Representation of student base data.
[7150]165
[6621]166    """
[7062]167    history = Attribute('Object history, a list of messages')
[6637]168    state = Attribute('Returns the registration state of a student')
[6699]169    password = Attribute('Encrypted password of a student')
[9334]170    temp_password = Attribute(
171        'Dictionary with user name, timestamp and encrypted password')
[7203]172    certcode = Attribute('The certificate code of any chosen study course')
173    depcode = Attribute('The department code of any chosen study course')
174    faccode = Attribute('The faculty code of any chosen study course')
[9761]175    entry_session = Attribute('The entry session of the student')
[7062]176    current_session = Attribute('The current session of the student')
[9142]177    current_level = Attribute('The current level of the student')
[7641]178    current_mode = Attribute('The current mode of the student')
[9182]179    current_verdict = Attribute('The current verdict of the student')
[7364]180    fullname = Attribute('All name parts separated by hyphens')
181    display_fullname = Attribute('The fullname of an applicant')
[8969]182    is_postgrad = Attribute('True if postgraduate student')
[6637]183
[8983]184    suspended = schema.Bool(
185        title = _(u'Account suspended'),
186        default = False,
[9035]187        required = False,
[8983]188        )
189
[9702]190    suspended_comment = schema.Text(
191        title = _(u"Reasons for Deactivation"),
192        required = False,
193        description = _(
194            u'This message will be shown if and only if deactivated '
195            'students try to login.'),
196        )
197
[6665]198    student_id = schema.TextLine(
[7723]199        title = _(u'Student Id'),
[6849]200        required = False,
[6665]201        )
202
[7357]203    firstname = schema.TextLine(
[7723]204        title = _(u'First Name'),
[6621]205        required = True,
206        )
207
[7357]208    middlename = schema.TextLine(
[7723]209        title = _(u'Middle Name'),
[7357]210        required = False,
211        )
212
213    lastname = schema.TextLine(
[7723]214        title = _(u'Last Name (Surname)'),
[7357]215        required = True,
216        )
217
[6996]218    sex = schema.Choice(
[7723]219        title = _(u'Sex'),
[6996]220        source = GenderSource(),
221        required = True,
222        )
223
[6788]224    reg_number = TextLineChoice(
[7723]225        title = _(u'Registration Number'),
[6696]226        required = True,
227        readonly = False,
[6788]228        source = contextual_reg_num_source,
[6696]229        )
230
[6788]231    matric_number = TextLineChoice(
[7723]232        title = _(u'Matriculation Number'),
[6750]233        required = False,
234        readonly = False,
[6788]235        source = contextual_mat_num_source,
[6750]236        )
237
[6769]238    adm_code = schema.TextLine(
[7723]239        title = _(u'PWD Activation Code'),
[6769]240        required = False,
[8977]241        readonly = False,
[6769]242        )
243
[7133]244    email = schema.ASCIILine(
[7723]245        title = _(u'Email'),
[7133]246        required = False,
247        constraint=validate_email,
248        )
[8176]249    phone = PhoneNumber(
[7723]250        title = _(u'Phone'),
[7331]251        description = u'',
[7133]252        required = False,
253        )
254
[9334]255    def setTempPassword(user, password):
256        """Set a temporary password (LDAP-compatible) SSHA encoded for
257        officers.
258
259        """
260
261    def getTempPassword():
262        """Check if a temporary password has been set and if it
263        is not expired.
264
265        Return the temporary password if valid,
266        None otherwise. Unset the temporary password if expired.
267        """
268
[9131]269    def transfer(certificate, current_session,
270        current_level, current_verdict):
271        """ Creates a new studycourse and backups the old one.
272
273        """
274
[7993]275class IUGStudentClearance(IKofaObject):
276    """Representation of undergraduate student clearance data.
[7150]277
[6631]278    """
[9543]279    officer_comment = schema.Text(
280        title = _(u"Officer's Comment"),
281        required = False,
[6631]282        )
283
[6695]284    clearance_locked = schema.Bool(
[7723]285        title = _(u'Clearance form locked'),
[6695]286        default = False,
[9035]287        required = False,
[6695]288        )
289
[6769]290    clr_code = schema.TextLine(
[7723]291        title = _(u'CLR Activation Code'),
[6769]292        required = False,
[8977]293        readonly = False,
[6769]294        )
295
[9543]296    date_of_birth = FormattedDate(
297        title = _(u'Date of Birth'),
298        required = True,
299        show_year = True,
300        )
301
[7523]302    nationality = schema.Choice(
[8069]303        vocabulary = nats_vocab,
[7723]304        title = _(u'Nationality'),
[7983]305        required = False,
[7523]306        )
307
[7993]308class IPGStudentClearance(IUGStudentClearance):
309    """Representation of postgraduate student clearance data.
310
311    """
312    employer = schema.TextLine(
313        title = _(u'Employer'),
314        required = False,
315        readonly = False,
316        )
317
[7819]318class IStudentPersonal(IKofaObject):
[6631]319    """Representation of student personal data.
[7150]320
[6631]321    """
[9543]322    personal_updated = schema.Datetime(
323        title = _(u'Updated'),
324        required = False,
325        readonly = False,
326        )
327
[6651]328    perm_address = schema.Text(
[7723]329        title = _(u'Permanent Address'),
[6631]330        required = False,
331        )
332
[8008]333class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,
334    IStudentPersonal):
[6631]335    """Representation of a student.
[7150]336
[6631]337    """
338
[9563]339class IStudentPersonalEdit(IStudentPersonal):
340    """Interface for editing personal data by students.
341
342    Here we can repeat the fields from IStudentPersonal and set the
343    `required` if necessary.
344    """
345
346    perm_address = schema.Text(
347        title = _(u'Permanent Address'),
348        required = True,
349        )
350
[6849]351class IStudentUpdateByRegNo(IStudent):
352    """Representation of a student. Skip regular reg_number validation.
[7150]353
[6849]354    """
355    reg_number = schema.TextLine(
[7723]356        title = _(u'Registration Number'),
[6849]357        required = False,
358        )
359
360class IStudentUpdateByMatricNo(IStudent):
361    """Representation of a student. Skip regular matric_number validation.
[7150]362
[6849]363    """
364    matric_number = schema.TextLine(
[7723]365        title = _(u'Matriculation Number'),
[6849]366        required = False,
367        )
368
[8779]369class IStudentRequestPW(IStudent):
370    """Representation of an student for first-time password request.
371
372    This interface is used when students use the requestpw page to
373    login for the the first time.
374    """
[8854]375    number = schema.TextLine(
376        title = _(u'Registr. or Matric. Number'),
[8779]377        required = True,
378        )
379
380    firstname = schema.TextLine(
381        title = _(u'First Name'),
382        required = True,
383        )
384
385    email = schema.ASCIILine(
386        title = _(u'Email Address'),
387        required = True,
388        constraint=validate_email,
389        )
390
[7819]391class IStudentStudyCourse(IKofaObject):
[6633]392    """A container for student study levels.
393
394    """
[6648]395    certificate = schema.Choice(
[7723]396        title = _(u'Certificate'),
[6648]397        source = CertificateSource(),
[7209]398        required = False,
[6633]399        )
[6635]400
[6996]401    entry_mode = schema.Choice(
[7723]402        title = _(u'Entry Mode'),
[7681]403        source = StudyModeSource(),
[6996]404        required = True,
405        readonly = False,
406        )
407
408    entry_session = schema.Choice(
[7723]409        title = _(u'Entry Session'),
[6996]410        source = academic_sessions_vocab,
[7425]411        #default = datetime.now().year,
[6996]412        required = True,
413        readonly = False,
414        )
415
[6724]416    current_session = schema.Choice(
[7723]417        title = _(u'Current Session'),
[6744]418        source = academic_sessions_vocab,
[6724]419        required = True,
[6996]420        readonly = False,
[6724]421        )
422
423    current_level = schema.Choice(
[7723]424        title = _(u'Current Level'),
[6725]425        source = StudyLevelSource(),
426        required = False,
[6996]427        readonly = False,
[6724]428        )
429
430    current_verdict = schema.Choice(
[7723]431        title = _(u'Current Verdict'),
[7619]432        source = VerdictSource(),
[8820]433        default = '0',
[6725]434        required = False,
[6724]435        )
436
437    previous_verdict = schema.Choice(
[7723]438        title = _(u'Previous Verdict'),
[7619]439        source = VerdictSource(),
[8820]440        default = '0',
[6725]441        required = False,
[6724]442        )
443
[9138]444class IStudentStudyCourseTransfer(IStudentStudyCourse):
445    """An student transfers.
446
447    """
448
449    certificate = schema.Choice(
450        title = _(u'Certificate'),
451        source = CertificateSource(),
452        required = True,
453        )
454
455    current_level = schema.Choice(
456        title = _(u'Current Level'),
457        source = StudyLevelSource(),
458        required = True,
459        readonly = False,
460        )
461
462
463IStudentStudyCourseTransfer['certificate'].order = IStudentStudyCourse[
464    'certificate'].order
465IStudentStudyCourseTransfer['current_level'].order = IStudentStudyCourse[
466    'current_level'].order
467
[7951]468class IStudentVerdictUpdate(IKofaObject):
469    """A interface for verdict imports.
470
471    """
472
473    current_verdict = schema.Choice(
474        title = _(u'Current Verdict'),
475        source = VerdictSource(),
476        required = True,
477        )
478
479    current_session = schema.Choice(
480        title = _(u'Current Session'),
481        source = academic_sessions_vocab,
482        required = True,
483        )
484
485    current_level = schema.Choice(
486        title = _(u'Current Level'),
487        source = StudyLevelSource(),
488        required = True,
489        )
490
[9296]491    bypass_validation = schema.Bool(
492        title = _(u'Bypass validation'),
493        required = False,
494        )
495
496    validated_by = schema.TextLine(
497        title = _(u'Validated by'),
498        required = False,
499        )
500
[7819]501class IStudentStudyLevel(IKofaObject):
[6774]502    """A container for course tickets.
503
504    """
505    level = Attribute('The level code')
[9235]506    number_of_tickets = Attribute('Number of tickets contained in this level')
[9253]507    certcode = Attribute('The certificate code of the study course')
[9257]508    is_current_level = Attribute('Is this level the current level of the student?')
[6774]509
[6793]510    level_session = schema.Choice(
[7723]511        title = _(u'Session'),
[6793]512        source = academic_sessions_vocab,
[9437]513        required = True,
[6793]514        )
[6781]515
[6793]516    level_verdict = schema.Choice(
[7723]517        title = _(u'Verdict'),
[7619]518        source = VerdictSource(),
[8820]519        default = '0',
[6793]520        required = False,
521        )
522
[9161]523    validated_by = schema.TextLine(
524        title = _(u'Validated by'),
525        default = None,
526        required = False,
527        )
528
529    validation_date = schema.Datetime(
530        title = _(u'Validation Date'),
531        required = False,
532        readonly = False,
533        )
534
[9690]535    total_credits = schema.Int(
536        title = _(u'Total Credits'),
537        required = False,
538        readonly = True,
539        )
540
541    gpa = schema.Int(
542        title = _(u'GPA'),
543        required = False,
544        readonly = True,
545        )
546
[8920]547    def addCourseTicket(ticket, course):
[8182]548        """Add a course ticket object.
549        """
550
[9501]551    def addCertCourseTickets(cert):
552        """Collect all certificate courses and create course
553        tickets automatically.
554        """
555
[7819]556class ICourseTicket(IKofaObject):
[9420]557    """An interface for course tickets.
[6781]558
559    """
[6783]560    code = Attribute('code of the original course')
[9253]561    certcode = Attribute('certificate code of the study course')
[9684]562    grade = Attribute('grade calculated from score')
563    weight = Attribute('weight calculated from score')
[9698]564    removable_by_student = Attribute('Is student allowed to remove the ticket?')
[9925]565    level_session = Attribute('session of the level the ticket has been added to')
566    level = Attribute('id of the level the ticket has been added to')
[6781]567
[9420]568    title = schema.TextLine(
569        title = _(u'Title'),
570        required = False,
571        )
572
573    fcode = schema.TextLine(
574        title = _(u'Faculty Code'),
575        required = False,
576        )
577
578    dcode = schema.TextLine(
579        title = _(u'Department Code'),
580        required = False,
581        )
582
583    semester = schema.Choice(
584        title = _(u'Semester/Term'),
585        source = SemesterSource(),
586        required = False,
587        )
588
589    passmark = schema.Int(
590        title = _(u'Passmark'),
591        required = False,
592        )
593
594    credits = schema.Int(
595        title = _(u'Credits'),
596        required = False,
597        )
598
[7665]599    mandatory = schema.Bool(
[9320]600        title = _(u'Required'),
[6795]601        default = False,
602        required = False,
603        )
604
[6781]605    score = schema.Int(
[7723]606        title = _(u'Score'),
[9684]607        default = None,
[6781]608        required = False,
609        )
610
[7661]611    carry_over = schema.Bool(
[7723]612        title = _(u'Carry-over Course'),
[7661]613        default = False,
614        required = False,
615        )
616
[9420]617    automatic = schema.Bool(
618        title = _(u'Automatical Creation'),
619        default = False,
[9316]620        required = False,
621        )
622
[7633]623
[9420]624class ICourseTicketAdd(IKofaObject):
[7150]625    """An interface for adding course tickets.
[6795]626
627    """
628    course = schema.Choice(
[7723]629        title = _(u'Course'),
[6795]630        source = CourseSource(),
631        readonly = False,
632        )
633
[9420]634class ICourseTicketImport(ICourseTicket):
635    """An interface for importing course results and nothing more.
636
637    """
638    score = schema.Int(
639        title = _(u'Score'),
640        required = False,
641        readonly = False,
642        )
643
644    level_session = schema.Choice(
645        title = _(u'Level Session'),
646        source = academic_sessions_vocab,
647        required = False,
648        readonly = False,
649        )
650
[7819]651class IStudentAccommodation(IKofaObject):
[6635]652    """A container for student accommodation objects.
653
654    """
655
[9423]656    def addBedTicket(bedticket):
657        """Add a bed ticket object.
658        """
659
660
[7819]661class IBedTicket(IKofaObject):
[6989]662    """A ticket for accommodation booking.
663
664    """
[6996]665    bed = Attribute('The bed object.')
666
667    bed_coordinates = schema.TextLine(
[9424]668        title = _(u'Allocated Bed'),
[9423]669        required = True,
[7014]670        readonly = False,
[6992]671        )
672
[6996]673    bed_type = schema.TextLine(
[9424]674        title = _(u'Requested Bed Type'),
[9423]675        required = True,
[7014]676        readonly = False,
[6996]677        )
678
[6992]679    booking_session = schema.Choice(
[7723]680        title = _(u'Session'),
[6992]681        source = academic_sessions_vocab,
682        required = True,
[7014]683        readonly = True,
[6992]684        )
685
[8170]686    booking_date = schema.Datetime(
[7723]687        title = _(u'Booking Date'),
[6992]688        required = False,
[7014]689        readonly = True,
[6992]690        )
691
692    booking_code = schema.TextLine(
[7723]693        title = _(u'Booking Activation Code'),
[6992]694        required = False,
[7014]695        readonly = True,
[6992]696        )
697
[6994]698    def getSessionString():
[7633]699        """Returns the title of academic_sessions_vocab term.
[7150]700
[6994]701        """
[6992]702
[6860]703class IStudentPaymentsContainer(IPaymentsContainer):
[6635]704    """A container for student payment objects.
705
706    """
707
[6877]708class IStudentOnlinePayment(IOnlinePayment):
709    """A student payment via payment gateways.
710
711    """
712
[9148]713    p_current = schema.Bool(
714        title = _(u'Current Session Payment'),
715        default = True,
716        required = False,
717        )
718
[8268]719    p_level = schema.Int(
720        title = _(u'Payment Level'),
721        required = False,
722        )
[6877]723
[8422]724    def doAfterStudentPayment():
725        """Process student after payment was made.
726
727        """
728
[8453]729    def doAfterStudentPaymentApproval():
730        """Process student after payment was approved.
731
732        """
733
[8420]734    def approveStudentPayment():
[8422]735        """Approve payment and process student.
[8420]736
737        """
738
[8268]739IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
740    'p_session'].order
[8408]741
[9864]742class IStudentPreviousPayment(IKofaObject):
[9148]743    """An interface for adding previous session payments.
744
745    """
746
[9864]747    p_category = schema.Choice(
748        title = _(u'Payment Category'),
749        default = u'schoolfee',
750        source = PreviousPaymentCategorySource(),
751        required = True,
752        )
753
[9148]754    p_session = schema.Choice(
755        title = _(u'Payment Session'),
756        source = academic_sessions_vocab,
757        required = True,
758        )
759
760    p_level = schema.Choice(
761        title = _(u'Payment Level'),
762        source = StudyLevelSource(),
763        required = True,
764        )
765
[9864]766class IStudentBalancePayment(IKofaObject):
767    """An interface for adding balances.
768
769    """
770
[9868]771    p_category = schema.Choice(
[9864]772        title = _(u'Payment Category'),
773        default = u'schoolfee',
774        required = True,
[9868]775        source = BalancePaymentCategorySource(),
[9864]776        )
777
778    balance_session = schema.Choice(
779        title = _(u'Payment Session'),
780        source = academic_sessions_vocab,
781        required = True,
782        )
783
784    balance_level = schema.Choice(
785        title = _(u'Payment Level'),
786        source = StudyLevelSource(),
787        required = True,
788        )
789
790    balance_amount = schema.Float(
791        title = _(u'Balance Amount'),
[9874]792        default = None,
[9864]793        required = True,
794        readonly = False,
795        description = _(
796            u'Balance in Naira '),
797        )
798
[8408]799class ICSVStudentExporter(ICSVExporter):
800    """A regular ICSVExporter that additionally supports exporting
801      data from a given student object.
802    """
[9801]803    def get_filtered(site, **kw):
[9797]804        """Get a filtered set of students.
805        """
[8408]806
807    def export_student(student, filepath=None):
808        """Export data for a given student.
809        """
[9734]810
[9797]811    def export_filtered(site, filepath=None, **kw):
[9734]812        """Export filtered set of students.
813        """
Note: See TracBrowser for help on using the repository browser.