:mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs) ******************************************************************** .. module:: waeup.sirp.accesscodes.accesscodes Components that represent access codes and related. .. :doctest: Access codes are created as parts of batches. We therefore have to create a batch first. Here we create a batch of three entries, with a cost of ``12.12`` per code, the batch prefix ``APP``, batch number ``10``, creator ID ``Fred`` and some arbitrary creation date: >>> import datetime >>> from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch >>> batch = AccessCodeBatch( ... datetime.datetime(2009, 12, 23), 'Fred','APP', 12.12, 3, num=10) The entries of a batch have to be created manually. This is, because we cannot add persistent objects in a still not persisted container: >>> batch.createEntries() Now we have three accesscodes stored in the batch: >>> sorted(list(batch.items())) [(u'0', >> ac = batch['0'] >>> ac.representation 'APP-10-<10-DIGITS>' The main point about a batch is that it can act as a dictionary for the generated access codes: >>> ac_codes = list(batch.values()) >>> [x.representation for x in ac_codes] ['APP-10-...', 'APP-10-...', 'APP-10-...'] `Accesscode` and `AccessCodeBatch` classes implement the respective interfaces: >>> from waeup.sirp.accesscodes.accesscodes import ( ... AccessCode, AccessCodeBatch) >>> from waeup.sirp.accesscodes.interfaces import( ... IAccessCode, IAccessCodeBatch) >>> from zope.interface.verify import verifyClass >>> verifyClass(IAccessCode, AccessCode) True >>> verifyClass(IAccessCodeBatch, AccessCodeBatch) True