source: main/waeup.sirp/trunk/src/waeup/sirp/jambtables/interfaces.py @ 5440

Last change on this file since 5440 was 5439, checked in by uli, 14 years ago

Fix typos and missing package names.

File size: 17.0 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
355        # XXX: should have sensible default: upcoming session
356        title = u'Entry Session',
357        required = False,
358        )
359    notice = schema.Text(
360        title = u'Notice',
361        required = False,
362        )
363    student_id = schema.TextLine(
364        title = u'Student ID',
365        required = False,
366        )
367    import_record_no = schema.TextLine(
368        title = u'Import Record No.',
369        required = False,
370        )
371    imported_by = schema.TextLine(
372        title = u'Imported By',
373        required = False,
374        )
375    import_date = schema.Datetime(
376        title = u'Import Date',
377        required = False,
378        )
379    import_from = schema.TextLine(
380        title = u'Import Source',
381        required = False,
382        )
383
384   
385class IApplicant(IApplicantBaseData):
386    """An applicant.
387
388    This is basically the applicant base data. Here we repeat the
389    fields from base data only with the `required` attribute of
390    required attributes set to True (which is the default).
391    """
392    access_code = schema.TextLine(
393        title = u'Access Code',
394        )
395    course1 = schema.TextLine(
396        title = u'1st Choice Course of Study',
397        )
398    firstname = schema.TextLine(
399        title = u'First Name',
400        )
401    middlenames = schema.TextLine(
402        title = u'Middle Names',
403        )
404    lastname = schema.TextLine(
405        title = u'Surname/Full Name',
406        )
407    date_of_birth = schema.Date(
408        title = u'Date of Birth',
409        )
410    jamb_state = schema.TextLine(
411        title = u'State (provided by JAMB)',
412        )
413    jamb_lga = schema.TextLine(
414        title = u'LGA (provided by JAMB)',
415        )
416    lga = schema.TextLine(
417        # XXX: should be choice
418        title = u'State/LGA (confirmed by applicant)',
419        )
420    sex = schema.Choice(
421        title = u'Sex',
422        source = GenderSource(),
423        default = u'm',
424        )
425    passport = schema.Bool(
426        title = u'Passport Photograph',
427        default = True,
428        )
429    #
430    # Higher Educational Data
431    #
432
433    #
434    # First sitting data
435    #
436    fst_sit_fname = schema.TextLine(
437        title = u'Full Name',
438        )
439
440    #
441    # Second sitting data
442    #
443    scd_sit_fname = schema.TextLine(
444        title = u'Full Name',
445        )
446    #
447    # JAMB scores
448    #
449   
450    #
451    # Application Data
452    #
453    application_date = schema.Date(
454        title = u'Application Date',
455        )
456    status = schema.TextLine(
457        # XXX: should be 'status' type
458        title = u'Application Status',
459        )
460    screening_date = schema.Date(
461        title = u'Screening Date',
462        )
463    screening_type = schema.TextLine(
464        # XXX: schould be choice
465        title = u'Screening Type',
466        )
467    screening_score = schema.TextLine(
468        title = u'Screening Score',
469        )
470    entry_session = schema.TextLine(
471        # XXX: should be choice
472        # XXX: should have sensible default: upcoming session
473        title = u'Entry Session',
474        )
475    import_record_no = schema.TextLine(
476        title = u'Import Record No.',
477        )
478    imported_by = schema.TextLine(
479        title = u'Imported By',
480        )
481    import_date = schema.Datetime(
482        title = u'Import Date',
483        )
484    import_from = schema.TextLine(
485        title = u'Import Source',
486        )
487
488class IApplicantPDEImportData(IApplicantBaseData):
489    """Data for applicants, that passed PDE screening.
490
491    This data set should be suitable for imports from JAMB tables. It
492    is also basicall the basic applicant data from
493    :class:`IApplicantBaseData` only with the required fields set.
494
495    """
496    firstname = schema.TextLine(
497        title = u'First Name',
498        required = True,
499        )
500    middlenames = schema.TextLine(
501        title = u'Middle Names',
502        required = True,
503        )
504    lastname = schema.TextLine(
505        title = u'Surname/Full Name',
506        required = True,
507        )
508    date_of_birth = schema.Date(
509        title = u'Date of Birth',
510        required = True,
511        )
512    jamb_state = schema.TextLine(
513        title = u'State (provided by JAMB)',
514        required = True,
515        )
516    jamb_lga = schema.TextLine(
517        title = u'LGA (provided by JAMB)',
518        required = True,
519        )
520    course1 = schema.TextLine(
521        title = u'1st Choice Course of Study',
522        required = True,
523        )
524    screening_date = schema.Date(
525        title = u'Screening Date',
526        required = True,
527        )
528    screening_type = schema.TextLine(
529        # XXX: schould be choice
530        title = u'Screening Type',
531        required = True,
532        )
533    screening_venue = schema.TextLine(
534        title = u'Screening Venue',
535        required = True,
536        )
537    entry_session = schema.TextLine(
538        # XXX: should be choice
539        # XXX: should have sensible default: upcoming session
540        title = u'Entry Session',
541        required = True,
542        )
543   
544class IApplicantContainer(IWAeUPObject):
545    """A container for applicants.
546    """
547
548class IApplicantPrincipalInfo(IPrincipalInfo):
549    """Infos about principals that are applicants.
550    """
551    reg_no = Attribute("The JAMB registration no. of the user")
552
553    access_code = Attribute("The Access Code the user purchased")
554
555class IApplicantPrincipal(IPrincipal):
556    """A principal that is an applicant.
557
558    This interface extends zope.security.interfaces.IPrincipal and
559    requires also an `id` and other attributes defined there.
560    """
561    reg_no = schema.TextLine(
562        title = u'Registration number',
563        description = u'The JAMB registration number',
564        required = True,
565        readonly = True)
566
567    access_code = schema.TextLine(
568        title = u'Access Code',
569        description = u'The access code purchased by the user.',
570        required = True,
571        readonly = True)
572
573class IApplicantsFormChallenger(Interface):
574    """A challenger that uses a browser form to collect applicant
575       credentials.
576    """
577    loginpagename = schema.TextLine(
578        title = u'Loginpagename',
579        description = u"""Name of the login form used by challenger.
580
581        The form must provide an ``access_code`` input field.
582        """)
583
584    accesscode_field = schema.TextLine(
585        title = u'Access code field',
586        description = u'''Field of the login page which is looked up for
587                          access_code''',
588        default = u'access_code',
589        )
590
591class IJAMBApplicantsFormChallenger(IApplicantsFormChallenger):
592    """A challenger that uses a browser form to collect applicant
593       credentials for applicants in JAMB process.
594
595       JAMB-screened applicants have to provide an extra registration
596       no. provided by JAMB.
597    """
598    jamb_reg_no_field = schema.TextLine(
599        title = u'JAMB registration no.',
600        description = u'''Field of the login page which is looked up for
601                          the JAMB registration number.''',
602        default = u'jamb_reg_no',
603        )
604
605class IApplicantSessionCredentials(Interface):
606    """Interface for storing and accessing applicant credentials in a
607       session.
608    """
609
610    def __init__(access_code):
611        pass
612
613    def getAccessCode():
614        """Return the access code."""
615
616
617class IJAMBApplicantSessionCredentials(IApplicantSessionCredentials):
618    """Interface for storing and accessing JAMB applicant credentials in a
619       session.
620    """
621
622    def __init__(access_code, jamb_reg_no):
623        pass
624
625    def getJAMBRegNo():
626        """Return the JAMB registration no."""
Note: See TracBrowser for help on using the repository browser.