source: main/waeup.sirp/branches/ulif-images/src/waeup/sirp/jambtables/interfaces.py @ 11078

Last change on this file since 11078 was 5530, checked in by uli, 14 years ago

Commit local changes (work inprogress)

File size: 20.7 KB
RevLine 
[5247]1##
2## interfaces.py
3## Login : <uli@pu.smp.net>
4## Started on  Sun Jun 27 11:06:23 2010 Uli Fouquet
5## $Id$
6##
7## Copyright (C) 2010 Uli Fouquet
8## This program is free software; you can redistribute it and/or modify
9## it under the terms of the GNU General Public License as published by
10## the Free Software Foundation; either version 2 of the License, or
11## (at your option) any later version.
12##
13## This program is distributed in the hope that it will be useful,
14## but WITHOUT ANY WARRANTY; without even the implied warranty of
15## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16## GNU General Public License for more details.
17##
18## You should have received a copy of the GNU General Public License
19## along with this program; if not, write to the Free Software
20## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21##
22"""Interfaces for JAMB data tables and related components.
23"""
[5530]24import os
25import waeup.sirp.browser
26from hurry.file import HurryFile
[5319]27from zc.sourcefactory.basic import BasicSourceFactory
[5251]28from zope import schema
[5530]29from zope.app.file.interfaces import IImage
[5432]30from zope.interface import Interface, Attribute
31from zope.pluggableauth.interfaces import IPrincipalInfo
32from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
[5530]33from waeup.sirp.interfaces import IWAeUPObject
34from waeup.sirp.image.schema import ImageFile
[5247]35
[5530]36IMAGE_PATH = os.path.join(
37    os.path.dirname(waeup.sirp.browser.__file__),
38    'static'
39    )
40DEFAULT_PASSPORT_IMAGE_MALE = HurryFile(
41    'passport.jpg',
42    open(os.path.join(IMAGE_PATH, 'placeholder_m.jpg')).read(),
43    )
44DEFAULT_PASSPORT_IMAGE_FEMALE = HurryFile(
45    'passport.jpg',
46    open(os.path.join(IMAGE_PATH, 'placeholder_f.jpg')).read(),
47    )
[5432]48
[5319]49class GenderSource(BasicSourceFactory):
50    """A gender source delivers basically a mapping
51       ``{'m': 'male', 'f': 'female'}``
[5271]52
[5319]53       Using a source, we make sure that the tokens (which are
54       stored/expected for instance from CSV files) are something one
55       can expect and not cryptic IntIDs.
56    """
57    def getValues(self):
58        return ['m', 'f']
59
60    def getToken(self, value):
61        return value[0].lower()
62       
63    def getTitle(self, value):
64        if value == 'm':
65            return 'male'
66        if value == 'f':
67            return 'female'
68
[5247]69class IJAMBDataTable(IWAeUPObject):
70    """A table containing JAMB data.
71    """
[5251]72    import_datetime = schema.Datetime(
73        title = u'Datetime of import of contained data.',
74        required = False,
75        )
76
77    importer_username = schema.TextLine(
78        title = u'Name of user who initiated import.',
79        required = False,
80        )
81
82    def __iter__():
83        """An iterator over all data elements.
84        """
85
86    def keys():
87        """Get iterator over all registration numbers of data.
88        """
89
90    def items():
91        """Get iterator over tuples of registration numbers and datasets.
92        """
93
94    def clear():
95        """Clear all data contained.
96
97        This will also erase any import data.
98        """
99
[5252]100    def importFromCSV(filepath, username=None):
[5251]101        """Import data from filepath.
[5252]102
103        `filepath` - the path to the CSV file to import data from.
104
105        `username` - the (optional) username of the importing person.
[5251]106        """
[5271]107       
108class IResultEntry(IWAeUPObject):
109    subject = schema.TextLine(
110        title = u'Subject',
111        description = u'The subject',
112        required=False,
113        )
114    score = schema.TextLine(
115        title = u'Score',
116        description = u'The score',
117        required=False,
118        )
[5268]119
[5319]120class IApplicantBaseData(IWAeUPObject):
121    """The data for an applicant.
[5268]122
[5319]123    This is a base interface with no field (except ``reg_no``)
124    required. For use with importers, forms, etc., please use one of
125    the derived interfaces below, which set more fields to required
126    state, depending on use-case.
[5268]127    """
128    reg_no = schema.TextLine(
129        title = u'JAMB Registration Number',
130        )
131    access_code = schema.TextLine(
132        title = u'Access Code',
[5319]133        required = False,
[5268]134        )
135    serial = schema.TextLine(
136        title = u'Serial Number',
137        required = False,
138        )
139    course1 = schema.TextLine(
140        title = u'1st Choice Course of Study',
[5319]141        required = False,
[5268]142        )
143    course2 = schema.TextLine(
144        title = u'2nd Choice Course of Study',
145        required = False,
146        )
147    course3 = schema.TextLine(
148        title = u'3rd Choice Course of Study',
149        required = False,
150        )
151    firstname = schema.TextLine(
152        title = u'First Name',
[5319]153        required = False,
[5268]154        )
155    middlenames = schema.TextLine(
156        title = u'Middle Names',
[5319]157        required = False,
[5268]158        )
159    lastname = schema.TextLine(
160        title = u'Surname/Full Name',
[5319]161        required = False,
[5268]162        )
163    jamb_age = schema.Int(
164        title = u'Age (provided by JAMB)',
165        required = False,
166        )
167    date_of_birth = schema.Date(
168        title = u'Date of Birth',
[5319]169        required = False,
[5268]170        )
171    jamb_state = schema.TextLine(
172        title = u'State (provided by JAMB)',
[5319]173        required = False,
[5268]174        )
175    jamb_lga = schema.TextLine(
176        title = u'LGA (provided by JAMB)',
[5319]177        required = False,
[5268]178        )
179    lga = schema.TextLine(
180        # XXX: should be choice
181        title = u'State/LGA (confirmed by applicant)',
[5319]182        required = False,
[5268]183        )
184    sex = schema.Choice(
185        title = u'Sex',
[5319]186        source = GenderSource(),
187        default = u'm',
188        required = False,
[5268]189        )
190    email = schema.TextLine(
191        title = u'Email',
192        required = False,
193        )
194    phone = schema.TextLine(
195        title = u'Phone',
196        required = False,
197        )
[5530]198    #passport = schema.Bool(
199    #    title = u'Passport Photograph',
200    #    default = True,
201    #    required = False,
202    #    )
203    passport = ImageFile(
[5268]204        title = u'Passport Photograph',
[5530]205        default = DEFAULT_PASSPORT_IMAGE_MALE,
206        required = True,
[5268]207        )
208    aos = schema.TextLine(
209        # XXX: should be choice
210        title = u'Area of Specialisation',
211        required = False,
212        )
213    subj1 = schema.TextLine(
214        # XXX: should be choice
215        title = u'1st Choice of Study',
216        required = False,
217        )
218    subj2 = schema.TextLine(
219        # XXX: should be choice
220        title = u'2nd Choice of Study',
221        required = False,
222        )
223    subj3 = schema.TextLine(
224        # XXX: should be choice
225        title = u'3rd Choice of Study',
226        required = False,
227        )
228    #
229    # Higher Educational Data
230    #
231    hq_matric_no = schema.TextLine(
232        title = u'Former Matric Number',
233        required = False,
234        )
235    hq_type = schema.TextLine(
236        title = u'Higher Qualification',
237        required = False,
238        )
239    hq_grade = schema.TextLine(
240        title = u'Higher Qualification Grade',
241        required = False,
242        )
243    hq_school = schema.TextLine(
244        title = u'School Attended',
245        required = False,
246        )
247    hq_session = schema.TextLine(
248        title = u'Session Obtained',
249        required = False,
250        )
251    hq_disc = schema.TextLine(
252        title = u'Discipline',
253        required = False,
254        )
255    #
256    # First sitting data
257    #
258    fst_sit_fname = schema.TextLine(
259        title = u'Full Name',
[5319]260        required = False,
[5268]261        )
262    fst_sit_no = schema.TextLine(
263        title = u'Exam Number',
264        required = False,
265        )
266    fst_sit_date = schema.Date(
267        title = u'Exam Date (dd/mm/yyyy)',
268        required = False,
269        )
270    fst_sit_type = schema.TextLine(
271        # XXX: Should be choice
272        title = u'Exam Type',
273        required = False,
274        )
[5271]275    fst_sit_results = schema.List(
[5268]276        title = u'Results',
277        required = False,
[5271]278        value_type = schema.Object(
279            title = u'Entries',
280            schema = IResultEntry,
[5319]281            required = False,
[5271]282            )
[5268]283        )
284    scd_sit_fname = schema.TextLine(
285        title = u'Full Name',
[5319]286        required = False,
[5268]287        )
288    scd_sit_no = schema.TextLine(
289        title = u'Exam Number',
290        required = False,
291        )
292    scd_sit_date = schema.Date(
293        title = u'Exam Date (dd/mm/yyyy)',
294        required = False,
295        )
296    scd_sit_type = schema.TextLine(
297        # XXX: Should be choice
298        title = u'Exam Type',
299        required = False,
300        )
301    scd_sit_results = schema.TextLine(
302        # XXX: Should be nested list of choices
303        title = u'Results',
304        required = False,
305        )
306    #
307    # JAMB scores
308    #
309    eng_score = schema.TextLine(
310        title = u"'English' score",
311        required = False,
312        )
313    subj1score = schema.TextLine(
314        title = u'1st Choice of Study Score',
315        required = False,
316        )
317    subj2score = schema.TextLine(
318        title = u'2nd Choice of Study Score',
319        required = False,
320        )
321    subj3score = schema.TextLine(
322        title = u'3rd Choice of Study Score',
323        required = False,
324        )
325    # XXX: Total score???
326   
327    #
328    # Application Data
329    #
330    application_date = schema.Date(
331        title = u'Application Date',
[5319]332        required = False,
[5268]333        )
334    status = schema.TextLine(
335        # XXX: should be 'status' type
336        title = u'Application Status',
[5319]337        required = False,
[5268]338        )
339    screening_date = schema.Date(
340        title = u'Screening Date',
[5319]341        required = False,
[5268]342        )
343    screening_type = schema.TextLine(
344        # XXX: schould be choice
345        title = u'Screening Type',
[5319]346        required = False,
[5268]347        )
348    screening_score = schema.TextLine(
349        title = u'Screening Score',
[5319]350        required = False,
[5268]351        )
352    screening_venue = schema.TextLine(
353        title = u'Screening Venue',
354        required = False,
355        )
356    total_score = schema.TextLine(
357        title = u'Total Score',
358        required = False,
359        )
360    course_admitted = schema.TextLine(
361        # XXX: should be choice
362        title = u'Admitted Course of Study',
363        required = False,
364        )
365    department = schema.TextLine(
366        # XXX: if we have a course, dept. is not necessary
367        title = u'Department',
368        required = False,
369        )
370    faculty = schema.TextLine(
371        # XXX: if we have a course, faculty is not necessary
372        title = u'Faculty',
373        required = False,
374        )
375    entry_session = schema.TextLine(
[5471]376        # XXX: should be choice, should have sensible default: upcoming session
[5269]377        title = u'Entry Session',
[5319]378        required = False,
[5268]379        )
380    notice = schema.Text(
381        title = u'Notice',
382        required = False,
[5269]383        )
384    student_id = schema.TextLine(
[5268]385        title = u'Student ID',
386        required = False,
387        )
388    import_record_no = schema.TextLine(
389        title = u'Import Record No.',
[5319]390        required = False,
[5268]391        )
392    imported_by = schema.TextLine(
393        title = u'Imported By',
[5319]394        required = False,
[5268]395        )
[5269]396    import_date = schema.Datetime(
[5268]397        title = u'Import Date',
[5319]398        required = False,
[5268]399        )
400    import_from = schema.TextLine(
401        title = u'Import Source',
[5319]402        required = False,
[5268]403        )
[5269]404
[5319]405   
406class IApplicant(IApplicantBaseData):
407    """An applicant.
408
409    This is basically the applicant base data. Here we repeat the
410    fields from base data only with the `required` attribute of
411    required attributes set to True (which is the default).
412    """
413    access_code = schema.TextLine(
414        title = u'Access Code',
415        )
416    course1 = schema.TextLine(
417        title = u'1st Choice Course of Study',
418        )
419    firstname = schema.TextLine(
420        title = u'First Name',
421        )
422    middlenames = schema.TextLine(
423        title = u'Middle Names',
424        )
425    lastname = schema.TextLine(
426        title = u'Surname/Full Name',
427        )
428    date_of_birth = schema.Date(
429        title = u'Date of Birth',
430        )
431    jamb_state = schema.TextLine(
432        title = u'State (provided by JAMB)',
433        )
434    jamb_lga = schema.TextLine(
435        title = u'LGA (provided by JAMB)',
436        )
437    lga = schema.TextLine(
438        # XXX: should be choice
439        title = u'State/LGA (confirmed by applicant)',
440        )
441    sex = schema.Choice(
442        title = u'Sex',
443        source = GenderSource(),
444        default = u'm',
445        )
[5530]446    #passport = schema.Bool(
447    #    title = u'Passport Photograph',
448    #    default = True,
449    #    )
450    passport = ImageFile(
[5319]451        title = u'Passport Photograph',
[5530]452        default = DEFAULT_PASSPORT_IMAGE_MALE,
453        required = True,
[5319]454        )
455    #
456    # Higher Educational Data
457    #
458
459    #
460    # First sitting data
461    #
462    fst_sit_fname = schema.TextLine(
463        title = u'Full Name',
464        )
465
466    #
467    # Second sitting data
468    #
469    scd_sit_fname = schema.TextLine(
470        title = u'Full Name',
471        )
472    #
473    # JAMB scores
474    #
475   
476    #
477    # Application Data
478    #
479    application_date = schema.Date(
480        title = u'Application Date',
481        )
482    status = schema.TextLine(
483        # XXX: should be 'status' type
484        title = u'Application Status',
485        )
486    screening_date = schema.Date(
487        title = u'Screening Date',
488        )
489    screening_type = schema.TextLine(
490        # XXX: schould be choice
491        title = u'Screening Type',
492        )
493    screening_score = schema.TextLine(
494        title = u'Screening Score',
495        )
496    entry_session = schema.TextLine(
497        # XXX: should be choice
498        # XXX: should have sensible default: upcoming session
499        title = u'Entry Session',
500        )
501    import_record_no = schema.TextLine(
502        title = u'Import Record No.',
503        )
504    imported_by = schema.TextLine(
505        title = u'Imported By',
506        )
507    import_date = schema.Datetime(
508        title = u'Import Date',
509        )
510    import_from = schema.TextLine(
511        title = u'Import Source',
512        )
513
[5482]514class IApplicantPDEEditData(IWAeUPObject):
515    """The data set presented to PDE applicants.
516    """
517    reg_no = schema.TextLine(
518        title = u'JAMB Registration Number',
519        readonly = True,
520        )
521    access_code = schema.TextLine(
522        title = u'Access Code',
523        readonly = True,
524        )
525    course1 = schema.TextLine(
526        title = u'1st Choice Course of Study',
527        readonly = True,
528        )
529    course2 = schema.TextLine(
530        title = u'2nd Choice Course of Study',
531        required = False,
532        )
533    course3 = schema.TextLine(
534        title = u'3rd Choice Course of Study',
535        required = False,
536        )
537    lastname = schema.TextLine(
538        title = u'Name',
539        readonly = True,
540        )
541    jamb_age = schema.Int(
542        title = u'Age',
543        readonly = True,
544        )
545    date_of_birth = schema.Date(
546        title = u'Date of Birth',
547        required = True,
548        )
549    jamb_state = schema.TextLine(
550        title = u'State (provided by JAMB)',
551        readonly = True,
552        )
553    jamb_lga = schema.TextLine(
554        title = u'LGA (provided by JAMB)',
555        readonly = True,
556        )
557    lga = schema.TextLine(
558        # XXX: should be choice
559        title = u'State/LGA (confirmed by applicant)',
560        required = False,
561        )
562    email = schema.TextLine(
563        title = u'Email',
564        required = False,
565        )
566    phone = schema.TextLine(
567        title = u'Phone',
568        required = False,
569        )
570    aos = schema.TextLine(
571        # XXX: should be choice
572        title = u'Area of Specialisation',
573        required = False,
574        )
575    subj1 = schema.TextLine(
576        # XXX: should be choice
577        title = u'1st Choice of Study',
578        readonly = True,
579        )
580    subj2 = schema.TextLine(
581        # XXX: should be choice
582        title = u'2nd Choice of Study',
583        required = False,
584        )
585    subj3 = schema.TextLine(
586        # XXX: should be choice
587        title = u'3rd Choice of Study',
588        required = False,
589        )
590   
591    #
592    # Application Data
593    #
594    application_date = schema.Date(
595        title = u'Application Date',
596        readonly = True,
597        )
598    status = schema.TextLine(
599        # XXX: should be 'status' type
600        title = u'Application Status',
601        readonly = True,
602        )
603    screening_date = schema.Date(
604        title = u'Screening Date',
605        readonly = True,
606        )
[5530]607    #passport = schema.Bool(
608    #    title = u'Passport Photograph',
609    #    default = True,
610    #    required = False,
611    #    ),
612    #passport = schema.Bytes(
613    #    title = u'Passport Photograph',
614    #    required = True,
615    #    )
616    #passport = schema.Object(
617    #    title = u'Passport Photograph',
618    #    required = True,
619    #    schema = IImage)
620    passport = ImageFile(
[5486]621        title = u'Passport Photograph',
[5530]622        default = DEFAULT_PASSPORT_IMAGE_MALE,
623        required = True,
[5486]624        )
[5482]625
[5319]626class IApplicantPDEImportData(IApplicantBaseData):
627    """Data for applicants, that passed PDE screening.
628
629    This data set should be suitable for imports from JAMB tables. It
630    is also basicall the basic applicant data from
631    :class:`IApplicantBaseData` only with the required fields set.
632
633    """
634    firstname = schema.TextLine(
635        title = u'First Name',
636        required = True,
637        )
638    middlenames = schema.TextLine(
639        title = u'Middle Names',
640        required = True,
641        )
642    lastname = schema.TextLine(
643        title = u'Surname/Full Name',
644        required = True,
645        )
646    date_of_birth = schema.Date(
647        title = u'Date of Birth',
648        required = True,
649        )
650    jamb_state = schema.TextLine(
651        title = u'State (provided by JAMB)',
652        required = True,
653        )
654    jamb_lga = schema.TextLine(
655        title = u'LGA (provided by JAMB)',
656        required = True,
657        )
658    course1 = schema.TextLine(
659        title = u'1st Choice Course of Study',
660        required = True,
661        )
662    screening_date = schema.Date(
663        title = u'Screening Date',
664        required = True,
665        )
666    screening_type = schema.TextLine(
667        # XXX: schould be choice
668        title = u'Screening Type',
669        required = True,
670        )
671    screening_venue = schema.TextLine(
672        title = u'Screening Venue',
673        required = True,
674        )
675    entry_session = schema.TextLine(
676        # XXX: should be choice
677        # XXX: should have sensible default: upcoming session
678        title = u'Entry Session',
679        required = True,
680        )
681   
[5269]682class IApplicantContainer(IWAeUPObject):
683    """A container for applicants.
684    """
[5432]685
686class IApplicantPrincipalInfo(IPrincipalInfo):
687    """Infos about principals that are applicants.
688    """
689    reg_no = Attribute("The JAMB registration no. of the user")
690
691    access_code = Attribute("The Access Code the user purchased")
692
693class IApplicantPrincipal(IPrincipal):
694    """A principal that is an applicant.
695
696    This interface extends zope.security.interfaces.IPrincipal and
697    requires also an `id` and other attributes defined there.
698    """
699    reg_no = schema.TextLine(
700        title = u'Registration number',
701        description = u'The JAMB registration number',
702        required = True,
703        readonly = True)
704
705    access_code = schema.TextLine(
706        title = u'Access Code',
707        description = u'The access code purchased by the user.',
708        required = True,
709        readonly = True)
[5436]710
[5437]711class IApplicantsFormChallenger(Interface):
[5436]712    """A challenger that uses a browser form to collect applicant
713       credentials.
714    """
715    loginpagename = schema.TextLine(
716        title = u'Loginpagename',
717        description = u"""Name of the login form used by challenger.
718
719        The form must provide an ``access_code`` input field.
[5439]720        """)
[5436]721
[5439]722    accesscode_field = schema.TextLine(
[5436]723        title = u'Access code field',
724        description = u'''Field of the login page which is looked up for
725                          access_code''',
726        default = u'access_code',
727        )
728
[5439]729class IJAMBApplicantsFormChallenger(IApplicantsFormChallenger):
[5436]730    """A challenger that uses a browser form to collect applicant
731       credentials for applicants in JAMB process.
732
733       JAMB-screened applicants have to provide an extra registration
734       no. provided by JAMB.
735    """
[5439]736    jamb_reg_no_field = schema.TextLine(
[5436]737        title = u'JAMB registration no.',
738        description = u'''Field of the login page which is looked up for
739                          the JAMB registration number.''',
740        default = u'jamb_reg_no',
741        )
[5438]742
743class IApplicantSessionCredentials(Interface):
744    """Interface for storing and accessing applicant credentials in a
745       session.
746    """
747
748    def __init__(access_code):
[5471]749        """Create applicant session credentials."""
[5438]750
751    def getAccessCode():
752        """Return the access code."""
753
754
755class IJAMBApplicantSessionCredentials(IApplicantSessionCredentials):
756    """Interface for storing and accessing JAMB applicant credentials in a
757       session.
758    """
759
760    def __init__(access_code, jamb_reg_no):
[5471]761        """Create credentials for JAMB screened applicants."""
[5438]762
763    def getJAMBRegNo():
764        """Return the JAMB registration no."""
Note: See TracBrowser for help on using the repository browser.