Ignore:
Timestamp:
20 Jun 2011, 02:37:06 (13 years ago)
Author:
uli
Message:

Reorganize tests. For what is over, make most of the remaining accesscode stuff work again. Still lots to do.

File:
1 edited

Legend:

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

    r6413 r6417  
    6161        return IWorkflowState(self).getState() == USED
    6262
    63 class AccessCodeBatch(grok.Model):
     63class AccessCodeBatch(grok.Container):
    6464    """A batch of access codes.
    6565    """
     
    7777        self.invalidated_num = 0
    7878        self.disabled_num = 0
    79         self._entries = list()
    80         self._acids = OIBTree()
    81         self._createEntries()
    8279
    8380    def _createEntries(self):
     
    9895            for x in range(10):
    9996                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():
    10198                curr += 1
    10299                yield pin
     
    116113        """Get all entries of this batch as generator.
    117114        """
    118         for x in self._entries:
     115        for x in self.values():
    119116            yield x
    120117
     
    122119        """Get the AccessCode with ID ``ac_id`` or ``KeyError``.
    123120        """
    124         return self._entries[self._acids[ac_id]]
     121        return self[ac_id]
    125122
    126123    def addAccessCode(self, num, pin):
     
    129126        ac = AccessCode(num, pin)
    130127        ac.__parent__ = self
    131         self._entries.append(ac)
    132         self._acids.update({ac.representation: num})
     128        self[ac.representation] = ac
    133129        return
    134130
     
    136132        """Invalidate the AC with ID ``ac_id``.
    137133        """
    138         num = self._acids[ac_id]
    139134        self.invalidated_num += 1
    140135
     
    157152        ACs are left untouched.
    158153        """
    159         num = self._acids[ac_id]
    160         self.disabled_num -= 1
    161154
    162155    def createCSVLogFile(self):
     
    179172        writer.writerow([self.prefix, str(self.num), "%0.2f" % self.cost])
    180173
    181         for value in self._entries:
     174        for value in self.values():
    182175            writer.writerow(
    183176                [str(value.batch_serial), str(value.representation)]
     
    205198        writer.writerow([self.prefix, '%0.2f' % self.cost, str(self.num),
    206199                         str(self.entry_num)])
    207         for value in self._entries:
     200        for value in self.values():
    208201            writer.writerow([
    209202                    self.prefix, value.batch_serial, value.representation,
     
    223216                return []
    224217
     218@grok.subscribe(IAccessCodeBatch, grok.IObjectAddedEvent)
     219def 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
    225230class AccessCodeBatchContainer(grok.Container):
    226231    grok.implements(IAccessCodeBatchContainer)
     
    245250        self._p_changed = True
    246251
    247     def createBatch(self, creation_date, creator, batch_prefix, cost,
     252    def createBatch(self, creation_date, creator, prefix, cost,
    248253                    entry_num):
    249254        """Create and add a batch.
    250255        """
    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,
    253258                                cost, entry_num, num=batch_num)
    254259        self.addBatch(batch)
     
    284289        if batch_name in self.keys():
    285290            raise KeyError('Batch already exists: %s' % batch_name)
     291        #batch = AccessCodeBatch(
     292        #    datetime.now(), creator, entry['serial'], cost, 0, num=num)
    286293        batch = AccessCodeBatch(
    287             datetime.now(), creator, entry['serial'], cost, 0, num=num)
     294            datetime.now(), creator, entry['serial'], cost, 0, num=0)
    288295        num_entries = 0
     296        self[batch_name] = batch
    289297        for row in reader:
    290298            pin = row['ac']
     
    294302            num_entries += 1
    295303        batch.entry_num = num_entries
    296         self[batch_name] = batch
     304
    297305        batch.createCSVLogFile()
    298306        return
Note: See TracChangeset for help on using the changeset viewer.