# -*- coding: utf-8 -*- ## $Id: interfaces.py 17305 2023-01-19 06:51:35Z henrik $ ## ## Copyright (C) 2011 Uli Fouquet & Henrik Bettermann ## This program is free software; you can redistribute it and/or modify ## it under the terms of the GNU General Public License as published by ## the Free Software Foundation; either version 2 of the License, or ## (at your option) any later version. ## ## This program is distributed in the hope that it will be useful, ## but WITHOUT ANY WARRANTY; without even the implied warranty of ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ## GNU General Public License for more details. ## ## You should have received a copy of the GNU General Public License ## along with this program; if not, write to the Free Software ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ## """Customized interfaces of the university application package. """ from datetime import datetime from zope import schema from zope.interface import invariant, Invalid from zope.component import getUtility from zope.catalog.interfaces import ICatalog from zc.sourcefactory.basic import BasicSourceFactory from waeup.kofa.university.vocabularies import StudyModeSource from waeup.kofa.applicants.interfaces import ( IApplicantBaseData, AppCatCertificateSource, CertificateSource) from waeup.kofa.schoolgrades import ResultEntryField from waeup.kofa.interfaces import ( SimpleKofaVocabulary, academic_sessions_vocab, validate_email, IKofaObject, MonthSource) from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber from waeup.kofa.students.vocabularies import nats_vocab, GenderSource from waeup.kofa.applicants.interfaces import ( contextual_reg_num_source, year_range, IApplicantBaseData) from kofacustom.nigeria.applicants.interfaces import ( LGASource, high_qual, high_grade, exam_types, jambsubjects, INigeriaUGApplicant, INigeriaPGApplicant, INigeriaApplicantOnlinePayment, INigeriaUGApplicantEdit, INigeriaPGApplicantEdit, INigeriaApplicantUpdateByRegNo, IPUTMEApplicantEdit, ) from kofacustom.nigeria.interfaces import ( LGASource, DisabilitiesSource, high_qual, high_grade, exam_types, validate_jamb_reg_number) from kofacustom.edocons.interfaces import MessageFactory as _ from kofacustom.edocons.payments.interfaces import ICustomOnlinePayment def entry_year_range(): curr_year = datetime.now().year return range(curr_year - 50, curr_year) programme_types_vocab = SimpleKofaVocabulary( (_('Post UTME'), 'putme'), (_('Post DE'), 'pude'), (_('Admission Screening Exercise'), 'ase'), (_('not applicable'), 'na'), ) DESTINATION_COST = { #'none': ('To the moon', 1000000000.0, 1), 'australia': ('Australia', 44500.0, 1), 'india': ('Arab Emirate/China/India/Saudi Arabia', 38500.0, 2), 'ghana': ('Benin/Ghana/South Africa', 37000.0, 3), 'isreal': ('Isreal/Turkey', 33500.0, 4), 'canada': ('Canada', 30500.0, 5), 'germany': ('Finland/France/Germany/Netherlands', 30000.0, 6), 'usa': ('USA', 29500.0, 7), 'uk': ('UK', 23500.0, 8), 'north': ('Nigeria North', 11800.0, 9), 'abuja': ('Abuja/Lokoja', 11200.0, 10), 'south': ('Nigeria South East/South/South West', 10700.0, 11), } class DestinationCostSource(BasicSourceFactory): """A source that delivers continents and shipment costs. """ def getValues(self): sorted_items = sorted(DESTINATION_COST.items(), key=lambda element: element[1][2]) return [item[0] for item in sorted_items] def getToken(self, value): return value def getTitle(self, value): return u"%s (₦ %s)" % ( DESTINATION_COST[value][0], DESTINATION_COST[value][1]) class OrderSource(BasicSourceFactory): """ """ def getValues(self): return ['c',] def getToken(self, value): return value def getTitle(self, value): #if value == 'o': # return _('Student Transcript') if value == 'c': return _('Certified Transcript') class TranscriptCertificateSource(CertificateSource): """Include Department and Faculty in Title. """ def getValues(self, context): catalog = getUtility(ICatalog, name='certificates_catalog') resultset = catalog.searchResults(code=(None, None)) resultlist = sorted(resultset, key=lambda value: value.__parent__.__parent__.__parent__.code + value.__parent__.__parent__.code + value.code) return resultlist def getTitle(self, context, value): """ """ try: title = "%s / %s / %s (%s)" % ( value.__parent__.__parent__.__parent__.title, value.__parent__.__parent__.title, value.title, value.code) except AttributeError: title = "NA / %s (%s)" % (value.title, value.code) return title class ICustomUGApplicant(INigeriaUGApplicant): """An undergraduate applicant. """ disabilities = schema.Choice( title = _(u'Disability'), source = DisabilitiesSource(), required = False, ) nationality = schema.Choice( source = nats_vocab, title = _(u'Nationality'), required = False, ) lga = schema.Choice( source = LGASource(), title = _(u'State/LGA (Nigerians only)'), required = True, ) perm_address = schema.Text( title = _(u'Permanent Address'), required = False, ) next_kin_name = schema.TextLine( title = _(u'Next of Kin Name'), required = False, readonly = False, ) next_kin_relation = schema.TextLine( title = _(u'Next of Kin Relationship'), required = False, readonly = False, ) next_kin_address = schema.Text( title = _(u'Next of Kin Address'), required = False, readonly = False, ) next_kin_phone = PhoneNumber( title = _(u'Next of Kin Phone'), required = False, readonly = False, ) course1 = schema.Choice( title = _(u'1st Choice Course of Study'), source = AppCatCertificateSource(), required = True, ) course2 = schema.Choice( title = _(u'2nd Choice Course of Study'), source = AppCatCertificateSource(), required = False, ) fst_sit_fname = schema.TextLine( title = _(u'Full Name'), required = False, readonly = False, ) fst_sit_no = schema.TextLine( title = _(u'Exam Number'), required = False, readonly = False, ) fst_sit_date = FormattedDate( title = _(u'Exam Date'), required = False, readonly = False, show_year = True, ) fst_sit_type = schema.Choice( title = _(u'Exam Type'), required = False, readonly = False, vocabulary = exam_types, ) fst_sit_results = schema.List( title = _(u'Exam Results'), value_type = ResultEntryField(), required = False, readonly = False, defaultFactory=list, ) scd_sit_fname = schema.TextLine( title = _(u'Full Name'), required = False, readonly = False, ) scd_sit_no = schema.TextLine( title = _(u'Exam Number'), required = False, readonly = False, ) scd_sit_date = FormattedDate( title = _(u'Exam Date'), required = False, readonly = False, show_year = True, ) scd_sit_type = schema.Choice( title = _(u'Exam Type'), required = False, readonly = False, vocabulary = exam_types, ) scd_sit_results = schema.List( title = _(u'Exam Results'), value_type = ResultEntryField(), required = False, readonly = False, defaultFactory=list, ) programme_type = schema.Choice( title = _(u'Programme Type'), vocabulary = programme_types_vocab, required = False, ) hq_type = schema.Choice( title = _(u'Qualification Obtained'), required = False, readonly = False, vocabulary = high_qual, ) hq_matric_no = schema.TextLine( title = _(u'Former Matric Number'), required = False, readonly = False, ) hq_degree = schema.Choice( title = _(u'Class of Degree'), required = False, readonly = False, vocabulary = high_grade, ) hq_school = schema.TextLine( title = _(u'Institution Attended'), required = False, readonly = False, ) hq_session = schema.TextLine( title = _(u'Years Attended'), required = False, readonly = False, ) hq_disc = schema.TextLine( title = _(u'Discipline'), required = False, readonly = False, ) jamb_subjects = schema.Text( title = _(u'Subjects and Scores'), required = False, ) jamb_subjects_list = schema.List( title = _(u'JAMB Subjects'), required = False, defaultFactory=list, value_type = schema.Choice( vocabulary = jambsubjects #source = JAMBSubjectSource(), ), ) jamb_score = schema.Int( title = _(u'Total JAMB Score'), required = False, ) #jamb_age = schema.Int( # title = _(u'Age (provided by JAMB)'), # required = False, # ) jamb_reg_number = schema.TextLine( title = _(u'JAMB Registration Number'), required = False, constraint=validate_jamb_reg_number, ) cbt_score = schema.Int( title = _(u'CBT Score'), required = False, ) cbt_venue = schema.TextLine( title = _(u'CBT Venue'), required = False, ) cbt_date = FormattedDate( title = _(u'CBT Date'), required = False, ) notice = schema.Text( title = _(u'Notice'), required = False, ) screening_venue = schema.TextLine( title = _(u'Screening Venue'), required = False, ) screening_date = schema.TextLine( title = _(u'Screening Date'), required = False, ) screening_score = schema.Int( title = _(u'Screening Score (%)'), required = False, ) aggregate = schema.Int( title = _(u'Aggregate Score (%)'), description = _(u'(average of relative JAMB and PUTME scores)'), required = False, ) result_uploaded = schema.Bool( title = _(u'Result uploaded'), default = False, required = False, ) student_id = schema.TextLine( title = _(u'Student Id'), required = False, readonly = False, ) course_admitted = schema.Choice( title = _(u'Admitted Course of Study'), source = CertificateSource(), required = False, ) locked = schema.Bool( title = _(u'Form locked'), default = False, required = False, ) class ICustomPGApplicant(INigeriaPGApplicant): """A postgraduate applicant. This interface defines the least common multiple of all fields in pg application forms. In customized forms, fields can be excluded by adding them to the PG_OMIT* tuples. """ class ITranscriptApplicant(IKofaObject): """A transcript applicant. """ suspended = schema.Bool( title = _(u'Account suspended'), default = False, required = False, ) locked = schema.Bool( title = _(u'Form locked'), default = False, required = False, ) applicant_id = schema.TextLine( title = _(u'Transcript Application Id'), required = False, readonly = False, ) student_id = schema.TextLine( title = _(u'Kofa Student Id'), required = False, readonly = False, ) matric_number = schema.TextLine( title = _(u'Matriculation Number'), readonly = False, required = False, ) firstname = schema.TextLine( title = _(u'First Name in School'), required = True, ) middlename = schema.TextLine( title = _(u'Middle Name in School'), required = False, ) lastname = schema.TextLine( title = _(u'Surname in School'), required = True, ) date_of_birth = FormattedDate( title = _(u'Date of Birth'), required = False, #date_format = u'%d/%m/%Y', # Use grok-instance-wide default show_year = True, ) sex = schema.Choice( title = _(u'Gender'), source = GenderSource(), required = True, ) #nationality = schema.Choice( # vocabulary = nats_vocab, # title = _(u'Nationality'), # required = False, # ) email = schema.ASCIILine( title = _(u'Email Address'), required = True, constraint=validate_email, ) phone = PhoneNumber( title = _(u'Phone'), description = u'', required = False, ) #perm_address = schema.Text( # title = _(u'Current Local Address'), # required = False, # readonly = False, # ) collected = schema.Bool( title = _(u'Have you collected transcript before?'), default = False, required = False, ) entry_year = schema.Choice( title = _(u'Year of Entrance'), required = False, values = entry_year_range(), readonly = False, ) entry_month = schema.Choice( title = _(u'Month of Entry'), source = MonthSource(), required = False, ) end_year = schema.Choice( title = _(u'Year of Graduation'), required = False, values = entry_year_range(), readonly = False, ) end_month = schema.Choice( title = _(u'Month of Graduation'), source = MonthSource(), required = False, ) entry_mode = schema.Choice( title = _(u'Course of Study'), source = StudyModeSource(), required = False, readonly = False, ) #course_studied = schema.Choice( # title = _(u'Course of Study'), # source = TranscriptCertificateSource(), # description = u'Faculty / Department / Course', # required = True, # readonly = False, # ) #course_changed = schema.Choice( # title = _(u'Change of Study Course / Transfer'), # description = u'If yes, select previous course of study.', # source = TranscriptCertificateSource(), # readonly = False, # required = False, # ) spillover_level = schema.Choice( title = _(u'Spill-over'), description = u'Any spill-over? If yes, select session of spill-over.', source = academic_sessions_vocab, required = False, readonly = False, ) purpose = schema.TextLine( title = _(u'Transcript Purpose'), required = False, ) #order = schema.Choice( # source = OrderSource(), # title = _(u'Type of Order'), # required = True, # ) org_name = schema.TextLine( title = _(u'Name of Organization'), required = False, ) dispatch_address = schema.Text( title = _(u'Recipient Address'), description = u'Addresses (including email address and phone number) ' 'to which transcripts should be posted. ' 'All addresses must involve same courier charges.', required = True, readonly = False, ) charge = schema.Choice( title = _(u'Transcript Charge'), source = DestinationCostSource(), required = True, readonly = False, ) curriculum = schema.Bool( title = _(u'Including curriculum'), description = u'₦ 5000 will be added to transcript charge.', default = False, required = False, ) no_copies = schema.Choice( title = _(u'Number of Copies'), description = u'Must correspond with the number of dispatch addresses above.', values=[1, 2, 3, 4], required = False, readonly = False, default = 1, ) courier_tno = schema.TextLine( title = _(u'Courier Tracking Number'), required = False, ) #proc_date = FormattedDate( # title = _(u'Processing Date'), # required = False, # #date_format = u'%d/%m/%Y', # Use grok-instance-wide default # show_year = True, # ) #@invariant #def type_of_order(applicant): # if not applicant.collected and applicant.order != 'o': # raise Invalid(_("If you haven't collected transcript before, type of order must be 'Student Transcript'.")) # if applicant.order == 'o' and applicant.charge.startswith('cert_'): # raise Invalid(_("You've selected the wrong transcript charge.")) # if applicant.order == 'c' and not applicant.charge.startswith('cert_'): # raise Invalid(_("You've selected the wrong transcript charge.")) class ICustomApplicant(ICustomUGApplicant, ICustomPGApplicant, ITranscriptApplicant): """An interface for both types of applicants. Attention: The ICustomPGApplicant field seetings will be overwritten by ICustomPGApplicant field settings. If a field is defined in both interfaces zope.schema validates only against the constraints in ICustomUGApplicant. This does not affect the forms since they are build on either ICustomUGApplicant or ICustomPGApplicant. """ def writeLogMessage(view, comment): """Adds an INFO message to the log file """ def createStudent(): """Create a student object from applicant data and copy applicant object. """ class ICustomUGApplicantEdit(ICustomUGApplicant): """An undergraduate applicant interface for edit forms. Here we can repeat the fields from base data and set the `required` and `readonly` attributes to True to further restrict the data access. Or we can allow only certain certificates to be selected by choosing the appropriate source. We cannot omit fields here. This has to be done in the respective form page. """ email = schema.ASCIILine( title = _(u'Email Address'), required = True, constraint=validate_email, ) phone = PhoneNumber( title = _(u'Phone'), description = u'', required = True, ) perm_address = schema.Text( title = _(u'Permanent Address'), required = True, ) next_kin_name = schema.TextLine( title = _(u'Next of Kin Name'), required = True, readonly = False, ) next_kin_relation = schema.TextLine( title = _(u'Next of Kin Relationship'), required = True, readonly = False, ) next_kin_address = schema.Text( title = _(u'Next of Kin Address'), required = True, readonly = False, ) next_kin_phone = PhoneNumber( title = _(u'Next of Kin Phone'), required = True, readonly = False, ) ICustomUGApplicantEdit[ 'email'].order = ICustomUGApplicant['email'].order ICustomUGApplicantEdit[ 'phone'].order = ICustomUGApplicant['phone'].order ICustomUGApplicantEdit[ 'perm_address'].order = ICustomUGApplicant['perm_address'].order ICustomUGApplicantEdit[ 'next_kin_name'].order = ICustomUGApplicant['next_kin_name'].order ICustomUGApplicantEdit[ 'next_kin_relation'].order = ICustomUGApplicant['next_kin_relation'].order ICustomUGApplicantEdit[ 'next_kin_address'].order = ICustomUGApplicant['next_kin_address'].order ICustomUGApplicantEdit[ 'next_kin_phone'].order = ICustomUGApplicant['next_kin_phone'].order class ICustomPGApplicantEdit(INigeriaPGApplicantEdit): """A postgraduate applicant interface for editing. Here we can repeat the fields from base data and set the `required` and `readonly` attributes to True to further restrict the data access. Or we can allow only certain certificates to be selected by choosing the appropriate source. We cannot omit fields here. This has to be done in the respective form page. """ class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment): """An applicant payment via payment gateways. """ class IPUTMEApplicantEdit(IPUTMEApplicantEdit): """An undergraduate applicant interface for editing. Here we can repeat the fields from base data and set the `required` and `readonly` attributes to True to further restrict the data access. Or we can allow only certain certificates to be selected by choosing the appropriate source. We cannot omit fields here. This has to be done in the respective form page. """ class ICustomApplicantUpdateByRegNo(INigeriaApplicantUpdateByRegNo): """Representation of an applicant. Skip regular reg_number validation if reg_number is used for finding the applicant object. """