[5080] | 1 | :mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs) |
---|
| 2 | ******************************************************************** |
---|
[5068] | 3 | |
---|
[5080] | 4 | .. module:: waeup.sirp.accesscodes.accesscodes |
---|
[5068] | 5 | |
---|
[5080] | 6 | Components that represent access codes and related. |
---|
[5068] | 7 | |
---|
[5080] | 8 | .. :doctest: |
---|
[5068] | 9 | |
---|
[5080] | 10 | Access codes are created as parts of batches. We therefore have to |
---|
| 11 | create a batch first. |
---|
[5068] | 12 | |
---|
[5080] | 13 | Here we create a batch of three entries, with a cost of ``12.12`` per |
---|
| 14 | code, the batch prefix ``APP``, batch number ``10``, creator ID |
---|
| 15 | ``Fred`` and some arbitrary creation date: |
---|
| 16 | |
---|
[5068] | 17 | >>> import datetime |
---|
| 18 | >>> from waeup.sirp.accesscodes.accesscodes import AccessCodeBatch |
---|
| 19 | >>> batch = AccessCodeBatch( |
---|
[5087] | 20 | ... datetime.datetime(2009, 12, 23), 'Fred','APP', 12.12, 3, num=10) |
---|
[5068] | 21 | |
---|
[5087] | 22 | The entries of a batch have to be created manually. This is, because |
---|
| 23 | we cannot add persistent objects in a still not persisted container: |
---|
| 24 | |
---|
| 25 | >>> batch.createEntries() |
---|
| 26 | |
---|
[5080] | 27 | Now we have three accesscodes stored in the batch: |
---|
[5068] | 28 | |
---|
[5080] | 29 | >>> sorted(list(batch.items())) |
---|
| 30 | [(u'0', <waeup.sirp...AccessCode object at 0x...), ...] |
---|
[5068] | 31 | |
---|
[5080] | 32 | As we can see, access codes entries can be found in a batch by their |
---|
| 33 | (stringified) serial number. |
---|
[5068] | 34 | |
---|
[5080] | 35 | Each accesscode has a representation: |
---|
[5068] | 36 | |
---|
[5080] | 37 | >>> ac = batch['0'] |
---|
| 38 | >>> ac.representation |
---|
| 39 | 'APP-10-<10-DIGITS>' |
---|
[5068] | 40 | |
---|
[5080] | 41 | The main point about a batch is that it can act as a dictionary for |
---|
| 42 | the generated access codes: |
---|
[5068] | 43 | |
---|
[5080] | 44 | >>> ac_codes = list(batch.values()) |
---|
| 45 | >>> [x.representation for x in ac_codes] |
---|
| 46 | ['APP-10-...', 'APP-10-...', 'APP-10-...'] |
---|
| 47 | |
---|
[5068] | 48 | `Accesscode` and `AccessCodeBatch` classes implement the respective |
---|
| 49 | interfaces: |
---|
| 50 | |
---|
| 51 | >>> from waeup.sirp.accesscodes.accesscodes import ( |
---|
| 52 | ... AccessCode, AccessCodeBatch) |
---|
| 53 | >>> from waeup.sirp.accesscodes.interfaces import( |
---|
| 54 | ... IAccessCode, IAccessCodeBatch) |
---|
| 55 | >>> from zope.interface.verify import verifyClass |
---|
| 56 | >>> verifyClass(IAccessCode, AccessCode) |
---|
| 57 | True |
---|
| 58 | |
---|
| 59 | >>> verifyClass(IAccessCodeBatch, AccessCodeBatch) |
---|
| 60 | True |
---|