Changeset 1799
- Timestamp:
- 19 May 2007, 10:58:59 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1783 r1799 93 93 portal_type = meta_type 94 94 security = ClassSecurityInfo() 95 96 security.declareProtected(ModifyPortalContent,"loadPumeResultsFromCSV")###( 97 def loadPumeResultsFromCSV(self): 98 """load Fulltime Studentdata from CSV values into pumeresults catalog""" 99 import transaction 100 import random 101 ## csv_d = {'jamb_reg_no': "RegNumber", ###( 102 ## 'status': "Admission Status", 103 ## 'name': "Name", 104 ## 'score': "Score", 105 ## 'sex': "Sex", 106 ## 'faculty': "Faculty", 107 ## 'department': "Dept", 108 ## 'course': "Course", 109 ## 'course_code_org': "Course Code", 110 ## } 111 ###) 112 ## csv_d = {'jamb_reg_no': "JAMBRegno", 113 ## 'name': "Name", 114 ## 'score': "Score", 115 ## 'sex': "Sex", 116 ## 'course': "Course", 117 ## 'faculty': "Faculty", 118 ## 'department': "Dept", 119 ## 'course_code_org': "Course Code", 120 ## 'status': "Admission Status", 121 ## 'result_type': None, 122 ## } 123 124 csv_d = {'jamb_reg_no': "reg_no", 125 'name': "Firstame" + "Middlename" +"Lastname", 126 'score': "pume_score", 127 'sex': "sex", 128 'course': "study_course", 129 'status': "admission_status", 130 'result_type': "entry_mode", 131 } 132 133 csv_fields = [f[1] for f in csv_d.items() if f[1]] 134 tr_count = 0 135 total = 0 136 #name = 'pup_new' 137 name = 'pup_update' 138 update = name.endswith('update') 139 no_import = [] 140 ok_import = [] 141 ok_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_d.keys()])) 142 no_import.append('%s' % ','.join(['"%s"' % fn for fn in csv_fields])) 143 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 144 ok_import_name = "%s/import/%s_imported_%s.csv" % (i_home,name,current) 145 #open(ok_import_name,"w").write('\n'.join(no_import)) 146 no_import_name = "%s/import/%s_not_imported_%s.csv" % (i_home,name,current) 147 #open(no_import_name,"w").write('\n'.join(no_import)) 148 logger = logging.getLogger('Import.%s' % name) 149 starttime = DateTime.now() 150 logger.info('Start loading from %s.csv' % name) 151 try: 152 result = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 153 except: 154 logger.error('Error reading %s.csv' % name) 155 return 156 pume = self.portal_pumeresults 157 format = ','.join(['"%%(%s)s"' % fn for fn in csv_fields]) 158 import_format = ','.join(['"%%(%s)s"' % fn for fn in csv_d.keys()]) 159 eduplicate = '%s,"duplicate"' % format 160 einvalidjamb = '%s,"invalid JambRegNo"' % format 161 added = 'added ,%s' % format 162 #from pdb import set_trace;set_trace() 163 for jamb in result: 164 dict = {} 165 for f,fn in csv_d.items(): 166 dict[f] = jamb.get(csv_d[f]) 167 dict['result_type'] = 'DE' 168 jnr = jamb.get(csv_d['jamb_reg_no']) 169 if not checkJambNo(jnr): 170 logger.info(einvalidjamb % jamb) 171 dd = {} 172 for f,fn in csv_d.items(): 173 dd[fn] = getattr(data,f) 174 no_import.append(eduplicate % dd) 175 no_import.append(eduplicate % jamb) 176 continue 177 res = pume(jamb_reg_no=jnr) 178 if len(res) > 0: 179 if update: 180 try: 181 pume.modifyRecord(**dict) 182 except ValueError: 183 logger.info(eduplicate % jamb) 184 continue 185 except KeyError: 186 pume.addRecord(**dict) 187 logger.info(added % jamb) 188 continue 189 else: 190 data = res[0] 191 if data.name != jamb.get(csv_d['name']): 192 #set_trace() 193 logger.info(eduplicate % jamb) 194 #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict 195 #logger.info(em) 196 dd = {} 197 for f,fn in csv_d.items(): 198 dd[fn] = getattr(data,f) 199 no_import.append(eduplicate % dd) 200 no_import.append(eduplicate % jamb) 201 continue 202 try: 203 pume.addRecord(**dict) 204 ok_import.append(import_format % dict) 205 except ValueError: 206 logger.info(eduplicate % jamb) 207 #em = 'Student with REG-NO %(jamb_reg_no)s already exists\n' % dict 208 #logger.info(em) 209 no_import.append(eduplicate % jamb) 210 logger.info('End loading from %s.csv' % name) 211 if len(no_import) > 1: 212 open(no_import_name,"w+").write('\n'.join(no_import)) 213 open(ok_import_name,"w+").write('\n'.join(ok_import)) 214 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 215 ###) 216 95 217 96 218 security.declareProtected(ModifyPortalContent,"createStudents")###(
Note: See TracChangeset for help on using the changeset viewer.