[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( |
---|
| 20 | ... datetime.datetime(2009, 12, 23), 'Fred', 10, 'APP', 12.12, 3) |
---|
| 21 | |
---|
[5080] | 22 | Now we have three accesscodes stored in the batch: |
---|
[5068] | 23 | |
---|
[5080] | 24 | >>> sorted(list(batch.items())) |
---|
| 25 | [(u'0', <waeup.sirp...AccessCode object at 0x...), ...] |
---|
[5068] | 26 | |
---|
[5080] | 27 | As we can see, access codes entries can be found in a batch by their |
---|
| 28 | (stringified) serial number. |
---|
[5068] | 29 | |
---|
[5080] | 30 | Each accesscode has a representation: |
---|
[5068] | 31 | |
---|
[5080] | 32 | >>> ac = batch['0'] |
---|
| 33 | >>> ac.representation |
---|
| 34 | 'APP-10-<10-DIGITS>' |
---|
[5068] | 35 | |
---|
[5080] | 36 | The main point about a batch is that it can act as a dictionary for |
---|
| 37 | the generated access codes: |
---|
[5068] | 38 | |
---|
[5080] | 39 | >>> ac_codes = list(batch.values()) |
---|
| 40 | >>> [x.representation for x in ac_codes] |
---|
| 41 | ['APP-10-...', 'APP-10-...', 'APP-10-...'] |
---|
| 42 | |
---|
[5068] | 43 | `Accesscode` and `AccessCodeBatch` classes implement the respective |
---|
| 44 | interfaces: |
---|
| 45 | |
---|
| 46 | >>> from waeup.sirp.accesscodes.accesscodes import ( |
---|
| 47 | ... AccessCode, AccessCodeBatch) |
---|
| 48 | >>> from waeup.sirp.accesscodes.interfaces import( |
---|
| 49 | ... IAccessCode, IAccessCodeBatch) |
---|
| 50 | >>> from zope.interface.verify import verifyClass |
---|
| 51 | >>> verifyClass(IAccessCode, AccessCode) |
---|
| 52 | True |
---|
| 53 | |
---|
| 54 | >>> verifyClass(IAccessCodeBatch, AccessCodeBatch) |
---|
| 55 | True |
---|