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

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

Commit local changes (work inprogress)

File size: 20.7 KB
Line 
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"""
24import os
25import waeup.sirp.browser
26from hurry.file import HurryFile
27from zc.sourcefactory.basic import BasicSourceFactory
28from zope import schema
29from zope.app.file.interfaces import IImage
30from zope.interface import Interface, Attribute
31from zope.pluggableauth.interfaces import IPrincipalInfo
32from zope.security.interfaces import IGroupClosureAwarePrincipal as IPrincipal
33from waeup.sirp.interfaces import IWAeUPObject
34from waeup.sirp.image.schema import ImageFile
35
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    )
48
49class GenderSource(BasicSourceFactory):
50    """A gender source delivers basically a mapping
51       ``{'m': 'male', 'f': 'female'}``
52
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
69class IJAMBDataTable(IWAeUPObject):
70    """A table containing JAMB data.
71    """
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
100    def importFromCSV(filepath, username=None):
101        """Import data from filepath.
102
103        `filepath` - the path to the CSV file to import data from.
104
105        `username` - the (optional) username of the importing person.
106        """
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        )
119
120class IApplicantBaseData(IWAeUPObject):
121    """The data for an applicant.
122
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.
127    """
128    reg_no = schema.TextLine(
129        title = u'JAMB Registration Number',
130        )
131    access_code = schema.TextLine(
132        title = u'Access Code',
133        required = False,
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',
141        required = False,
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',
153        required = False,
154        )
155    middlenames = schema.TextLine(
156        title = u'Middle Names',
157        required = False,
158        )
159    lastname = schema.TextLine(
160        title = u'Surname/Full Name',
161        required = False,
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',
169        required = False,
170        )
171    jamb_state = schema.TextLine(
172        title = u'State (provided by JAMB)',
173        required = False,
174        )
175    jamb_lga = schema.TextLine(
176        title = u'LGA (provided by JAMB)',
177        required = False,
178        )
179    lga = schema.TextLine(
180        # XXX: should be choice
181        title = u'State/LGA (confirmed by applicant)',
182        required = False,
183        )
184    sex = schema.Choice(
185        title = u'Sex',
186        source = GenderSource(),
187        default = u'm',
188        required = False,
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        )
198    #passport = schema.Bool(
199    #    title = u'Passport Photograph',
200    #    default = True,
201    #    required = False,
202    #    )
203    passport = ImageFile(
204        title = u'Passport Photograph',
205        default = DEFAULT_PASSPORT_IMAGE_MALE,
206        required = True,
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',
260        required = False,
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        )
275    fst_sit_results = schema.List(
276        title = u'Results',
277        required = False,
278        value_type = schema.Object(
279            title = u'Entries',
280            schema = IResultEntry,
281            required = False,
282            )
283        )
284    scd_sit_fname = schema.TextLine(
285        title = u'Full Name',
286        required = False,
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',
332        required = False,
333        )
334    status = schema.TextLine(
335        # XXX: should be 'status' type
336        title = u'Application Status',
337        required = False,
338        )
339    screening_date = schema.Date(
340        title = u'Screening Date',
341        required = False,
342        )
343    screening_type = schema.TextLine(
344        # XXX: schould be choice
345        title = u'Screening Type',
346        required = False,
347        )
348    screening_score = schema.TextLine(
349        title = u'Screening Score',
350        required = False,
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(
376        # XXX: should be choice, should have sensible default: upcoming session
377        title = u'Entry Session',
378        required = False,
379        )
380    notice = schema.Text(
381        title = u'Notice',
382        required = False,
383        )
384    student_id = schema.TextLine(
385        title = u'Student ID',
386        required = False,
387        )
388    import_record_no = schema.TextLine(
389        title = u'Import Record No.',
390        required = False,
391        )
392    imported_by = schema.TextLine(
393        title = u'Imported By',
394        required = False,
395        )
396    import_date = schema.Datetime(
397        title = u'Import Date',
398        required = False,
399        )
400    import_from = schema.TextLine(
401        title = u'Import Source',
402        required = False,
403        )
404
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        )
446    #passport = schema.Bool(
447    #    title = u'Passport Photograph',
448    #    default = True,
449    #    )
450    passport = ImageFile(
451        title = u'Passport Photograph',
452        default = DEFAULT_PASSPORT_IMAGE_MALE,
453        required = True,
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
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        )
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(
621        title = u'Passport Photograph',
622        default = DEFAULT_PASSPORT_IMAGE_MALE,
623        required = True,
624        )
625
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   
682class IApplicantContainer(IWAeUPObject):
683    """A container for applicants.
684    """
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)
710
711class IApplicantsFormChallenger(Interface):
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.
720        """)
721
722    accesscode_field = schema.TextLine(
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
729class IJAMBApplicantsFormChallenger(IApplicantsFormChallenger):
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    """
736    jamb_reg_no_field = schema.TextLine(
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        )
742
743class IApplicantSessionCredentials(Interface):
744    """Interface for storing and accessing applicant credentials in a
745       session.
746    """
747
748    def __init__(access_code):
749        """Create applicant session credentials."""
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):
761        """Create credentials for JAMB screened applicants."""
762
763    def getJAMBRegNo():
764        """Return the JAMB registration no."""
Note: See TracBrowser for help on using the repository browser.