source: main/waeup.sirp/branches/ulif-paster/src/waeup/sirp/jambtables/interfaces.py @ 11110

Last change on this file since 11110 was 5486, checked in by uli, 14 years ago

Move passport field of pde edit page to bottom of field set.

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