Changeset 1529
- Timestamp:
- 8 Mar 2007, 23:18:47 (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1515 r1529 902 902 ###) 903 903 904 security.declareProtected(ModifyPortalContent,"fixVerdicts")###( 905 def fixVerdicts(self,csv_file=None): 906 """fix wrong uploaded verdicts""" 907 import transaction 908 import random 909 wftool = self.portal_workflow 910 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 911 students_folder = self.portal_url.getPortalObject().campus.students 912 tr_count = 1 913 total = 0 914 if csv_file is None: 915 name = 'Verdicts' 916 else: 917 name = csv_file 918 st_cat = self.students_catalog 919 no_import = [] 920 verdicts_voc = self.portal_vocabularies.verdicts 921 rverdicts = {} 922 for k,v in verdicts_voc.items(): 923 rverdicts[v.upper()] = k 924 logger = logging.getLogger('fixVerdicts') 925 try: 926 verdicts = csv.DictReader(open("%s/import/%s.csv" % (i_home,name),"rb")) 927 except: 928 logger.error('Error reading %s.csv' % name) 929 return 930 start = True 931 #import pdb;pdb.set_trace() 932 for verdict in verdicts: 933 if start: 934 start = False 935 logger.info('start loading from %s.csv' % name) 936 s = ','.join(['"%s"' % fn for fn in verdict.keys()]) 937 no_import.append('%s,"Error"' % s) 938 format = ','.join(['"%%(%s)s"' % fn for fn in verdict.keys()]) 939 format_error = format + ',"%(Error)s"' 940 matric_no = verdict.get('MAT NO') 941 if not matric_no: 942 continue 943 matric_no = matric_no.upper() 944 if matric_no == '': 945 continue 946 verdict_code = rverdicts.get(verdict.get('CATEGORY'),None) 947 if verdict_code is None: 948 continue 949 sres = st_cat(matric_no = matric_no) 950 if sres: 951 student_id = sres[0].id 952 student_obj = getattr(students_folder,student_id,None) 953 if student_obj: 954 study_course = getattr(student_obj,'study_course',None) 955 if study_course is None: 956 verdict['Error'] = "Student did not yet log in" 957 no_import.append( format_error % verdict) 958 continue 959 try: 960 st_cat.modifyRecord(id = student_id, 961 verdict=verdict_code) 962 except KeyError: 963 student['Error'] = "Not found in students_catalog" 964 no_import.append( format_error % student) 965 continue 966 dsc = {} 967 dsc['current_verdict'] = verdict_code 968 study_course.getContent().edit(mapping=dsc) 969 tr_count += 1 970 if tr_count > 1000: 971 if len(no_import) > 0: 972 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 973 '\n'.join(no_import) + '\n') 974 no_import = [] 975 em = '%d transactions commited total %s\n' % (tr_count,total) 976 transaction.commit() 977 regs = [] 978 logger.info(em) 979 total += tr_count 980 tr_count = 0 981 open("%s/import/%s_not_imported%s.csv" % (i_home,name,current),"a").write( 982 '\n'.join(no_import)) 983 total += tr_count 984 em = '%d total transactions commited' % (total) 985 logger.info(em) 986 return self.REQUEST.RESPONSE.redirect("%s" % self.REQUEST.get('URL1')) 987 ###) 988 904 989 security.declareProtected(ModifyPortalContent,"fixAllEntryModeForReturning")###( 905 990 def fixAllEntryModeForReturning(self): … … 1671 1756 ###) 1672 1757 1673 1758 1674 1759 security.declareProtected(View,"fixOwnership") 1675 1760 def fixOwnership(self):
Note: See TracChangeset for help on using the changeset viewer.