- Timestamp:
- 26 Jun 2007, 15:01:57 (17 years ago)
- Location:
- WAeUP_SRP/trunk
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
WAeUP_SRP/trunk/Students.py
r1969 r1970 1022 1022 ###) 1023 1023 1024 security.declareProtected(ModifyPortalContent,"dumpStudentsCatalog")###( 1025 def dumpStudentsCatalog(self): 1026 """dump all data in students_catalog to a csv""" 1027 member = self.portal_membership.getAuthenticatedMember() 1028 logger = logging.getLogger('Students.dumpStudentsCatalog') 1029 current = DateTime.DateTime().strftime("%d-%m-%y_%H_%M_%S") 1030 export_file = "%s/export/students_catalog_%s.csv" % (i_home,current) 1031 res_list = [] 1032 lines = [] 1033 fields = [] 1034 for f in self.students_catalog.schema(): 1035 fields.append(f) 1036 headline = ','.join(fields) 1037 open(export_file,"a").write(headline +'\n') 1038 format = '"%(' + ')s","%('.join(fields) + ')s"' 1039 students = self.students_catalog() 1040 nr2export = len(students) 1041 logger.info('%s starts exportStudents, %s student records to export' % (member,nr2export)) 1042 chunk = 2000 1043 total = 0 1044 start = DateTime.DateTime().timeTime() 1045 start_chunk = DateTime.DateTime().timeTime() 1046 for student in students: 1047 not_all = False 1048 d = self.getFormattedStudentEntry(student) 1049 lines.append(format % d) 1050 total += 1 1051 if total and not total % chunk or total == len(students): 1052 open(export_file,"a").write('\n'.join(lines) +'\n') 1053 anz = len(lines) 1054 logger.info("wrote %(anz)d total written %(total)d" % vars()) 1055 end_chunk = DateTime.DateTime().timeTime() 1056 duration = end_chunk-start_chunk 1057 per_record = duration/anz 1058 till_now = end_chunk - start 1059 avarage_per_record = till_now/total 1060 estimated_end = DateTime.DateTime(start + avarage_per_record * nr2export) 1061 estimated_end = estimated_end.strftime("%H:%M:%S") 1062 logger.info('%(duration)4.1f, %(per_record)4.3f,end %(estimated_end)s' % vars()) 1063 start_chunk = DateTime.DateTime().timeTime() 1064 lines = [] 1065 end = DateTime.DateTime().timeTime() 1066 logger.info('total time %6.2f m' % ((end-start)/60)) 1067 filename, extension = os.path.splitext(export_file) 1068 from subprocess import call 1069 msg = "wrote %(total)d records to %(export_file)s" % vars() 1070 try: 1071 retcode = call('gzip %s' % (export_file),shell=True) 1072 if retcode == 0: 1073 msg = "wrote %(total)d records to %(export_file)s.gz" % vars() 1074 except OSError, e: 1075 retcode = -99 1076 logger.info("zip failed with %s" % e) 1077 logger.info(msg) 1078 args = {'portal_status_message': msg} 1079 #url = self.REQUEST.get('URL1') + '?' + urlencode(args) 1080 url = self.REQUEST.get('URL2') 1081 return self.REQUEST.RESPONSE.redirect(url) 1082 ###) 1083 1084 1024 1085 security.declareProtected(ModifyPortalContent,"importResults")###( 1025 1086 def importResults(self): -
WAeUP_SRP/trunk/skins/waeup_student/getFormattedStudentEntry.py
r1415 r1970 17 17 for f in fields: 18 18 d[f] = getattr(brain,f,'') 19 if not d[f]: 20 d[f] = '' 19 21 if f == "sex": 20 22 if d[f]: … … 24 26 elif f == "name": 25 27 d[f] = d[f].strip() 28 26 29 return d
Note: See TracChangeset for help on using the changeset viewer.