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

Last change on this file since 11580 was 11450, checked in by Henrik Bettermann, 11 years ago

Move ContextualDictSourceFactoryBase? to waeup.kofa.interfaces to avoid circular imports.

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