Index: main/waeup.kofa/trunk/tools/fix_import_file.py
===================================================================
--- main/waeup.kofa/trunk/tools/fix_import_file.py	(revision 9007)
+++ main/waeup.kofa/trunk/tools/fix_import_file.py	(revision 9009)
@@ -111,4 +111,5 @@
 COLNAME_MAPPING = {
     # base data
+    'id': 'student_id',
     'reg_state': 'state',
     'reg_transition': 'state',
@@ -184,4 +185,7 @@
     """
     header = dict([(name, name) for name in fieldnames])
+    # Remove whitespaces
+    for key in header:
+        header[key] = key.strip()
     for in_name, out_name in COLNAME_MAPPING.items():
         if in_name not in header:
@@ -195,5 +199,5 @@
 
     @classmethod
-    def student_id(self, value):
+    def student_id(self, value, row):
         """ 'A123456' --> 'EA123456'
         """
@@ -203,5 +207,5 @@
 
     @classmethod
-    def reg_state(self, value):
+    def reg_state(self, value, row):
         """ 'courses_validated' --> 'courses validated'
         """
@@ -209,5 +213,5 @@
 
     @classmethod
-    def reg_transition(self, value):
+    def reg_transition(self, value, row):
         if value == "admitted":
             return "admit"
@@ -217,6 +221,7 @@
 
     @classmethod
-    def level(self, value):
+    def level(self, value, row):
         """ '000' --> '10'
+        '800' --> '999' if pg student
         """
         try:
@@ -226,8 +231,10 @@
         if number == 0:
             return 10
+        if row.get('entry_mode').startswith('pg'):
+            return 999
         return number
 
     @classmethod
-    def semester(self, value):
+    def semester(self, value, row):
         """ '0' --> '9'
         """
@@ -241,5 +248,5 @@
 
     @classmethod
-    def application_category(self, value):
+    def application_category(self, value, row):
         """ '' --> 'no'
         """
@@ -249,5 +256,5 @@
 
     @classmethod
-    def lga(self, value):
+    def lga(self, value, row):
         """ Remove apostrophe
         """
@@ -285,5 +292,5 @@
 
     @classmethod
-    def session(self, value):
+    def session(self, value, row):
         """ '08' --> '2008'
         '2008/2009' --> '2008'
@@ -309,5 +316,5 @@
 
     @classmethod
-    def former(self, value):
+    def former(self, value, row):
         """ True --> yes
         '2008/2009' --> '2008'
@@ -318,5 +325,5 @@
 
     @classmethod
-    def year(self, value):
+    def year(self, value, row):
         """ '0' --> ''
         """
@@ -329,5 +336,5 @@
 
     @classmethod
-    def marit_stat(self, value):
+    def marit_stat(self, value, row):
         """ 'True'/'False' --> 'married'/'unmarried'
         """
@@ -341,5 +348,5 @@
 
     @classmethod
-    def gender(self, value):
+    def gender(self, value, row):
         """ 'True'/'False' --> 'f'/'m'
         """
@@ -353,5 +360,5 @@
 
     @classmethod
-    def date(self, value):
+    def date(self, value, row):
         """ 'yyyy/mm/dd' --> 'yyyy-mm-dd'
         """
@@ -368,5 +375,5 @@
 
     @classmethod
-    def no_int(self, value):
+    def no_int(self, value, row):
         """ Add hash and skip numbers starting with 999999
         """
@@ -383,5 +390,5 @@
 
     @classmethod
-    def mode(self, value):
+    def mode(self, value, row):
         if value == "transfer_fulltime":
             return "transfer_ft"
@@ -391,5 +398,5 @@
 
     @classmethod
-    def password(self, value):
+    def password(self, value, row):
         if value == "not set":
             return ""
@@ -397,5 +404,5 @@
 
     @classmethod
-    def nationality(self, value):
+    def nationality(self, value, row):
         if value == "nigeria":
             return "NG"
@@ -405,5 +412,5 @@
 
     @classmethod
-    def sittype(self, value):
+    def sittype(self, value, row):
         if value == "nabtec":
             return "nabteb"
@@ -411,5 +418,5 @@
 
     @classmethod
-    def company(self, value):
+    def company(self, value, row):
         if value == "online":
             return "interswitch"
@@ -417,5 +424,5 @@
 
     @classmethod
-    def p_category(self, value):
+    def p_category(self, value, row):
         if value == "acceptance":
             return "clearance"
@@ -423,9 +430,9 @@
 
     @classmethod
-    def email(self, value):
+    def email(self, value, row):
         return value.strip()
 
     @classmethod
-    def phone(self, value):
+    def phone(self, value, row):
         """ '<num-seq1>-<num-seq2> asd' -> '--<num-seq1><num-seq2>'
 
@@ -447,5 +454,5 @@
 
     @classmethod
-    def result(self, value):
+    def result(self, value, row):
         try:
             liste = eval(value)
@@ -472,9 +479,12 @@
             writer.writerow(header)
         if row.get('reg_state') == 'student_created':
+            # We do not reimport student records which have never been accessed.
             continue
         if row.get('status') == 'started':
-            # We do not use started payments
+            # We do not reimport started payments.
             continue
         for key, value in row.items():
+            # Remove unwanted whitespaces.
+            row[key] = row[key].strip()
             if not key in OPTIONS.keys():
                 continue
@@ -484,5 +494,5 @@
                 print "WARNING: cannot find converter %s" % conv_name
                 continue
-            row[key] = converter(row[key])
+            row[key] = converter(row[key], row)
         try:
             writer.writerow(row)
