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','APP', 12.12, 3, num=10) |
---|
21 | |
---|
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 | |
---|
27 | Now we have three accesscodes stored in the batch: |
---|
28 | |
---|
29 | >>> sorted(list(batch.items())) |
---|
30 | [(u'0', <waeup.sirp...AccessCode object at 0x...), ...] |
---|
31 | |
---|
32 | As we can see, access codes entries can be found in a batch by their |
---|
33 | (stringified) serial number. |
---|
34 | |
---|
35 | Each accesscode has a representation: |
---|
36 | |
---|
37 | >>> ac = batch['0'] |
---|
38 | >>> ac.representation |
---|
39 | 'APP-10-<10-DIGITS>' |
---|
40 | |
---|
41 | The main point about a batch is that it can act as a dictionary for |
---|
42 | the generated access codes: |
---|
43 | |
---|
44 | >>> ac_codes = list(batch.values()) |
---|
45 | >>> [x.representation for x in ac_codes] |
---|
46 | ['APP-10-...', 'APP-10-...', 'APP-10-...'] |
---|
47 | |
---|
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 |
---|