Changeset 5086


Ignore:
Timestamp:
26 Mar 2010, 11:49:22 (15 years ago)
Author:
uli
Message:

Split creation of batches and batch entry creation. This is needed,
because we cannot add persistent access codes inside a yet not stored
persistent container (?!).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.py

    r5079 r5086  
    2727    def batch(self):
    2828        return getattr(self, '__parent__', None)
    29    
     29
    3030    @property
    3131    def batch_prefix(self):
     
    3333            return ''
    3434        return self.batch.prefix
    35    
     35
    3636    @property
    3737    def batch_num(self):
     
    4545    grok.implements(IAccessCodeBatch)
    4646
    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):
    4949        super(AccessCodeBatch, self).__init__()
    5050        self.creation_date = creation_date
    5151        self.creator = creator
    52         self.num = batch_num
    5352        self.prefix = batch_prefix
    5453        self.cost = cost
    5554        self.entry_num = entry_num
    56         self._createEntries()
     55        self.num = num
    5756
    58     def _createEntries(self):
     57    def createEntries(self):
    5958        """Create the entries for this batch.
    6059        """
     
    6564            self[str(num)] = ac
    6665        del self._used
    67        
     66
    6867    def getNewRandomNum(self):
    6968        """Create a random number of 10 digits.
     
    8281
    8382    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)
    8587        self[key] = batch
     88        batch.createEntries()
     89        self._p_changed = True
     90        self.curr_num += 1
    8691
     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       
    87101class AccessCodePlugin(grok.GlobalUtility):
    88102    grok.name('accesscodes')
Note: See TracChangeset for help on using the changeset viewer.