source: main/kofacustom.lpng/trunk/src/kofacustom/lpng/applicants/interfaces.py @ 17959

Last change on this file since 17959 was 17201, checked in by Henrik Bettermann, 2 years ago

Finetune exporter pages.

  • Property svn:keywords set to Id
File size: 10.1 KB
RevLine 
[17091]1## $Id: interfaces.py 17201 2022-12-01 15:57:05Z 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 zope import schema import unicodecsv import os from zope.interface import Interface, Attribute, implements, directlyProvides 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) from waeup.kofa.schema import FormattedDate, TextLineChoice, PhoneNumber from waeup.kofa.sourcefactory import SmartBasicContextualSourceFactory from waeup.kofa.students.vocabularies import (   nats_vocab, GenderSource,RegNumberSource) from waeup.kofa.applicants.interfaces import contextual_reg_num_source from kofacustom.lpng.interfaces import MessageFactory as _ from kofacustom.lpng.payments.interfaces import ICustomOnlinePayment from kofacustom.nigeria.interfaces import LGASource from kofacustom.nigeria.applicants.interfaces import (     INigeriaApplicantOnlinePayment,) def make_dict(filename, depth):     rows = unicodecsv.reader(         open(os.path.dirname(__file__)  + '/%s'%filename, 'rb'))     result = dict()     try:         i = 1         for row in rows:             result['_'.join(row[0:depth])] = row[depth]             i += 1     except:         print 'WARNING: check %s line %d' % (filename, i)         import pdb; pdb.set_trace()     return result STATES = make_dict('states.csv', 1) LGAS = make_dict('lgas.csv', 2) WARDS = make_dict('wards.csv', 3) PUNITS = make_dict('punits.csv', 4) class SpecialContextualDictSourceFactoryBase(SmartBasicContextualSourceFactory):     """     """     def getValues(self, context):         sorted_items = sorted(self.DICT_NAME.items(),                               key=lambda item: item[1])         return [item[0] for item in sorted_items]     def getToken(self, context, value):         return str(value)     def getTitle(self, context, value):         return self.DICT_NAME[value] class StateSource(SpecialContextualDictSourceFactoryBase):     """A source for Nigerian states, lgas, wards and polling units     """     DICT_NAME = STATES    class LgaSource(SpecialContextualDictSourceFactoryBase):     """A source for Nigerian states, lgas, wards and polling units     """     DICT_NAME = LGAS     def getValues(self, context):         items = []         if not context.federalstate:             return items         for item in self.DICT_NAME.items():             if item[0].split('_')[0] == context.federalstate:                 items.append(item)         sorted_items = sorted(items, key=lambda item: item[1])         return [item[0] for item in sorted_items] class WardSource(SpecialContextualDictSourceFactoryBase):     """A source for Nigerian states, lgas, wards and polling units     """     DICT_NAME = WARDS     def getValues(self, context):         items = []         if not context.lga:             return items         for item in self.DICT_NAME.items():             if item[0].split('_')[:2] == context.lga.split('_')[:2]:                 items.append(item)         sorted_items = sorted(items, key=lambda item: item[1])         return [item[0] for item in sorted_items] class PunitSource(SpecialContextualDictSourceFactoryBase):     """A source for Nigerian states, lgas, wards and polling units     """     DICT_NAME = PUNITS        def getValues(self, context):         items = []         if not context.ward:             return items         for item in self.DICT_NAME.items():             if item[0].split('_')[:3] == context.ward.split('_')[:3]:                 items.append(item)         sorted_items = sorted(items, key=lambda item: item[1])         return [item[0] for item in sorted_items] class IPollingUnit(IKofaObject):     """     """     federalstate = schema.Choice(         source = StateSource(),         title = _(u'State'),         required = False,         )     lga = schema.Choice(         source = LgaSource(),         title = _(u'LGA'),         required = False,         )     ward = schema.Choice(         source = WardSource(),         title = _(u'Ward'),         required = False,         )     punit = schema.Choice(         source = PunitSource(),         title = _(u'Polling Unit'),         required = False,         ) class IApplicantBaseData(IKofaObject):     """This is a base interface of an applicant with no field     required. For use with processors, forms, etc., please use one of     the derived interfaces below, which set more fields to required     state, depending on use-case.     """     state = Attribute('Application state of an applicant')     history = Attribute('Object history, a list of messages')     display_fullname = Attribute('The fullname of an applicant')     application_number = Attribute('The key under which the record is stored')     container_code = Attribute('Code of the parent container plus additional information if record is used or not')     translated_state = Attribute('Real name of the application state')     special = Attribute('True if special application')     payments = Attribute('List of payment objects stored in the applicant container')     application_date = Attribute('UTC datetime of submission, used for export only')     password = Attribute('Encrypted password of an applicant')     suspended = schema.Bool(         title = _(u'Account suspended'),         default = False,         required = False,         )     applicant_id = schema.TextLine(         title = _(u'Registrant Id'),         required = False,         readonly = False,         )             reg_number = TextLineChoice(         title = _(u'Registration Number'),         readonly = False,         required = False,         source = contextual_reg_num_source,         )     vin = schema.TextLine(         title = _(u'Voter Identification No (VIN)'),         required = False,         )     firstname = schema.TextLine(         title = _(u'First Name'),         required = True,         )     middlename = schema.TextLine(         title = _(u'Middle Name'),         required = False,         )     lastname = schema.TextLine(         title = _(u'Last Name (Surname)'),         required = True,         )     date_of_birth = FormattedDate(         title = _(u'Date of Birth'),         required = False,         show_year = True,         )     sex = schema.Choice(         title = _(u'Gender'),         source = GenderSource(),         required = False,         )             occupation = schema.ASCIILine(         title = _(u'Occupation'),         required = False,         )             state_of_residence = schema.Choice(         source = StateSource(),         title = _(u'State of Residence'),         required = False,         )     perm_address = schema.Text(         title = _(u'Residential Address'),         required = False,         )                     phone = PhoneNumber(         title = _(u'Phone'),         description = u'',         required = False,         )     email = schema.ASCIILine(         title = _(u'Email Address'),         required = False,         constraint=validate_email,         )     #notice = schema.Text(     #    title = _(u'Notice'),     #    required = False,     #    )     student_id = schema.TextLine(         title = _(u'Student Id'),         required = False,         readonly = False,         )     locked = schema.Bool(         title = _(u'Form locked'),         default = False,         required = False,         ) class ICustomApplicant(IPollingUnit, IApplicantBaseData):     """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 ICustomApplicantEdit(ICustomApplicant):     """This is an 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.     """     reg_number = TextLineChoice(         title = _(u'Registration Number'),         readonly = True,         required = False,         source = contextual_reg_num_source,         )     email = schema.ASCIILine(         title = _(u'Email Address'),         required = True,         constraint=validate_email,         ) ICustomApplicantEdit['reg_number'].order = ICustomApplicant['reg_number'].order ICustomApplicantEdit['email'].order = ICustomApplicant['email'].order class ICustomApplicantOnlinePayment(INigeriaApplicantOnlinePayment):     """An applicant payment via payment gateways.     """ class ICustomApplicantUpdateByRegNo(ICustomApplicant):     """Representation of an applicant.     Skip regular reg_number validation if reg_number is used for finding     the applicant object.     """     reg_number = schema.TextLine(         title = u'Registration Number',         required = False,         )
Note: See TracBrowser for help on using the repository browser.