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

Last change on this file since 13314 was 13314, checked in by Henrik Bettermann, 9 years ago

Add maint_payment_made method to BedTicket? class.

  • Property svn:keywords set to Id
File size: 25.1 KB
Line 
1## $Id: interfaces.py 13314 2015-10-13 17:29:07Z 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.browser.interfaces import IStudentNavigationBase
24from waeup.kofa.interfaces import (
25    IKofaObject, academic_sessions_vocab, validate_email, ICSVExporter,
26    ContextualDictSourceFactoryBase, IKofaUtils)
27from waeup.kofa.interfaces import MessageFactory as _
28from waeup.kofa.schema import TextLineChoice, FormattedDate, PhoneNumber
29from waeup.kofa.students.vocabularies import (
30    StudyLevelSource, contextual_reg_num_source, contextual_mat_num_source,
31    GenderSource, nats_vocab
32    )
33from waeup.kofa.payments.interfaces import (
34    IPaymentsContainer, IOnlinePayment)
35from waeup.kofa.university.vocabularies import (
36    CourseSource, StudyModeSource, CertificateSource, SemesterSource,
37    )
38
39class PreviousPaymentCategorySource(ContextualDictSourceFactoryBase):
40    """A source that delivers all selectable categories of previous session
41    payments.
42    """
43    #: name of dict to deliver from kofa utils.
44    DICT_NAME = 'PREVIOUS_PAYMENT_CATEGORIES'
45
46class BalancePaymentCategorySource(ContextualDictSourceFactoryBase):
47    """A source that delivers all selectable items of balance payments.
48    """
49    #: name of dict to deliver from kofa utils.
50    DICT_NAME = 'BALANCE_PAYMENT_CATEGORIES'
51
52# VerdictSource can't be placed into the vocabularies module because it
53# requires importing IStudentsUtils which then leads to circular imports.
54class VerdictSource(BasicContextualSourceFactory):
55    """A verdicts source delivers all verdicts provided
56    in the portal.
57    """
58    def getValues(self, context):
59        verdicts_dict = getUtility(IKofaUtils).VERDICTS_DICT
60        return sorted(verdicts_dict.keys())
61
62    def getToken(self, context, value):
63        return value
64
65    def getTitle(self, context, value):
66        verdicts_dict = getUtility(IKofaUtils).VERDICTS_DICT
67        if value != '0':
68            return verdicts_dict[value] + ' (%s)' % value
69        return verdicts_dict[value]
70
71
72class IStudentsUtils(Interface):
73    """A collection of methods which are subject to customization.
74    """
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
83    def setPaymentDetails(category, student, previous_session=None,
84            previous_level=None,):
85        """Create Payment object and set the payment data of a student for
86        the payment category specified.
87        """
88
89    def increaseMatricInteger(student):
90        """Increase counter for matric numbers.
91
92        This counter can be a centrally stored attribute or an attribute of
93        faculties, departments or certificates. In the base package the counter
94        is as an attribute of the site configuration object.
95        """
96
97    def constructMatricNumber(student):
98        """Fetch the matric number counter which fits the student and
99        construct the new matric number of the student.
100
101        In the base package the counter is returned which is as an attribute
102        of the site configuration object.
103        """
104
105    def setMatricNumber(student):
106        """Set matriculation number of student.
107
108        If the student's matric number is unset a new matric number is
109        constructed according to the matriculation number construction rules
110        defined in the constructMatricNumber method. The new matric number is
111        set, the students catalog updated. The corresponding matric number
112        counter is increased by one.
113
114        This method is tested but not used in the base package. It can
115        be used in custom packages by adding respective views
116        and by customizing increaseMatricInteger and constructMatricNumber
117        according to the university's matriculation number construction rules.
118
119        The method can be disabled by setting the counter to zero.
120        """
121
122    def getAccommodation_details(student):
123        """Determine the accommodation dates of a student.
124        """
125
126    def selectBed(available_beds):
127        """Select a bed from a list of available beds.
128        In the standard configuration we select the first bed found,
129        but can also randomize the selection if we like.
130        """
131
132    def getPDFCreator(context):
133        """Get some IPDFCreator instance suitable for use with `context`.
134        """
135
136    def renderPDF(view, subject='', filename='slip.pdf',):
137        """Render pdf slips for various pages.
138        """
139
140class IStudentsContainer(IKofaObject):
141    """A students container contains university students.
142    """
143    def addStudent(student):
144        """Add an IStudent object and subcontainers.
145        """
146
147    unique_student_id = Attribute("""A unique student id.""")
148
149class IStudentNavigation(IStudentNavigationBase):
150    """Interface needed for navigation and logging. This interface is
151    implemented by all content classes in the students section.
152    """
153    student = Attribute('Student object of context')
154
155    def writeLogMessage(view, message):
156        """Add an INFO message to students.log.
157        """
158
159class IStudentBase(IKofaObject):
160    """Representation of student base data.
161    """
162    history = Attribute('Object history, a list of messages')
163    state = Attribute('Registration state')
164    translated_state = Attribute('Real name of the registration state')
165    certcode = Attribute('Certificate code of any chosen study course')
166    depcode = Attribute('Department code of any chosen study course')
167    faccode = Attribute('Faculty code of any chosen study course')
168    entry_session = Attribute('Entry session')
169    current_session = Attribute('Current session')
170    current_level = Attribute('Current level')
171    current_mode = Attribute('Current mode')
172    current_verdict = Attribute('Current verdict')
173    fullname = Attribute('All name parts separated by hyphens')
174    display_fullname = Attribute('Fullname as displayed on pages')
175    is_postgrad = Attribute('True if postgraduate student')
176    is_special_postgrad = Attribute('True if special postgraduate student')
177    is_fresh = Attribute('True if fresh student')
178    before_payment = Attribute('True if no previous payment has to be made')
179    personal_data_expired = Attribute('True if personal data expired')
180    transcript_enabled = Attribute('True if transcript processing is enabled')
181    clearance_locked = Attribute('True if clearance form is locked')
182
183    password = Attribute('Encrypted password')
184    temp_password = Attribute('Dictionary with user name, timestamp and encrypted password')
185
186    suspended = schema.Bool(
187        title = _(u'Account suspended'),
188        default = False,
189        required = False,
190        )
191
192    suspended_comment = schema.Text(
193        title = _(u"Reasons for Deactivation"),
194        required = False,
195        description = _(
196            u'This message will be shown if and only if deactivated '
197            'students try to login.'),
198        )
199
200    student_id = schema.TextLine(
201        title = _(u'Student Id'),
202        required = False,
203        )
204
205    firstname = schema.TextLine(
206        title = _(u'First Name'),
207        required = True,
208        )
209
210    middlename = schema.TextLine(
211        title = _(u'Middle Name'),
212        required = False,
213        )
214
215    lastname = schema.TextLine(
216        title = _(u'Last Name (Surname)'),
217        required = True,
218        )
219
220    sex = schema.Choice(
221        title = _(u'Sex'),
222        source = GenderSource(),
223        required = True,
224        )
225
226    reg_number = TextLineChoice(
227        title = _(u'Registration Number'),
228        required = True,
229        readonly = False,
230        source = contextual_reg_num_source,
231        )
232
233    matric_number = TextLineChoice(
234        title = _(u'Matriculation Number'),
235        required = False,
236        readonly = False,
237        source = contextual_mat_num_source,
238        )
239
240    adm_code = schema.TextLine(
241        title = _(u'PWD Activation Code'),
242        required = False,
243        readonly = False,
244        )
245
246    email = schema.ASCIILine(
247        title = _(u'Email'),
248        required = True,
249        constraint=validate_email,
250        )
251    phone = PhoneNumber(
252        title = _(u'Phone'),
253        description = u'',
254        required = False,
255        )
256
257    def setTempPassword(user, password):
258        """Set a temporary password (LDAP-compatible) SSHA encoded for
259        officers.
260        """
261
262    def getTempPassword():
263        """Check if a temporary password has been set and if it
264        is not expired. Return the temporary password if valid,
265        None otherwise. Unset the temporary password if expired.
266        """
267
268    def transfer(certificate, current_session,
269        current_level, current_verdict):
270        """ Creates a new studycourse and backups the old one.
271        """
272
273    def revert_transfer():
274        """ Revert previous transfer.
275        """
276
277class IUGStudentClearance(IKofaObject):
278    """Representation of undergraduate student clearance data.
279    """
280    officer_comment = schema.Text(
281        title = _(u"Officer's Comment"),
282        required = False,
283        )
284
285    clr_code = schema.TextLine(
286        title = _(u'CLR Activation Code'),
287        required = False,
288        readonly = False,
289        )
290
291    date_of_birth = FormattedDate(
292        title = _(u'Date of Birth'),
293        required = True,
294        show_year = True,
295        )
296
297    nationality = schema.Choice(
298        vocabulary = nats_vocab,
299        title = _(u'Nationality'),
300        required = False,
301        )
302
303class IPGStudentClearance(IUGStudentClearance):
304    """Representation of postgraduate student clearance data.
305    """
306    employer = schema.TextLine(
307        title = _(u'Employer'),
308        required = False,
309        readonly = False,
310        )
311
312class IStudentPersonal(IKofaObject):
313    """Representation of student personal data.
314    """
315    personal_updated = schema.Datetime(
316        title = _(u'Updated'),
317        required = False,
318        readonly = False,
319        )
320
321    perm_address = schema.Text(
322        title = _(u'Permanent Address'),
323        required = False,
324        )
325
326class IStudentTranscript(IKofaObject):
327    """Representation of student transcript data.
328    """
329
330    transcript_comment = schema.Text(
331        title = _(u'Comment'),
332        required = False,
333        )
334
335
336class IStudent(IStudentBase,IUGStudentClearance,IPGStudentClearance,
337    IStudentPersonal, IStudentTranscript):
338    """Representation of a student.
339    """
340
341class IStudentPersonalEdit(IStudentPersonal):
342    """Interface for editing personal data by students.
343    Here we can repeat the fields from IStudentPersonal and set the
344    `required` if necessary.
345    """
346
347    perm_address = schema.Text(
348        title = _(u'Permanent Address'),
349        required = True,
350        )
351
352class IStudentUpdateByRegNo(IStudent):
353    """Representation of a student. Skip regular reg_number validation.
354    """
355    reg_number = schema.TextLine(
356        title = _(u'Registration Number'),
357        required = False,
358        )
359
360class IStudentUpdateByMatricNo(IStudent):
361    """Representation of a student. Skip regular matric_number validation.
362    """
363    matric_number = schema.TextLine(
364        title = _(u'Matriculation Number'),
365        required = False,
366        )
367
368class IStudentRequestPW(IStudent):
369    """Representation of a student for first-time password request.
370    This interface is used when students use the requestpw page to
371    login for the the first time.
372    """
373    number = schema.TextLine(
374        title = _(u'Registr. or Matric. Number'),
375        required = True,
376        )
377
378    firstname = schema.TextLine(
379        title = _(u'First Name'),
380        required = True,
381        )
382
383    email = schema.ASCIILine(
384        title = _(u'Email Address'),
385        required = True,
386        constraint=validate_email,
387        )
388
389class IStudentStudyCourse(IKofaObject):
390    """Representation of student study course data.
391    """
392    next_session_allowed = Attribute('True if the student can proceed to next session')
393    is_postgrad = Attribute('True if student is postgraduate student')
394    is_current = Attribute('True if the study course is the current course of studies')
395    is_previous = Attribute('True if the study course is the previous course of studies')
396
397    certificate = schema.Choice(
398        title = _(u'Certificate'),
399        source = CertificateSource(),
400        required = False,
401        )
402
403    entry_mode = schema.Choice(
404        title = _(u'Entry Mode'),
405        source = StudyModeSource(),
406        required = True,
407        readonly = False,
408        )
409
410    entry_session = schema.Choice(
411        title = _(u'Entry Session'),
412        source = academic_sessions_vocab,
413        #default = datetime.now().year,
414        required = True,
415        readonly = False,
416        )
417
418    current_session = schema.Choice(
419        title = _(u'Current Session'),
420        source = academic_sessions_vocab,
421        required = True,
422        readonly = False,
423        )
424
425    current_level = schema.Choice(
426        title = _(u'Current Level'),
427        source = StudyLevelSource(),
428        required = False,
429        readonly = False,
430        )
431
432    current_verdict = schema.Choice(
433        title = _(u'Current Verdict'),
434        source = VerdictSource(),
435        default = '0',
436        required = False,
437        )
438
439    previous_verdict = schema.Choice(
440        title = _(u'Previous Verdict'),
441        source = VerdictSource(),
442        default = '0',
443        required = False,
444        )
445
446    def addStudentStudyLevel(cert, studylevel):
447        """Add a study level object.
448        """
449
450    def getTranscriptData():
451        """Get a sorted list of dicts with level and course ticket data.
452        This method is used for transcripts.
453        """
454
455class IStudentStudyCourseTransfer(IStudentStudyCourse):
456    """An interface used for student transfers.
457    """
458    certificate = schema.Choice(
459        title = _(u'Certificate'),
460        source = CertificateSource(),
461        required = True,
462        )
463
464    current_level = schema.Choice(
465        title = _(u'Current Level'),
466        source = StudyLevelSource(),
467        required = True,
468        readonly = False,
469        )
470
471    entry_session = schema.Choice(
472        title = _(u'Entry Session'),
473        source = academic_sessions_vocab,
474        #default = datetime.now().year,
475        required = False,
476        readonly = False,
477        )
478
479
480IStudentStudyCourseTransfer['certificate'].order = IStudentStudyCourse[
481    'certificate'].order
482IStudentStudyCourseTransfer['current_level'].order = IStudentStudyCourse[
483    'current_level'].order
484
485class IStudentStudyCourseTranscript(IKofaObject):
486    """An interface for student transcripts.
487    """
488    entry_mode = schema.Choice(
489        title = _(u'Entry Mode'),
490        source = StudyModeSource(),
491        required = True,
492        readonly = False,
493        )
494
495    entry_session = schema.Choice(
496        title = _(u'Entry Session'),
497        source = academic_sessions_vocab,
498        #default = datetime.now().year,
499        required = True,
500        readonly = False,
501        )
502
503class IStudentVerdictUpdate(IKofaObject):
504    """A interface for verdict imports.
505    """
506    current_verdict = schema.Choice(
507        title = _(u'Current Verdict'),
508        source = VerdictSource(),
509        required = True,
510        )
511
512    current_session = schema.Choice(
513        title = _(u'Current Session'),
514        source = academic_sessions_vocab,
515        required = True,
516        )
517
518    current_level = schema.Choice(
519        title = _(u'Current Level'),
520        source = StudyLevelSource(),
521        required = True,
522        )
523
524    bypass_validation = schema.Bool(
525        title = _(u'Bypass validation'),
526        required = False,
527        )
528
529    validated_by = schema.TextLine(
530        title = _(u'Validated by'),
531        required = False,
532        )
533
534class IStudentStudyLevel(IKofaObject):
535    """A representation of student study level data.
536    """
537    certcode = Attribute('The certificate code of the study course')
538    is_current_level = Attribute('True if level is current level of the student')
539    level_title = Attribute('Level title from source')
540    getSessionString = Attribute('Session title from source')
541    number_of_tickets = Attribute('Number of tickets contained in this level')
542    passed_params = Attribute('Information about passed and failed courses')
543    gpa_params_rectified = Attribute('Corrected sessional GPA parameters')
544    gpa_params = Attribute('GPA parameters for this level.')
545    cumulative_params = Attribute('Cumulative GPA and other cumulative parameters for this level')
546    course_registration_allowed = Attribute('True if registerin courses is allowed')
547
548    level = schema.Choice(
549        title = _(u'Level'),
550        source = StudyLevelSource(),
551        required = True,
552        readonly = False,
553        )
554
555    level_session = schema.Choice(
556        title = _(u'Session'),
557        source = academic_sessions_vocab,
558        required = True,
559        )
560
561    level_verdict = schema.Choice(
562        title = _(u'Verdict'),
563        source = VerdictSource(),
564        default = '0',
565        required = False,
566        )
567
568    validated_by = schema.TextLine(
569        title = _(u'Validated by'),
570        default = None,
571        required = False,
572        )
573
574    validation_date = schema.Datetime(
575        title = _(u'Validation Date'),
576        required = False,
577        readonly = False,
578        )
579
580    total_credits = schema.Int(
581        title = _(u'Total Credits'),
582        required = False,
583        readonly = True,
584        )
585
586    gpa = schema.Int(
587        title = _(u'Unrectified GPA'),
588        required = False,
589        readonly = True,
590        )
591
592    def addCourseTicket(ticket, course):
593        """Add a course ticket object.
594        """
595
596    def addCertCourseTickets(cert):
597        """Collect all certificate courses and create course
598        tickets automatically.
599        """
600
601class ICourseTicket(IKofaObject):
602    """A representation of course ticket data.
603    """
604    certcode = Attribute('Certificate code of the study course')
605    level_session = Attribute('Session of the study level the ticket has been added to')
606    level = Attribute('Level value of the study level the ticket has been added to')
607    grade = Attribute('Grade calculated from score')
608    weight = Attribute('Weight calculated from score')
609    removable_by_student = Attribute('True if student is allowed to remove the ticket')
610    editable_by_lecturer = Attribute('True if lecturer is allowed to edit the ticket')
611
612    code = Attribute('Code of the original course')
613
614    title = schema.TextLine(
615        title = _(u'Title'),
616        required = False,
617        )
618
619    fcode = schema.TextLine(
620        title = _(u'Faculty Code'),
621        required = False,
622        )
623
624    dcode = schema.TextLine(
625        title = _(u'Department Code'),
626        required = False,
627        )
628
629    semester = schema.Choice(
630        title = _(u'Semester/Term'),
631        source = SemesterSource(),
632        required = False,
633        )
634
635    passmark = schema.Int(
636        title = _(u'Passmark'),
637        required = False,
638        )
639
640    credits = schema.Int(
641        title = _(u'Credits'),
642        required = False,
643        )
644
645    mandatory = schema.Bool(
646        title = _(u'Required'),
647        default = False,
648        required = False,
649        )
650
651    score = schema.Int(
652        title = _(u'Score'),
653        default = None,
654        required = False,
655        missing_value = None,
656        )
657
658    carry_over = schema.Bool(
659        title = _(u'Carry-over Course'),
660        default = False,
661        required = False,
662        )
663
664    automatic = schema.Bool(
665        title = _(u'Automatical Creation'),
666        default = False,
667        required = False,
668        )
669
670class ICourseTicketAdd(IKofaObject):
671    """An interface for adding course tickets.
672    """
673    course = schema.Choice(
674        title = _(u'Course'),
675        source = CourseSource(),
676        readonly = False,
677        )
678
679class ICourseTicketImport(ICourseTicket):
680    """An interface for importing course results and nothing more.
681    """
682    score = schema.Int(
683        title = _(u'Score'),
684        required = False,
685        readonly = False,
686        )
687
688    level_session = schema.Choice(
689        title = _(u'Level Session'),
690        source = academic_sessions_vocab,
691        required = False,
692        readonly = False,
693        )
694
695class IStudentAccommodation(IKofaObject):
696    """A container for student accommodation objects.
697    """
698
699    def addBedTicket(bedticket):
700        """Add a bed ticket object.
701        """
702
703
704class IBedTicket(IKofaObject):
705    """A representation of accommodation booking data.
706    """
707    bed = Attribute('The bed object')
708    booking_date = Attribute('Date of booking the bed')
709    maint_payment_made = Attribute('True if maintenance payment is made')
710
711    display_coordinates = schema.TextLine(
712        title = _(u'Allocated Bed'),
713        required = False,
714        readonly = True,
715        )
716
717    bed_coordinates = schema.TextLine(
718        title = u'',
719        required = True,
720        readonly = False,
721        )
722
723    bed_type = schema.TextLine(
724        title = _(u'Requested Bed Type'),
725        required = True,
726        readonly = False,
727        )
728
729    booking_session = schema.Choice(
730        title = _(u'Session'),
731        source = academic_sessions_vocab,
732        required = True,
733        readonly = True,
734        )
735
736    booking_date = schema.Datetime(
737        title = _(u'Booking Date'),
738        required = False,
739        readonly = True,
740        )
741
742    booking_code = schema.TextLine(
743        title = _(u'Booking Activation Code'),
744        required = False,
745        readonly = True,
746        )
747
748    def getSessionString():
749        """Returns the title of academic_sessions_vocab term of the session
750        when the bed was booked.
751        """
752
753class IStudentPaymentsContainer(IPaymentsContainer):
754    """A container for student payment objects.
755    """
756
757class IStudentOnlinePayment(IOnlinePayment):
758    """A student payment via payment gateways.
759    """
760
761    p_current = schema.Bool(
762        title = _(u'Current Session Payment'),
763        default = True,
764        required = False,
765        )
766
767    p_level = schema.Int(
768        title = _(u'Payment Level'),
769        required = False,
770        )
771
772    def doAfterStudentPayment():
773        """Process student after payment was made.
774        """
775
776    def doAfterStudentPaymentApproval():
777        """Process student after payment was approved.
778        """
779
780    def approveStudentPayment():
781        """Approve payment and process student.
782        """
783
784IStudentOnlinePayment['p_level'].order = IStudentOnlinePayment[
785    'p_session'].order
786
787class IStudentPreviousPayment(IKofaObject):
788    """An interface for adding previous session payments.
789    """
790
791    p_category = schema.Choice(
792        title = _(u'Payment Category'),
793        default = u'schoolfee',
794        source = PreviousPaymentCategorySource(),
795        required = True,
796        )
797
798    p_session = schema.Choice(
799        title = _(u'Payment Session'),
800        source = academic_sessions_vocab,
801        required = True,
802        )
803
804    p_level = schema.Choice(
805        title = _(u'Payment Level'),
806        source = StudyLevelSource(),
807        required = True,
808        )
809
810class IStudentBalancePayment(IKofaObject):
811    """An interface for adding balances.
812    """
813
814    p_category = schema.Choice(
815        title = _(u'Payment Category'),
816        default = u'schoolfee',
817        required = True,
818        source = BalancePaymentCategorySource(),
819        )
820
821    balance_session = schema.Choice(
822        title = _(u'Payment Session'),
823        source = academic_sessions_vocab,
824        required = True,
825        )
826
827    balance_level = schema.Choice(
828        title = _(u'Payment Level'),
829        source = StudyLevelSource(),
830        required = True,
831        )
832
833    balance_amount = schema.Float(
834        title = _(u'Balance Amount'),
835        default = None,
836        required = True,
837        readonly = False,
838        description = _(
839            u'Balance in Naira '),
840        )
841
842class ICSVStudentExporter(ICSVExporter):
843    """A regular ICSVExporter that additionally supports exporting
844      data from a given student object.
845    """
846    def get_filtered(site, **kw):
847        """Get a filtered set of students.
848        """
849
850    def get_selected(site, selected):
851        """Get set of selected students.
852        """
853
854    def export_student(student, filepath=None):
855        """Export data for a given student.
856        """
857
858    def export_filtered(site, filepath=None, **kw):
859        """Export data for filtered set of students.
860        """
861
862    def export_selected(site, filepath=None, **kw):
863        """Export data for selected set of students.
864        """
Note: See TracBrowser for help on using the repository browser.