Changeset 5110 for main/waeup.sirp/trunk/src
- Timestamp:
- 31 Mar 2010, 23:21:04 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r5107 r5110 1 1 """Components to handle access codes. 2 2 """ 3 import csv 3 4 import grok 5 import os 4 6 from random import SystemRandom as random 5 7 from waeup.sirp.interfaces import IWAeUPSIRPPluggable … … 81 83 return result 82 84 85 def createCSVLogFile(self): 86 """Create a CSV file with data in batch. 87 88 Data will not contain invalidation date nor student ids. File 89 will be created in ``accesscodes`` subdir of data center 90 storage path. 91 92 Returns name of created file. 93 """ 94 site = grok.getSite() 95 storagepath = site['datacenter'].storage 96 ac_storage = os.path.join(storagepath, 'accesscodes') 97 if not os.path.exists(ac_storage): 98 os.mkdir(ac_storage) 99 date = self.creation_date.strftime('%Y_%m_%d_%H_%M_%S') 100 csv_path = os.path.join( 101 ac_storage, '%s-%s-%s-%s.csv' % ( 102 self.prefix, self.num, date, self.creator) 103 ) 104 writer = csv.writer(open(csv_path, 'w'), quoting=csv.QUOTE_ALL) 105 writer.writerow(['serial', 'ac', 'cost']) 106 writer.writerow([self.prefix, str(self.num), "%0.2f" % self.cost]) 107 for key, value in self.items(): 108 writer.writerow( 109 [str(value.batch_serial), str(value.representation)] 110 ) 111 return os.path.basename(csv_path) 112 113 83 114 class AccessCodeBatchContainer(grok.Container): 84 115 grok.implements(IAccessCodeBatchContainer)
Note: See TracChangeset for help on using the changeset viewer.