1 | :mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs) |
---|
2 | ******************************************************************** |
---|
3 | |
---|
4 | .. module:: waeup.sirp.accesscodes.accesscodes |
---|
5 | |
---|
6 | Components that represent access codes and related. |
---|
7 | |
---|
8 | .. :doctest: |
---|
9 | |
---|
10 | Access codes are created as parts of batches. We therefore have to |
---|
11 | create a batch first. |
---|
12 | |
---|
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 | |
---|
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 | |
---|
22 | Now we have three accesscodes stored in the batch: |
---|
23 | |
---|
24 | >>> sorted(list(batch.items())) |
---|
25 | [(u'0', <waeup.sirp...AccessCode object at 0x...), ...] |
---|
26 | |
---|
27 | As we can see, access codes entries can be found in a batch by their |
---|
28 | (stringified) serial number. |
---|
29 | |
---|
30 | Each accesscode has a representation: |
---|
31 | |
---|
32 | >>> ac = batch['0'] |
---|
33 | >>> ac.representation |
---|
34 | 'APP-10-<10-DIGITS>' |
---|
35 | |
---|
36 | The main point about a batch is that it can act as a dictionary for |
---|
37 | the generated access codes: |
---|
38 | |
---|
39 | >>> ac_codes = list(batch.values()) |
---|
40 | >>> [x.representation for x in ac_codes] |
---|
41 | ['APP-10-...', 'APP-10-...', 'APP-10-...'] |
---|
42 | |
---|
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 |
---|