Changeset 8321
- Timestamp:
- 2 May 2012, 06:24:42 (13 years ago)
- Location:
- main/waeup.kofa/trunk/src/waeup/kofa/accesscodes
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/accesscode.py
r8194 r8321 85 85 self.random_num = random_num 86 86 self.owner = None 87 self.cost = None 87 88 IWorkflowInfo(self).fireTransition('init') 88 89 … … 119 120 return self.batch.num 120 121 121 @property122 def cost(self):123 """A float representing the price or ``None``. A read-only attribute.124 """125 if self.batch is None:126 return None127 return self.batch.cost122 #@property 123 #def cost(self): 124 # """A float representing the price or ``None``. A read-only attribute. 125 # """ 126 # if self.batch is None: 127 # return None 128 # return self.batch.cost 128 129 129 130 @property … … 167 168 """ 168 169 for num, pin in enumerate(self.getNewRandomNum(num=self.entry_num)): 169 self.addAccessCode(num, pin )170 self.addAccessCode(num, pin, self.cost) 170 171 return 171 172 … … 200 201 return self[ac_id] 201 202 202 def addAccessCode(self, num, pin, owner=None):203 def addAccessCode(self, num, pin, cost=0.0, owner=None): 203 204 """Add an access-code. 204 205 """ … … 206 207 if owner: 207 208 ac.owner = owner 209 ac.cost = cost 208 210 ac.__parent__ = self 209 211 self[ac.representation] = ac … … 255 257 ) 256 258 writer = csv.writer(open(csv_path, 'w'), quoting=csv.QUOTE_ALL) 257 writer.writerow(['prefix', 'serial', 'ac', 'state', 'history' ])259 writer.writerow(['prefix', 'serial', 'ac', 'state', 'history', 'cost']) 258 260 writer.writerow([self.prefix, '%0.2f' % self.cost, str(self.num), 259 261 str(self.entry_num)]) … … 264 266 writer.writerow([ 265 267 self.prefix, value.batch_serial, value.representation, 266 value.state, value.history 268 value.state, value.history, value.cost 267 269 ]) 268 270 return os.path.basename(csv_path) … … 363 365 pin = row['ac'] 364 366 serial = int(row['serial']) 367 try: 368 cost = float(row['cost']) 369 except ValueError: 370 cost = 0.0 365 371 rand_num = pin.rsplit('-', 1)[-1] 366 batch.addAccessCode(serial, rand_num )372 batch.addAccessCode(serial, rand_num, cost) 367 373 num_entries += 1 368 374 batch.entry_num = num_entries 369 370 375 batch.createCSVLogFile() 371 376 return -
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/browser.txt
r7819 r8321 438 438 ... sorted(os.listdir(ac_storage))[-2]) 439 439 >>> print open(archive_file, 'rb').read() 440 "prefix","serial","ac","state","history" 440 "prefix","serial","ac","state","history","cost" 441 441 "BLA","19.12","1","3" 442 "BLA","0","BLA-1-<10-DIGITS>","initialized","..." 443 "BLA","1","BLA-1-<10-DIGITS>","initialized","..." 444 "BLA","2","BLA-1-<10-DIGITS>","initialized","..." 442 "BLA","0","BLA-1-<10-DIGITS>","initialized","...","19.12" 443 "BLA","1","BLA-1-<10-DIGITS>","initialized","...","19.12" 444 "BLA","2","BLA-1-<10-DIGITS>","initialized","...","19.12" 445 445 446 446 Clean up: -
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/interfaces.py
r8172 r8321 40 40 cost = schema.Float( 41 41 title = _(u'Cost of access code'), 42 default = 0.0, min = 0.0,43 42 ) 44 43 state = schema.TextLine( -
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/sample_import.csv
r6543 r8321 1 "prefix","serial","ac","state","history" 2 "FOO","9.99","1","0" 3 "FOO","0","FOO-1-11111111","used","2011-06-01 12:12:14 - AC initialized by system||2011-06-01 12:14:14 - comment with ""quotes"" by system" 4 "FOO","1","FOO-1-22222222","initialized","2011-05-30 21:10:12 - AC initialized by system" 5 "FOO","2","FOO-1-33333333","disabled","2012-05-30 21:12:10 - AC initialized by system||2012-05-30 23:10:10 - AC disabled by system" 1 "prefix","serial","ac","state","history","cost" 2 "FOO","9.99","1","0","" 3 "FOO","0","FOO-1-11111111","used","2011-06-01 12:12:14 - AC initialized by system||2011-06-01 12:14:14 - comment with ""quotes"" by system","1000.0" 4 "FOO","1","FOO-1-22222222","initialized","2011-05-30 21:10:12 - AC initialized by system","" 5 "FOO","2","FOO-1-33333333","disabled","2012-05-30 21:12:10 - AC initialized by system||2012-05-30 23:10:10 - AC disabled by system","" -
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_accesscode.py
r8234 r8321 238 238 239 239 def test_cost(self): 240 # We get the cost set in batch 240 # The cost of an access code will be stored by handle_batch_added 241 # right after the batch has been added to the ZODB. Thus after 242 # creation of the batch, cost is still 0.0 241 243 cost = self.ac1.cost 242 assert cost == 6.6244 assert cost == 0.0 243 245 244 246 class AccessCodeBatchTests(FunctionalTestCase): … … 264 266 265 267 self.ac1 = AccessCode(0, '11111111') 268 self.ac1.cost = 2345.0 266 269 self.ac2 = AccessCode(1, '22222222') 267 270 self.ac3 = AccessCode(2, '33333333') … … 298 301 result_path = os.path.join(batch._getStoragePath(), basename) 299 302 expected = ''' 300 "prefix","serial","ac","state","history" 303 "prefix","serial","ac","state","history","cost" 301 304 "FOO","9.99","1","0" 302 "FOO","0","FOO-1-11111111","used","<YYYY-MM-DD hh:mm:ss> UTC - ..." 303 "FOO","1","FOO-1-22222222","initialized","<YYYY-MM-DD hh:mm:ss> UTC - ..." 304 "FOO","2","FOO-1-33333333","disabled","<YYYY-MM-DD hh:mm:ss> UTC - ..." 305 "FOO","0","FOO-1-11111111","used","<YYYY-MM-DD hh:mm:ss> UTC - ...","2345.0" 306 "FOO","1","FOO-1-22222222","initialized","<YYYY-MM-DD hh:mm:ss> UTC - ...","" 307 "FOO","2","FOO-1-33333333","disabled","<YYYY-MM-DD hh:mm:ss> UTC - ...","" 305 308 '''[1:] 306 309 contents = open(result_path, 'rb').read() … … 366 369 keys, 367 370 [u'FOO-1-11111111', u'FOO-1-22222222', u'FOO-1-33333333']) 371 # Also cost has been stored correctly 372 self.assertEqual(batch['FOO-1-11111111'].cost,1000.0) 368 373 369 374 def test_getAccessCode(self): -
main/waeup.kofa/trunk/src/waeup/kofa/accesscodes/tests/test_catalog.py
r7811 r8321 60 60 self.ac2 = batch.getAccessCode('APP-1-22222222') 61 61 self.ac3 = batch.getAccessCode('APP-1-33333333') 62 63 64 62 return 65 63
Note: See TracChangeset for help on using the changeset viewer.