Changeset 1289
- Timestamp:
- 13 Jan 2007, 21:55:52 (18 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1264 r1289 869 869 table.addRecord(**student) 870 870 except ValueError: 871 import pdb;pdb.set_trace()871 #import pdb;pdb.set_trace() 872 872 student['Error'] = "Duplicate" 873 873 no_import.append( format_error % student) … … 896 896 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 897 897 ###) 898 899 900 901 902 security.declareProtected(ModifyPortalContent,"updateReturningStudents")###( 903 def updateReturningStudents(self): 904 """load and overwrite Returning Student Data from CSV values""" 905 import transaction 906 import random 907 #from pdb import set_trace 908 wftool = self.portal_workflow 909 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 910 students_folder = self.portal_catalog({'meta_type': 'StudentsFolder'})[-1].getObject() 911 tr_count = 1 912 total = 0 913 #name = 'pume_results' 914 name = 'Returning_update' 915 table = self.returning_import 916 no_import = [] 917 imported = [] 918 logger = logging.getLogger('Import.%s' % name) 919 try: 920 returning = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 921 except: 922 logger.error('Error reading %s.csv' % name) 923 return 924 l = self.portal_catalog({'meta_type': "Certificate"}) 925 certs = {} 926 cert_docs = {} 927 for f in l: 928 certs[f.getId] = f.getObject().getContent() 929 start = True 930 res = table() 931 regs = [] 932 if len(res) > 0: 933 regs = [s.matric_no for s in res] 934 for student in returning: 935 if start: 936 start = False 937 logger.info('start loading from %s.csv' % name) 938 s = ','.join(['"(%s)"' % fn for fn in student.keys()]) 939 imported.append(s) 940 no_import.append('%s,"Error"' % s) 941 format = ','.join(['"%%(%s)s"' % fn for fn in student.keys()]) 942 format_error = format + ',"%(Error)s"' 943 no_certificate = "no certificate %s" % format 944 matric_no = student.get('matric_no').upper() 945 student['matric_no'] = matric_no 946 if matric_no == '': 947 student['Error'] = "Empty matric_no" 948 no_import.append( format_error % student) 949 continue 950 # if matric_no in regs or self.returning_import(matric_no = matric_no): 951 # student['Error'] = "Duplicate" 952 # no_import.append( format_error % student) 953 # continue 954 # cert_id = makeCertificateCode(student.get('Coursemajorcode')) 955 # if cert_id not in certs.keys(): 956 # student['Error'] = "No Certificate %s" % cert_id 957 # no_import.append( format_error % student) 958 # continue 959 try: 960 table.modifyRecord(**student) 961 except KeyError: 962 #import pdb;pdb.set_trace() 963 student['Error'] = "no Student found to update" 964 no_import.append( format_error % student) 965 continue 966 s = self.students_catalog(matric_no=matric_no) 967 if s: 968 level = "%s" % (int(student.get('Level')) + 100) 969 self.students_catalog.modifyRecord(id = s[0].id, 970 level=level) 971 972 regs.append(student.get('matric_no')) 973 imported.append(format % student) 974 tr_count += 1 975 if tr_count > 1000: 976 if len(no_import) > 0: 977 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 978 '\n'.join(no_import) + '\n') 979 no_import = [] 980 open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( 981 '\n'.join(no_import) + "\n") 982 imported = [] 983 em = '%d transactions commited total %s\n' % (tr_count,total) 984 transaction.commit() 985 regs = [] 986 logger.info(em) 987 total += tr_count 988 tr_count = 0 989 open("%s/import/%simported%s.csv" % (i_home,name,current),"a").write( 990 '\n'.join(imported)) 991 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 992 '\n'.join(no_import)) 993 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 994 ###) 995 996 997 898 998 899 999 security.declareProtected(ModifyPortalContent,"importResults")###(
Note: See TracChangeset for help on using the changeset viewer.