Changeset 5080
- Timestamp:
- 24 Mar 2010, 12:58:37 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.sirp/trunk/src/waeup/sirp/accesscodes/accesscodes.txt
r5068 r5080 1 Accesscodes 2 *********** 1 :mod:`waeup.sirp.accesscodes.accesscodes` -- access codes (aka PINs) 2 ******************************************************************** 3 3 4 :doctest: 4 .. module:: waeup.sirp.accesscodes.accesscodes 5 5 6 We can create accesscodes: 6 Components that represent access codes and related. 7 7 8 >>> from waeup.sirp.accesscodes.accesscodes import AccessCode 9 >>> ac = AccessCode(0, 'APP', 12, '0123456789', 12.12) 10 >>> ac.representation 11 'APP-12-0123456789' 8 .. :doctest: 12 9 13 We can create batches. Here we create a batch of three entries, with a 14 cost of 12.12 per code, the batch prefix 'APP', batch number 12, 15 creator ID 'Fred' and some arbitrary creation date: 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 16 17 17 >>> import datetime … … 20 20 ... datetime.datetime(2009, 12, 23), 'Fred', 10, 'APP', 12.12, 3) 21 21 22 The main point about a batch is that it can act as an iterator over 23 the generated access codes. The codes are generated on-the-fly when 24 iterating over the batch for the first time: 22 Now we have three accesscodes stored in the batch: 25 23 26 >>> ac_codes = [x.representation for x in batch] 27 >>> ac_codes 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] 28 41 ['APP-10-...', 'APP-10-...', 'APP-10-...'] 29 30 When we ask for the access codes again, we will get equal31 entries. 'Equal' means: we will get same representations, but not32 neccessarily the same objects:33 34 >>> ac_codes2 = [x.representation for x in batch]35 >>> ac_codes2 == ac_codes36 True37 38 >>> ac_codes[0] == ac_codes2[0]39 True40 41 >>> ac_codes[0] is ac_codes2[0]42 False43 42 44 43 `Accesscode` and `AccessCodeBatch` classes implement the respective
Note: See TracChangeset for help on using the changeset viewer.