- Timestamp:
- 20 Jun 2011, 02:37:06 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r6413 r6417 61 61 return IWorkflowState(self).getState() == USED 62 62 63 class AccessCodeBatch(grok. Model):63 class AccessCodeBatch(grok.Container): 64 64 """A batch of access codes. 65 65 """ … … 77 77 self.invalidated_num = 0 78 78 self.disabled_num = 0 79 self._entries = list()80 self._acids = OIBTree()81 self._createEntries()82 79 83 80 def _createEntries(self): … … 98 95 for x in range(10): 99 96 pin += str(random().randint(0, 9)) 100 if not '%s-%s-%s' % (self.prefix, self.num, pin) in self. _acids:97 if not '%s-%s-%s' % (self.prefix, self.num, pin) in self.keys(): 101 98 curr += 1 102 99 yield pin … … 116 113 """Get all entries of this batch as generator. 117 114 """ 118 for x in self. _entries:115 for x in self.values(): 119 116 yield x 120 117 … … 122 119 """Get the AccessCode with ID ``ac_id`` or ``KeyError``. 123 120 """ 124 return self ._entries[self._acids[ac_id]]121 return self[ac_id] 125 122 126 123 def addAccessCode(self, num, pin): … … 129 126 ac = AccessCode(num, pin) 130 127 ac.__parent__ = self 131 self._entries.append(ac) 132 self._acids.update({ac.representation: num}) 128 self[ac.representation] = ac 133 129 return 134 130 … … 136 132 """Invalidate the AC with ID ``ac_id``. 137 133 """ 138 num = self._acids[ac_id]139 134 self.invalidated_num += 1 140 135 … … 157 152 ACs are left untouched. 158 153 """ 159 num = self._acids[ac_id]160 self.disabled_num -= 1161 154 162 155 def createCSVLogFile(self): … … 179 172 writer.writerow([self.prefix, str(self.num), "%0.2f" % self.cost]) 180 173 181 for value in self. _entries:174 for value in self.values(): 182 175 writer.writerow( 183 176 [str(value.batch_serial), str(value.representation)] … … 205 198 writer.writerow([self.prefix, '%0.2f' % self.cost, str(self.num), 206 199 str(self.entry_num)]) 207 for value in self. _entries:200 for value in self.values(): 208 201 writer.writerow([ 209 202 self.prefix, value.batch_serial, value.representation, … … 223 216 return [] 224 217 218 @grok.subscribe(IAccessCodeBatch, grok.IObjectAddedEvent) 219 def handle_local_role_changed(batch, event): 220 # A (maybe dirty?) workaround to make batch containers work 221 # without self-maintained acids: as batches should contain their 222 # set of data immediately after creation, but we cannot add 223 # subobjects as long as the batch was not added already to the 224 # ZODB, we trigger the item creation for the time after the batch 225 # was added to the ZODB. 226 batch._createEntries() 227 return 228 229 225 230 class AccessCodeBatchContainer(grok.Container): 226 231 grok.implements(IAccessCodeBatchContainer) … … 245 250 self._p_changed = True 246 251 247 def createBatch(self, creation_date, creator, batch_prefix, cost,252 def createBatch(self, creation_date, creator, prefix, cost, 248 253 entry_num): 249 254 """Create and add a batch. 250 255 """ 251 batch_num = self.getNum( batch_prefix)252 batch = AccessCodeBatch(creation_date, creator, batch_prefix,256 batch_num = self.getNum(prefix) 257 batch = AccessCodeBatch(creation_date, creator, prefix, 253 258 cost, entry_num, num=batch_num) 254 259 self.addBatch(batch) … … 284 289 if batch_name in self.keys(): 285 290 raise KeyError('Batch already exists: %s' % batch_name) 291 #batch = AccessCodeBatch( 292 # datetime.now(), creator, entry['serial'], cost, 0, num=num) 286 293 batch = AccessCodeBatch( 287 datetime.now(), creator, entry['serial'], cost, 0, num= num)294 datetime.now(), creator, entry['serial'], cost, 0, num=0) 288 295 num_entries = 0 296 self[batch_name] = batch 289 297 for row in reader: 290 298 pin = row['ac'] … … 294 302 num_entries += 1 295 303 batch.entry_num = num_entries 296 self[batch_name] = batch 304 297 305 batch.createCSVLogFile() 298 306 return
Note: See TracChangeset for help on using the changeset viewer.