Changeset 9009


Ignore:
Timestamp:
17 Jul 2012, 05:30:42 (12 years ago)
Author:
Henrik Bettermann
Message:

Add option for a conditional converter.

Remove whitespaces.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.kofa/trunk/tools/fix_import_file.py

    r9007 r9009  
    111111COLNAME_MAPPING = {
    112112    # base data
     113    'id': 'student_id',
    113114    'reg_state': 'state',
    114115    'reg_transition': 'state',
     
    184185    """
    185186    header = dict([(name, name) for name in fieldnames])
     187    # Remove whitespaces
     188    for key in header:
     189        header[key] = key.strip()
    186190    for in_name, out_name in COLNAME_MAPPING.items():
    187191        if in_name not in header:
     
    195199
    196200    @classmethod
    197     def student_id(self, value):
     201    def student_id(self, value, row):
    198202        """ 'A123456' --> 'EA123456'
    199203        """
     
    203207
    204208    @classmethod
    205     def reg_state(self, value):
     209    def reg_state(self, value, row):
    206210        """ 'courses_validated' --> 'courses validated'
    207211        """
     
    209213
    210214    @classmethod
    211     def reg_transition(self, value):
     215    def reg_transition(self, value, row):
    212216        if value == "admitted":
    213217            return "admit"
     
    217221
    218222    @classmethod
    219     def level(self, value):
     223    def level(self, value, row):
    220224        """ '000' --> '10'
     225        '800' --> '999' if pg student
    221226        """
    222227        try:
     
    226231        if number == 0:
    227232            return 10
     233        if row.get('entry_mode').startswith('pg'):
     234            return 999
    228235        return number
    229236
    230237    @classmethod
    231     def semester(self, value):
     238    def semester(self, value, row):
    232239        """ '0' --> '9'
    233240        """
     
    241248
    242249    @classmethod
    243     def application_category(self, value):
     250    def application_category(self, value, row):
    244251        """ '' --> 'no'
    245252        """
     
    249256
    250257    @classmethod
    251     def lga(self, value):
     258    def lga(self, value, row):
    252259        """ Remove apostrophe
    253260        """
     
    285292
    286293    @classmethod
    287     def session(self, value):
     294    def session(self, value, row):
    288295        """ '08' --> '2008'
    289296        '2008/2009' --> '2008'
     
    309316
    310317    @classmethod
    311     def former(self, value):
     318    def former(self, value, row):
    312319        """ True --> yes
    313320        '2008/2009' --> '2008'
     
    318325
    319326    @classmethod
    320     def year(self, value):
     327    def year(self, value, row):
    321328        """ '0' --> ''
    322329        """
     
    329336
    330337    @classmethod
    331     def marit_stat(self, value):
     338    def marit_stat(self, value, row):
    332339        """ 'True'/'False' --> 'married'/'unmarried'
    333340        """
     
    341348
    342349    @classmethod
    343     def gender(self, value):
     350    def gender(self, value, row):
    344351        """ 'True'/'False' --> 'f'/'m'
    345352        """
     
    353360
    354361    @classmethod
    355     def date(self, value):
     362    def date(self, value, row):
    356363        """ 'yyyy/mm/dd' --> 'yyyy-mm-dd'
    357364        """
     
    368375
    369376    @classmethod
    370     def no_int(self, value):
     377    def no_int(self, value, row):
    371378        """ Add hash and skip numbers starting with 999999
    372379        """
     
    383390
    384391    @classmethod
    385     def mode(self, value):
     392    def mode(self, value, row):
    386393        if value == "transfer_fulltime":
    387394            return "transfer_ft"
     
    391398
    392399    @classmethod
    393     def password(self, value):
     400    def password(self, value, row):
    394401        if value == "not set":
    395402            return ""
     
    397404
    398405    @classmethod
    399     def nationality(self, value):
     406    def nationality(self, value, row):
    400407        if value == "nigeria":
    401408            return "NG"
     
    405412
    406413    @classmethod
    407     def sittype(self, value):
     414    def sittype(self, value, row):
    408415        if value == "nabtec":
    409416            return "nabteb"
     
    411418
    412419    @classmethod
    413     def company(self, value):
     420    def company(self, value, row):
    414421        if value == "online":
    415422            return "interswitch"
     
    417424
    418425    @classmethod
    419     def p_category(self, value):
     426    def p_category(self, value, row):
    420427        if value == "acceptance":
    421428            return "clearance"
     
    423430
    424431    @classmethod
    425     def email(self, value):
     432    def email(self, value, row):
    426433        return value.strip()
    427434
    428435    @classmethod
    429     def phone(self, value):
     436    def phone(self, value, row):
    430437        """ '<num-seq1>-<num-seq2> asd' -> '--<num-seq1><num-seq2>'
    431438
     
    447454
    448455    @classmethod
    449     def result(self, value):
     456    def result(self, value, row):
    450457        try:
    451458            liste = eval(value)
     
    472479            writer.writerow(header)
    473480        if row.get('reg_state') == 'student_created':
     481            # We do not reimport student records which have never been accessed.
    474482            continue
    475483        if row.get('status') == 'started':
    476             # We do not use started payments
     484            # We do not reimport started payments.
    477485            continue
    478486        for key, value in row.items():
     487            # Remove unwanted whitespaces.
     488            row[key] = row[key].strip()
    479489            if not key in OPTIONS.keys():
    480490                continue
     
    484494                print "WARNING: cannot find converter %s" % conv_name
    485495                continue
    486             row[key] = converter(row[key])
     496            row[key] = converter(row[key], row)
    487497        try:
    488498            writer.writerow(row)
Note: See TracChangeset for help on using the changeset viewer.