Changeset 5086
- Timestamp:
- 26 Mar 2010, 11:49:22 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py
r5079 r5086 27 27 def batch(self): 28 28 return getattr(self, '__parent__', None) 29 29 30 30 @property 31 31 def batch_prefix(self): … … 33 33 return '' 34 34 return self.batch.prefix 35 35 36 36 @property 37 37 def batch_num(self): … … 45 45 grok.implements(IAccessCodeBatch) 46 46 47 def __init__(self, creation_date, creator, batch_ num, batch_prefix, cost,48 entry_num ):47 def __init__(self, creation_date, creator, batch_prefix, cost, 48 entry_num, num=None): 49 49 super(AccessCodeBatch, self).__init__() 50 50 self.creation_date = creation_date 51 51 self.creator = creator 52 self.num = batch_num53 52 self.prefix = batch_prefix 54 53 self.cost = cost 55 54 self.entry_num = entry_num 56 self. _createEntries()55 self.num = num 57 56 58 def _createEntries(self):57 def createEntries(self): 59 58 """Create the entries for this batch. 60 59 """ … … 65 64 self[str(num)] = ac 66 65 del self._used 67 66 68 67 def getNewRandomNum(self): 69 68 """Create a random number of 10 digits. … … 82 81 83 82 def addBatch(self, batch): 84 key = "%s_%s" % (batch.prefix, batch.num) 83 """Add a batch. 84 """ 85 batch.num = self.getNum(batch.prefix) 86 key = "%s-%s" % (batch.prefix, batch.num) 85 87 self[key] = batch 88 batch.createEntries() 89 self._p_changed = True 90 self.curr_num += 1 86 91 92 def getNum(self, prefix): 93 """Get next unused num for given prefix. 94 """ 95 num = 1 96 prefix = prefix.upper() 97 while self.get('%s-%s' % (prefix, num), None): 98 num += 1 99 return num 100 87 101 class AccessCodePlugin(grok.GlobalUtility): 88 102 grok.name('accesscodes')
Note: See TracChangeset for help on using the changeset viewer.