Last change
on this file since 10097 was
5179,
checked in by Henrik Bettermann, 15 years ago
|
continue numbering of pin batches instead of filling gaps
|
-
Property svn:keywords set to
Id
|
File size:
1.0 KB
|
Line | |
---|
1 | ##parameters=type_name, datamodel |
---|
2 | # $Id: scratch_card_batch_create_do.py 5179 2010-04-30 06:39:44Z henrik $ |
---|
3 | """ |
---|
4 | Create an empty object in the context according to the datamodel. |
---|
5 | |
---|
6 | Datamodel may be examined to create a suitable id. |
---|
7 | """ |
---|
8 | from Products.CMFCore.utils import getToolByName |
---|
9 | |
---|
10 | #try: |
---|
11 | # from Products.zdb import set_trace |
---|
12 | #except: |
---|
13 | # def set_trace(): |
---|
14 | # pass |
---|
15 | |
---|
16 | |
---|
17 | prefix = datamodel.get('prefix').upper() |
---|
18 | datamodel.set('prefix',prefix) |
---|
19 | bl = context.portal_catalog({'meta_type': "ScratchCardBatch",}) |
---|
20 | b_ids = [] |
---|
21 | |
---|
22 | for b in bl: |
---|
23 | b_ids.append(b.getId) |
---|
24 | |
---|
25 | p_ids = [p_id for p_id in b_ids if p_id.startswith(prefix)] |
---|
26 | if p_ids: |
---|
27 | max_bno = max([int(bno.split('_')[1]) for bno in p_ids]) |
---|
28 | next = max_bno+1 |
---|
29 | else: |
---|
30 | next = 1 |
---|
31 | |
---|
32 | #next = 1 |
---|
33 | #while b_ids and "%s_%d" % (prefix,next) in b_ids: |
---|
34 | # next += 1 |
---|
35 | |
---|
36 | id = "%s_%d" % (prefix,next) |
---|
37 | |
---|
38 | datamodel.set('batch_no',next) |
---|
39 | new_id = context.invokeFactory(type_name, id, datamodel=datamodel, |
---|
40 | ) |
---|
41 | if new_id is not None: |
---|
42 | id = new_id |
---|
43 | |
---|
44 | ob = getattr(context, id) |
---|
45 | ob.getContent().edit(mapping=datamodel) |
---|
46 | |
---|
47 | return ob |
---|
Note: See
TracBrowser for help on using the repository browser.